B.1 Example using RS-232 mode
CRBasic Example 3: RS-232 mode example
'-----------------------------------------------------------------------
' Example use of the SDM-SIO2R.
' This example shows how to open a serial port using an SDM-SIO2R.
' A prompt is sent from the data logger to the sensor and it then waits for a
' response before reading the data.
' The data logger then retrieves the data and places it into a string
'-----------------------------------------------------------------------
Public
ReturnedData
as string
* 100
'string where the data from the data 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-SIO2R 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
SDM-SIO2R Serial Input/Output Module with Switched Sensor Power
46