Example Using Rs-485 Mode; Rs-485 Mode Example - Campbell SDM-SIO1A Instruction Manual

Serial input/output module
Hide thumbs Also See for SDM-SIO1A:
Table of Contents

Advertisement

6.3.2.2 Example using RS-485 Mode

CRBasic Example 6-2. RS-485 Mode Example
'-----------------------------------------------------------------------
'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 datalogger to the sensor.
'The program then sits in a loop until the SDM-SIO1A reports it has data
'available
'The datalogger 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
Public
AvailableData
Public
ReturnedData
as string
Public
ConvertedValue
as float
Sequentialmode
BeginProg
Const
SensorPort = 32
SDMSpeed
(30)
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)
'Request data' will need to be replaced with the correct command for your sensor
SerialOut
(SensorPort,"Request data","",0,10)
'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 =
SerialInChk
AvailableData = ChkValReturned
Loop until
AvailableData <> 0
SerialIn
(ReturnedData,SensorPort,100,0,100)
'Convert string to float
ConvertedValue = ReturnedData
'add an offset to the returned floating point value
ConvertedValue = ConvertedValue + 100
SerialClose
(SensorPort)
'this places the SDM-SIO1A into its lowest power mode
Next Scan
EndProg
'value returned by the SerialInChk function
'amount of data in the SDM-SIO1As buffer at present
* 100
'string where the data from the datalogger is stored
'floating point value returned by sensor
'Declare the serial port the sensor is set to
'The sensors address switch should be set to position 0
'Optionally set the SDMSpeed, not normally needed
(SensorPort)
AND
4095
SDM-SIO1A Serial Input/Output Module
'open the serial port to the sensor
'Send data to the sensor
'Get available data
'mask off the input pin flag (bit 16)
'wait until data is available
'Get data from the sensor
'Close the serial port to the sensor
21

Advertisement

Table of Contents
loading

Table of Contents