Return

Visual Basic code for security alarm: check sensors and display status

Public Sub checkSensors()
'procedure to check inputs from sensors and tampers
'and set leds accordingly

Dim Door, Z1S, Z2S, ZBT, Z1T, Z2T As Integer
'masks and assignment for inputs as follows:
Door = 1 'bit1 = door contacts main entry/exit
Z1S = 2 'bit2 = zone1 sensor
Z2S = 4 'bit3 = zone2 sensor
' 'bit4 = not used
ZBT = 16 'bit5 = bell tamper
Z1T = 32 'bit6 = zone 1 tamper
Z2T = 64 'bit7 = zone 2 tamper
' 'bit8 = not used
'get the current state of sensors and tampers
InVal = readInputs
'show sensor and tamper status; latch positives on until alarm reset
If (InVal And Z1S) Then LED2Z1On (True) Else LED2Z1On (False)
If (InVal And Z2S) Then LED2Z2On (True) Else LED2Z2On (False)
If (InVal And Z1T) Then LED3Z1On (True) Else LED3Z1On (False)
If (InVal And Z2T) Then LED3Z2On (True) Else LED3Z2On (False)
'call Entry timer if only signal is from main entry/exit sensor
If (InVal = Door And AlSet) Then 'only main entry sensor activated
If TimerEntry.Enabled = False Then EntrySecs = EntryTime 'set countdown timer to entry time allowed
TimerEntry.Enabled = True 'start countdown; line above prevents from resetting every second!
'need to prevent recurrence when timeout complete!
End If
'other conditions start alarm immediately unless it has already timed out
If AlSet Then 'sensors only cause an alarm if alarm is set
If ((InVal And Z1S) And Z1On) Then Alarm
If ((InVal And Z2S) And Z2On) Then Alarm
End If
'tampers cause an alarm anytime
If ((InVal And Z1T) And Z1TOn) Then Alarm
If ((InVal And Z2T) And Z2TOn) Then Alarm
If ((InVal And ZBT) And ZBTOn) Then Alarm
'reset timeout automatically if all sensors and tampers clear
If InVal = 0 Then AlHasTimedOut = False
End Sub