beautypg.com

C.2 crbasic poll program – Campbell Scientific CS125 Present Weather Sensor User Manual

Page 57

background image

Appendix C. Example CRBasic programs

C-3

C.2 CRBasic POLL program

'CR800
'Demonstration program to read data from a CS125 set to polled output
'with the full SYNOP (default) message being transmitted
'Note: the sensor needs to be configured to behave like this, it is not setup by this
program.

Public Visibility
'These variables could be defined as DIM in a final program

Public InString As String * 100 'Incoming string
Public SerialIndest(27) 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)=External_temp_error '0..3 - External Temperature
Alias SerialIndest(18)=Signature_error '0..1 - Signature Error
Alias SerialIndest(19)=Flash_read_error '0..1 - Flash Read Error
Alias SerialIndest(20)=Flash_write_error '0..1 - Flash Write Error
Alias SerialIndest(21)=Particle_Limit_error '0 or 1 - Particle limit reached
Alias SerialIndest(22)=Particle_Count
Alias SerialIndest(23)=Intensity 'mm/h
Alias SerialIndest(24)=SYNOP_code
Alias SerialIndest(25)=Temperature 'deg C
Alias SerialIndest(26)=Relative_Humidity '%, 0..100
Alias SerialIndest(27) = checksumrx 'CCITT Checksum
'Define the serial port to which the CS125 is connected - amend as needed
Const CS125_Comport = COM1

'Preload the poll command for a sensor for address 0, in this example
'If the sensor has a different address uncomment the relevant line
Const CS125_Poll = CHR(2)&"POLL:0:0:3A3B:"&CHR(3)&CHR(13) 'address 0
'Const CS125_Poll = CHR(2)&"POLL:1:0:0D0B:"&CHR(3)&CHR(13) 'address 1
'Const CS125_Poll = CHR(2)&"POLL:2:0:545B:"&CHR(3)&CHR(13) 'address 2
'Const CS125_Poll = CHR(2)&"POLL:3:0:636B:"&CHR(3)&CHR(13) 'address 3
'Const CS125_Poll = CHR(2)&"POLL:4:0:E6FB:"&CHR(3)&CHR(13) 'address 4
'Const CS125_Poll = CHR(2)&"POLL:5:0:D1CB:"&CHR(3)&CHR(13) 'address 5
'Const CS125_Poll = CHR(2)&"POLL:6:0:889B:"&CHR(3)&CHR(13) 'address 6
'Const CS125_Poll = CHR(2)&"POLL:7:0:BFAB:"&CHR(3)&CHR(13) 'address 7