Appendix B. Example Programs
B-3
B.3 CR1000 RS-232 Program
Although this is a CR1000 program, other CRBasic dataloggers are
programmed similarly.
CRBasic Example B-3. CR1000 RS-232 Program
'CR1000 Series Datalogger
'Declare Public Variables
Public
RS232 (5)
Public
Counter
Public
OutString As String * 20
Public
OutString2 As String * 10
Public InString As String * 100
'Declare Other Variables
'RS232(1) is the address
Alias
RS232(2) = OBS
Alias
RS232(3) = SS
Alias
RS232(4) = Temp
Alias
RS232(5) = WetDry
'Define Data Tables
DataTable
(Test,1,1000)
DataInterval
(0,60,Min,10)
Sample
(1,OBS,FP2)
Sample
(1,SS,FP2)
Sample
(1,Temp,FP2)
Sample
(1,WetDry,FP2)
EndTable
'Main Program
BeginProg
SerialOpen
(Com1,9600,0,0,150)
Scan
(30,Sec,0,0)
OutString2 = CHR (13)
'a series of carriage returns will put OBS501 into RS-232 mode
OutString = "0M!" + CHR (13)
'address and then use commands M to M8
'Send String over communication port C1 (COM1 TX).
SerialOut
(Com1,OutString2,"OBS_500",15,100)
'put OBS501 into RS232 mode
delay
(1,1,Sec)
SerialOut
(Com1,OutString,"",0,1000)
'send command,
'Receive String over communication port C1 (COM1 RX).
SerialIn
(InString,Com1,5,33,150)
'The sensor echoes back the command ending with an "!" (CHR 33)
SerialIn
(InString,Com1,2500,62,150)
'The sensor will open, close and after about 20 seconds
'send "OBS_500>" and then the data. CHR 62 is ">"
SerialIn
(InString,Com1,100,13,200)
'Now the data comes ending with a carriage return, CHR 13
SplitStr
(RS232(),InString,"",5,0)
'Split the ASCII string into numeric variables
'Call Output Tables
'Example:
CallTable
Test
NextScan
EndProg