C-1
Appendix C. Example CRBasic programs
C.1 CRBasic read program
'CR800
'Demonstration program to read data from a CS120A set to continuous output
'with the default message being transmitted
'This is the default behaviour of the CS120A.
Public Visibility
'These variables could be defined as DIM in a final program
Public InString As String * 100 'Incoming string
Public SerialIndest(20) As String, NBytesReturned
Public ChecksumOK As Boolean
Public lngCRCCalc As Long, lngCRCMsg As Long
'Define the aliases for the full message
Alias SerialIndest(1)=Message_ID '0..2
Alias SerialIndest(2)=Sensor_ID '0..9
Alias SerialIndest(3)=System_status '0..3
Alias SerialIndest(4)=Interval_time '1..3600
Alias SerialIndest(5)=Visibilitystr '0..32000 metres
Alias SerialIndest(6)= VisibilityUnits 'M or F for Metres or Feet
Alias SerialIndest(7)=Averaging_duration '1 or 10 minutes
Alias SerialIndest(8)=User_alarm_1 '0..1 - Visibility compared to Threshold One
Alias SerialIndest(9)=User_alarm_2 '0..1 - Visibility compared to Threshold Two
Alias SerialIndest(10)=Emitter_failure '0..2 - Emitter Failure
Alias SerialIndest(11)=Emitter_lens_dirty '0..3 - Emitter Lens Dirty
Alias SerialIndest(12)=Emitter_temp_error '0..3 - Emitter Temperature
Alias SerialIndest(13)=Detector_lens_dirty '0..3 - Detector Lens Dirty
Alias SerialIndest(14)=Detector_temp_error '0..3 - Detector Temperature
Alias SerialIndest(15)=Detector_saturated '0..1 - Detector DC Saturation Level
Alias SerialIndest(16)=Hood_temp_error '0..3 - Hood Temperature
Alias SerialIndest(17)=Signature_error '0..1 - Signature Error
Alias SerialIndest(18)=Flash_read_error '0..1 - Flash Read Error
Alias SerialIndest(19)=Flash_write_error '0..1 - Flash Write Error
Alias SerialIndest(20) = checksumrx 'CCITT Checksum
'Define the serial port to which the CS120A is connected - amend as needed
Const CS120A_Comport = COM1
'Main Program
BeginProg
'Open the logger serial port to which the CS120A is connected
SerialOpen (CS120A_Comport,38400,3,0,1000)
Scan(10,Sec,1,0)
'Default behaviour is for the CS120A to send a message every 60 seconds
'so this will fail 5 times out of 6
SerialInRecord(CS120A_Comport,InString,&h02,0,&h03,NBytesReturned,01)
'Check that a message has been received first
If NBytesReturned > 0 Then
SplitStr (SerialIndest(),InString," ",20,5)
'Check the received checksum is valid
'Calculate the expected checksum
lngCRCCalc = CheckSum(InString,1,NBytesReturned-5)
'Extract the checksum from the message & convert it for comparison
lngCRCMsg = HexToDec(checksumrx)
ChecksumOK = ( lngCRCMsg = lngCRCCalc)
'In critical applications the visibility can be set to NaN if the system status
'is degraded or a critical error flag is set.
If ChecksumOK Then Visibility = Visibilitystr Else Visibility =NaN
EndIf
'Call data storage commands here
NextScan
EndProg
Содержание CS120A
Страница 2: ......
Страница 4: ......
Страница 6: ......
Страница 8: ......
Страница 23: ...User Guide 13...
Страница 24: ...CS120A Visibility Sensor 14...
Страница 25: ...User Guide 15...
Страница 50: ...CS120A Visibility Sensor A 2...
Страница 52: ...CS120A Visibility Sensor B 2...