7 Replies Latest reply on Aug 17, 2016 1:20 PM by gregor

    How to make an alarm stop beeping after acknowledging it in ProcessBook?

    etelmcstos

      The purpose of this display is to give an audible alert the operator stating the same when the variable under observation has exceeded the limits of high and low. When it was only with a routine inserted alarm was running perfectly - the beep and by disrupting their alarm acknowledgment ..

       

      When we insert the other variables, the audible alarm sounds intermittently, stopping without alarm acknowledgment, as if paused.

       

      Someone can help me?

       

       

      VBA code is:

       

       

      '
      ' Execução de Sons no PI-ProcessBook
      '
      
      Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As Any, ByVal hModule As Long, ByVal dwFlags As Long) As Long
      '  Declaração de constantes usadas pela biblioteca de sons do windows.
      Private Const SND_ASYNC = &H1
      Private Const SND_LOOP = &H8
      Private Const SND_MEMORY = &H4
      Private Const SND_NODEFAULT = &H2
      Private Const SND_NOSTOP = &H10
      Private Const SND_SYNC = &H0
      Private Const SND_ALIAS = &H10000
      Private Const SND_APPLICATION = &H80
      Private Const SND_ALIAS_ID = &H110000
      Private Const SND_FILENAME = &H20000
      Private Const SND_NOWAIT = &H2000
      Private Const SND_PURGE = &H40
      Private Const SND_RESOURCE = &H40004
      
      Private Sub Display_Open()
        ThisDisplay.Application.FullScreen = True
        ' Zoom = "FitAll"
      
      End Sub
      
      Private Sub Display_Size(ByVal lWidth As Long, ByVal lHeight As Long, ByVal lDeltaX As Long, ByVal lDeltaY As Long)
      ' Zoom = "FitAll"
      
      End Sub
      
      Private Sub Ret1_MouseOut()
      'ThisDisplay.Ret1.Visible = False
      End Sub
      
      Private Sub Ret1_MouseOver()
      'ThisDisplay.Ret1.Visible = True
      End Sub
      
      'ALARME NIVEL SAO-01 ETO BURACICA
      
      Private Sub VlnivelSAO01ETOBuracica_Click(ByVal lvarX As Long, ByVal lvarY As Long)
            CheckforAlarm VlnivelSAO01ETOBuracica, 1.4, -1
      
      End Sub
      
      'ALARME NIVEL TQ-01 EIA BURACICA
      
      Private Sub VlnivelTQ01EIABuracica_DataUpdate()
          CheckforAlarm VlnivelTQ01EIABuracica, 1.5, 8
      
      End Sub
      
      'ALARME NIVEL TQ-03 TORORO
      
      Private Sub VlnivelTQ03Tororo_DataUpdate()
          CheckforAlarm VlnivelTQ03Tororo, 1.6, 4
      End Sub
      
      'ALARME NIVEL TQ-04 FPX
      
      Private Sub VlnivelTQ04FPX_DataUpdate()
          CheckforAlarm VlnivelTQ04FPX, 1, 3
      End Sub
      
      'ALARME NIVEL TQ-04 LAMEIRO
      
      Private Sub VlnivelTQ04Lameiro_DataUpdate()
      'ALARME tanque04 Lameiro
          CheckforAlarm VlnivelTQ04Lameiro, 5.5, 6.4
      End Sub
      
      'ALARME NIVEL TQ-08 PEREIRA
      
      Private Sub VlnivelTQ08Pereira_DataUpdate()
            CheckforAlarm VlnivelTQ08Pereira, 4, 6.5
      End Sub
      
      'ALARME NIVEL TQ-27 CAMBOATA
      
      Private Sub VlnivelTQ27Camboata_DataUpdate()
           CheckforAlarm VlnivelTQ27Camboata, 4, 8
      End Sub
      
      'ALARME ACOMPANHAMENTO CHEGADA LAV
      Private Sub vltotalvazaocamboata_DataUpdate()
          CheckforAlarm vltotalvazaocamboata, 13800, 16100
      End Sub
      
      'ALARME PIT-218 ETO
      
      Private Sub VlvazaoPIT218InjecaoETOBuracica_DataUpdate()
          CheckforAlarm VlvazaoPIT218InjecaoETOBuracica, 800, 1000
      
      End Sub
      
      'ALARME NIVEL TQ-21 CAMBOATA
      
      Private Sub VlnivelTQ21CAMBOATA_DataUpdate()
          CheckforAlarm VlnivelTQ21CAMBOATA, 1.1, 3
        
      End Sub
      
      'ALARME NIVEL TQ-22 CAMBOATA
      
      Private Sub VlnivelTQ22CAMBOATA_DataUpdate()
           CheckforAlarm VlnivelTQ22CAMBOATA, 1.1, 3
      
      
      End Sub
      
      '
      ' Check specified ProcessBook Value against specified Digital State.
      ' esta função recebe o Tag e seu valor de alarme
      Public Sub CheckforAlarm(vPBValue As Value, nFaixaLOW As Double, nFaixaTOP As Double)
      
      Dim sValue As String
      Dim bBad As Boolean
      
      'On Error Resume Next
      
          ' Get current ProcessBook Value object's current value.
          sValue = vPBValue.GetValue(Now(), bBad)
        
          ' Check for "good" value before alarm processing.
          If Not bBad Then
      
              ' Check Value for Alarm condition.
              If sValue < nFaixaLOW Or sValue > nFaixaTOP Then
            
                  ' Check if this alarm has been acknowledged (text is yellow).
                  If vPBValue.LineColor <> vbYellow Then
            
                      ' Not acknowledged, turn value red to indicate in alarm state.
                      vPBValue.BackgroundColor = vbRed
                      vPBValue.LineColor = vbWhite
                    
                      ' Sound alarm repeatedly.
                      PlayAlarmSound
                    
                      ' coloca a tela que alarmou em primeiro plano
                      ThisDisplay.Activate
            
                  End If
            
              ' Point not in alarm.
              Else
            
                  ' Alarm NOT has been acknowledged.
                  If vPBValue.LineColor = vbBlack And vPBValue.BackgroundColor = vbRed Then
                        
                      ' Set color back to red with no fill.
                      vPBValue.BackgroundColor = pbNone_Color
                      vPBValue.LineColor = vbRed
                    
                  ' Alarm acknowledged.
                  ElseIf vPBValue.LineColor = pbYellow Then
                    
                      ' Set color back to black with no fill.
                      vPBValue.BackgroundColor = pbBlack
                      vPBValue.LineColor = vbYellow
                
                  End If
                  StopSound
              End If
            
          End If
      
      End Sub
      '
      '  Esta sub-rotina pode ser usada por qualquer VBA para rodar o som repetidamente.
      '
      Public Sub PlayAlarmSound(Optional ByVal Soundfile As String)
      
      Dim sAlert As String
      
          ' Roda o som especificado.
          If Soundfile <> "" Then
              sAlert = Soundfile
            
          ' Ou senão, roda o som padrão.
          Else
              sAlert = "notify.wav"     ' Se o arquivo não estiver no mesmo diretório do arquivo PI-ProcessBook
                                             ' voce pode especificar um caminho completo.
          End If
        
          ' Inicia o som repetidamente.
          PlaySound sAlert, 0, SND_LOOP + SND_ASYNC
      
      End Sub
      
      '
      '   Esta rotina pára a execução de todos os sons.
      '
      Public Sub StopSound()
      
              PlaySound vbNullString, 0, SND_PURGE
      
      End Sub
      
      Private Sub ReconhecerAlarm_Click(ByVal lvarX As Long, ByVal lvarY As Long)
          StopSound
          ' Set color back to black with no fill.
                      vltotalvazaocamboata.BackgroundColor = vbBlack
                      vltotalvazaocamboata.LineColor = pbRed
      
      End Sub
      
      Private Sub Retângulo1_Click(ByVal lvarX As Long, ByVal lvarY As Long)
          StopSound
          ' Set color back to black with no fill.
                      VlnivelTQ04Lameiro.BackgroundColor = vbBlack
                      VlnivelTQ04Lameiro.LineColor = pbRed
      
      End Sub
      
      Private Sub ReconhecerAlarm6_Click(ByVal lvarX As Long, ByVal lvarY As Long)
          StopSound
          ' Set color back to black with no fill.
                      VlnivelTQ04FPX.BackgroundColor = vbBlack
                      VlnivelTQ04FPX.LineColor = pbRed
      End Sub
      
      Private Sub ReconhecerAlarm5_Click(ByVal lvarX As Long, ByVal lvarY As Long)
          StopSound
          ' Set color back to black with no fill.
          VlnivelTQ27Camboata.BackgroundColor = vbBlack
          VlnivelTQ27Camboata.LineColor = pbRed
      End Sub
      
      Private Sub Retângulo3_Click(ByVal lvarX As Long, ByVal lvarY As Long)
          StopSound
          ' Set color back to black with no fill.
          VlnivelTQ03Tororo.BackgroundColor = vbBlack
          VlnivelTQ03Tororo.LineColor = pbRed
      End Sub
      
      Private Sub Retângulo9_Click(ByVal lvarX As Long, ByVal lvarY As Long)
          StopSound
          ' Set color back to black with no fill.
          VlnivelTQ08Pereira.BackgroundColor = vbBlack
          VlnivelTQ08Pereira.LineColor = pbRed
      End Sub
      
      Private Sub ReconhecerAlarm3_Click(ByVal lvarX As Long, ByVal lvarY As Long)
      
      StopSound
          ' Set color back to black with no fill.
          VlnivelTQ01EIABuracica.BackgroundColor = vbBlack
          VlnivelTQ01EIABuracica.LineColor = pbRed
      
      End Sub
      
      Private Sub ReconhecerAlarm1_Click(ByVal lvarX As Long, ByVal lvarY As Long)
      
      StopSound
          ' Set color back to black with no fill.
          VlnivelSAO01ETOBuracica.BackgroundColor = vbBlack
          VlnivelSAO01ETOBuracica.LineColor = pbRed
      
      End Sub
      
      Private Sub ReconhecerAlarm2_Click(ByVal lvarX As Long, ByVal lvarY As Long)
      
      StopSound
      ' Set color back to black with no fill.
          VlvazaoPIT218InjecaoETOBuracica.BackgroundColor = vbBlack
          VlvazaoPIT218InjecaoETOBuracica.LineColor = pbRed
      
      End Sub
      
      
      Private Sub ReconhecerAlarm4_Click(ByVal lvarX As Long, ByVal lvarY As Long)
      
      StopSound
      ' Set color back to black with no fill.
          VlnivelTQ21CAMBOATA.BackgroundColor = vbBlack
          VlnivelTQ21CAMBOATA.LineColor = pbRed
      
      End Sub
      
      
      Private Sub ReconhecerAlarm7_Click(ByVal lvarX As Long, ByVal lvarY As Long)
      
      StopSound
      ' Set color back to black with no fill.
          VlnivelTQ22CAMBOATA.BackgroundColor = vbBlack
          VlnivelTQ22CAMBOATA.LineColor = pbRed
      

       

       

       

       

       

      Thanks!