Example Using Rs-485 Mode - Campbell SDM-SI01A Product Manual

Table of Contents

Advertisement

B.2 Example using RS-485 mode
'-----------------------------------------------------------------------
'Example use of the SDM-SIO1A.
'This example shows how to open the RS-485 serial port using an SDM-SIO1A.
'Data is sent from the data logger to the sensor.
'The program then sits in a loop until the SDM-SIO1A reports it has data
'available
'The data logger then retrieves the data and places it into a string
'The returned string is then converted to a float and an offset is applied
'-----------------------------------------------------------------------
Public
ChkValReturned  'value returned by the SerialInChk function
Public
AvailableData  'amount of data in the SDM-SIO1As buffer at present
Public
ReturnedData
Public
ConvertedValue
SequentialMode
BeginProg
Const
SensorPort =
'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-485 mode, 115200bps, 8-bit data, 1 stop bit, and
'no parity
'note that the 'SerialOpenFormat' parameter is 19 for RS-485 mode
SerialOpen
(SensorPort,115200,19,100,10000)  'open the serial port to
'Request data' will need to be replaced with the correct command for
'your sensor
SerialOut
(SensorPort,"Request
'wait for the sensor to respond using a loop this time – this may be useful
'if there is not a predictable response from the sensor.
Do
 ChkValReturned =
 AvailableData = ChkValReturned
Loop Until
AvailableData <>
SerialIn
(ReturnedData,SensorPort,100,0,100)  'Get data from the sensor
CRBasic Example 4: RS-485 mode example
As String
*
100  'string where the data from the data logger
'is stored
As Float
'floating point value returned by sensor
32  'Declare the serial port the sensor is set to
data","",0,10)  'Send data to the sensor
SerialInChk
(SensorPort)  'Get available data
AND
0  'wait until data is available
SDM-SIO1A and SDM-SIO4A Serial Input/Output Modules
'the sensor
4095  'mask off the input pin flag
'(bit 16)
37

Advertisement

Table of Contents
loading

This manual is also suitable for:

Sdm-si04a

Table of Contents