This is a sample Serial
communication implementation built for a controller that could be communicated with via Modbus
or Serial
.
There is one exposed function, writeSerial()
, that takes in four params:
portPath
[Required] : the direct path to your serial port (for Unix systems, something like/dev/tty.usbserial
, for WindowsCOM10
)baudRate
[Required] : the baud rate of the controller you're communicating withmessage
[Required]: message to sendexpectedLength
[Optional]: if there's a message expected to return, pass the expected length of that message here
Without providing expectedLength
, the first chunk of information that's provided will immediately cause the writeSerial()
function to return. The messages coming from the controller this implementation was built on would return messages in chunks, and it was required for the full message to be returned.
expectedLength
allows for multiple-chunk messages to be queued up before returns to upper layers- Timeouts: if either
expectedLength
or no information is returned, the upper layers recieve a timeout message