A.2 example programs, A.2.1 crbasic, A.2.1 – Campbell Scientific ENC10/12, ENC12/14, ENC14/16, ENC16/18 Enclosures User Manual
Page 33

Appendix A. Door Switch
A.2 Example Programs
A.2.1 CRBasic
'Program name: DOOR SWITCH CR1000.CR1
'Date written: 11/7/2005
'
' Door Switch Wiring
' +5V black - power to door switch
' C1 black - signal to control port 3
'\\\\\\\\\\\\\\\\\\\\\\\\\ DECLARATIONS /////////////////////////
Public DOOR_open_1
Public DOOR_output
'\\\\\\\\\\\\\\\\\\\\\\\\ OUTPUT SECTION ////////////////////////
DataTable(Table101,true,-1)
OpenInterval
DataInterval(0,5,Min,10)
Sample(1, DOOR_output, FP2)
EndTable
DataTable(Table102,true,-1)
OpenInterval
DataInterval(0,5,Min,10)
Histogram(DOOR_open_1, FP2, 0, 1,001, 1 , 0.5, 1.5)
EndTable
'\\\\\\\\\\\\\\\\\\\\\\\\\\\ PROGRAM ////////////////////////////
BeginProg
Scan(1,Sec, 3, 0)
' Configure control ports as inputs or outputs
PortsConfig (&B11111111,&B00000000)
' Measure Door switch
' (0=low=closed, 1=high=open)
If CheckPort(1) = true then
DOOR_open_1 = 1
Else
DOOR_open_1 = 0
EndIf
' Two of many possible methods to output the status of the door open switch
' - assumes 5 minute data:
' Method #1: If the door is open even one reading during the output interval,
' output a 1 for the Door variable
' If (DOOR_open_1 = 1)
Then
DOOR_output = 1
EndIf
CallTable Table101
' Reset door status after output interval
If TimeInToInterval(0,5,Min) Then
DOOR_output = 0
EndIf
' Method #2: Door open status may be recorded as a fraction of the output
' interval (between 0 and 1) using the Histogram instruction.
CallTable Table102
NextScan
EndProg
A-5