CRBasic Example 1: Door switch example
'Program Name: DoorSwitchWithEventTable.CR1X
'This program creates a record each time the enclosure door opens or closes.
'It also records the door status at regular intervals.
' Door Switch Wiring
' +5V black - power to door switch
' C1 black - signal to control port 1
'\\\\\\\\\\\\\\\\\\\\\\\\\ DECLARATIONS /////////////////////////
Public
Door_Open
As Boolean
Dim
LastDoorState
As Boolean
'\\\\\\\\\\\\\\\\\\\\\\\\ OUTPUT SECTION ////////////////////////
'Records when door opens or closes
DataTable
(DoorEvent,Door_Open <> LastDoorState,100)
Sample
(1,Door_Open,Boolean)
EndTable
DataTable
(DoorStatus,true,-1)
DataInterval
(0,5,Min,10)
Sample
(1,Door_Open,Boolean)
EndTable
'\\\\\\\\\\\\\\\\\\\\\\\\\\\ PROGRAM ////////////////////////////
BeginProg
'Powers on NL241 attached to CS I/O for 5 minutes on powerup
IPNetPower
(3,1,300)
Scan
(1,Sec, 3, 0)
' Measure Door switch
PortGet
(Door_Open,C1)
'Powers on NL241 attached to CS I/O for 5 minutes if door open. This
'section not required if only the door status is required.
If
(Door_Open)
Then
IPNetPower
(3,1,300)
EndIf
CallTable
DoorEvent
CallTable
DoorStatus
LastDoorState = Door_Open
'Preserve door switch state for next scan.
NextScan
EndProg
Enclosures
30