2 cr1000 example (rs-232 mode) – Campbell Scientific SR50A Distance Sensor User Manual

Page 38

Advertising
background image

SR50A Sonic Ranging Sensor

10.2.2 CR1000 Example (RS-232 Mode)

'CR1000 Series Datalogger

'In this example, the SR50AT is mounted 2.5 meters above the ground.
'The SR50AT is used in RS-232 mode (internal jumpers are set).
'The CR1000 sends a serial string to the SR50AT, which is in "Measure on Poll Mode",
'and then receives a serial string in return which is parsed into different values.

'Wiring: Black: Power Ground
' clear: Power

Ground

' Red:

+12V,

' White:

C1

' Green:

C2


'Declare Variables
'Declare SR50AData as a dimensioned string of maximum 50 chrs
Dim SR50AData as STRING * 50

Public ParseVals(6) as FLOAT

Alias ParseVals(1)=SerialAddress
Alias ParseVals(2)=Dist_To_Snow
Alias ParseVals(3)=SignalQuality
Alias ParseVals(4)=SR50AT_Temp
Alias ParseVals(5)=Diagnostics
Alias ParseVals(6)=Chcksum

Public Snow_Depth

'Declare the initial distance of the SR50AT from the ground in meters:
Const Initial_Distance=2.5

'Define Data Tables
DataTable (Table1,True,-1)
DataInterval

(0,60,Min,10)

Sample

(1,Snow_Depth,FP2)

EndTable

'Main Program
BeginProg

'Open RS232 port for communications 9600 BAUD is the default:

SerialOpen

(Com1,9600,0,0,2000)

Scan

(10,Sec,0,0)

'Measure

the

SR50A:

'Transmit

serial

command

"p33<CR>"

SerialOut

(Com1,"p33"+chr(13),"",0,0)

'Flush the serial buffer

SerialFlush

(Com1)

'Recieve serial string from SR50A

SerialIn

(SR50AData,Com1,200,13,50)

SplitStr

(ParseVals,SR50AData,"",6,0)

32

Advertising