beautypg.com

Campbell Scientific CS125 Present Weather Sensor User Manual

Page 63

background image

Appendix C. Example CRBasic programs

C-9

'CS215 Temperature & Relative Humidity Sensor measurements AirTC and RH
SDI12Recorder(TRHData(),5,"0","M!",1,0)

'Calculate DewPoint
DewPoint(TempDewPoint,AirTC,RH)

' Gather the current settings from the CS125
SerialFlush (Com1)
TempString = "GET:0:0"
CheckVal = CheckSum (TempString,1,0) ' Use the CCITT CRC16 checksum
OutString = CHR(2) + TempString + ":" + FormatLong (CheckVal,"%04X") + ":" +
CHR(3) + CHR(13) + CHR(10)
SerialOut (Com1,OutString,"",0,100) ' Send GET command to the CS125
Delay (1,1,Sec)
SerialIn (InStringGET,Com1,100,0,200) ' Save the data returned from the GET
command
If Len(InStringGET) > 1 Then ' Check data was returned
SplitStr (CS125CArray(1),InStringGET, " ",21,5) ' Strip the settings from the
returned data string
CS125CArray(1) = Right (CS125CArray(1),1)' Trim the SOT from the first data
point
EndIf

'Enable Dew Heaters if AirTC < DewPoint
If AirTC <= TempDewPoint AND StatusDewHeater=False Then
CS125CArray(17)=0
SerialFlush (Com1)
TempString = CS125_SETNCCommand()
SerialOut (Com1,TempString,"",0,100)
Delay (1,1,Sec)
SerialIn (InStringSETNC,Com1,100,0,1000)
StatusDewHeater=True
EndIf

'Disable Dew Heaters if AirTC > DewPoint+3
If AirTC > TempDewPoint+3 AND StatusDewHeater=True Then
CS125CArray(17)=1
SerialFlush (Com1)
TempString = CS125_SETNCCommand()
SerialOut (Com1,TempString,"",0,100)
Delay (1,1,Sec)
SerialIn (InStringSETNC,Com1,100,0,1000)

StatusDewHeater=False
EndIf

NextScan
EndProg