3 example datalogger programs, 1 example using rs-232 mode, Example datalogger programs – Campbell Scientific SDM-SIO1 Serial Input/Output Module User Manual

Page 26: Example using rs-232 mode

Advertising
background image

SDM-SIO1 Serial Input/Output Module

4.3 Example Datalogger Programs

Some simple examples of how to write programs in CRBasic to send and
receive data using the SDM-SIO1 follow. These programs are not extensive
and are fundamentally no different to those written for use when reading data
from a standard serial port.

The exact program to be used will vary with the serial device being used.
Unfortunately the number of possible variations of reading different sensors is
almost infinite. If you are struggling to write code please contact Campbell
Scientific who may already have experience with the sensor and may be able to
offer advice on how to deal with it.

4.3.1 Example Using RS-232 Mode

'-----------------------------------------------------------------------
' Example use of the SDM-SIO1.
' This example shows how to open the a serial port using an SDM-SIO1.
' A prompt is sent from the logger to the sensor and it then waits for a response
' before reading the data.
' The logger then retrieves the data and places it into a string
'-----------------------------------------------------------------------

Public ReturnedData as string * 100 'string where the data from the logger is stored

BeginProg

Const SensorPort = 32 'Declare the serial port the sensor is set to

'The sensors address switch should be set to position 0

SDMSpeed (30) 'Optionally set the SDMSpeed - not normally needed


Scan(1000,mSec,0,0)

'Open serial port to RS-232 mode, 115200bps, 8-bit data, 1 stop bit and no parity

SerialOpen

(SensorPort,115200,3,100,10000)

'open the serial port to the sensor


'Request data' will need to be replaced with the correct command for your sensor

'In this example we wait for the response Start, for up to 1 second before continuing

SerialOut

(SensorPort,"Request

data","Start",1,100) 'Send data to the sensor


SerialIn

(ReturnedData,SensorPort,100,0,100)

'Get data from the sensor


SerialClose

(SensorPort)

'Close the serial port to the sensor

'(this places the SDM-SIO1 into its lowest power mode)


'Now there would be code to read the data out of the ReturnedData string and either store

'it as strings or convert the string into number(s).


Next

Scan


EndProg

20

Advertising