User Guide
21
4.3.1.2
Example using RS-485 mode
'-----------------------------------------------------------------------
' Example use of the SDM-SIO1.
' This example shows how to open the RS-485 serial port using an SDM-SIO1.
' Data is sent from the logger to the sensor.
' The program then sits in a loop until the SDM-SIO1 reports it had data
' available
' The 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-SIO1s buffer at present
Public ReturnedData as string * 100
'string where the data from the logger is stored
Public ConvertedValue as float
'floating point value returned by sensor
Sequentialmode
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-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 the sensor
'Request data' will need to be replaced with the correct command for your sensor
SerialOut (SensorPort,"Request data","",0,10)
'Send data to the sensor
' 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 (SensorPort)
' Get available data
AvailableData = ChkValReturned AND 4095
' mask off the input pin flag (bit 16)
Loop until AvailableData <> 0
' wait until data is available
SerialIn (ReturnedData,SensorPort,100,0,100)
' Get data from the sensor
'Convert string to float
ConvertedValue = ReturnedData
' add an offset to the returned floating point value
ConvertedValue = Converte 100
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