liblightmodbus
2.0
A lightweight, cross-platform Modbus RTU library
|
Functions | |
ModbusError | modbusBuildException (ModbusSlave *status, uint8_t function, ModbusExceptionCode code) |
Builds an exception frame and stores it in the ModbusSlave structure. More... | |
ModbusError | modbusParseRequest (ModbusSlave *status) |
Interprets incoming Modbus request frame located in the slave structure. More... | |
ModbusError | modbusSlaveInit (ModbusSlave *status) |
Performs initialization of the ModbusSlave structure. More... | |
ModbusError | modbusSlaveEnd (ModbusSlave *status) |
Frees memory used by slave structure, previously initialized with modbusSlaveInit. More... | |
ModbusError modbusBuildException | ( | ModbusSlave * | status, |
uint8_t | function, | ||
ModbusExceptionCode | code | ||
) |
Builds an exception frame and stores it in the ModbusSlave structure.
The exception frame is only built if the request was not broadcasted.
Updates ModbusSlave::lastException member in provided ModbusSlave structure.
This function is used by more sophisticated modbusBuildExceptionErr().
status | The slave structure to work on |
function | Function code of function throwing the exception |
code | A Modbus exception code |
ModbusError modbusParseRequest | ( | ModbusSlave * | status | ) |
Interprets incoming Modbus request frame located in the slave structure.
Firstly, the function frees memory allocated for the previous response frame (ModbusSlave::response) (if dynamic memory allocation is enabled). Then, integrity of the frame is verified with modbusCRC function.
If the frame CRC is correct, the destination slave address is checked. Frames meant for other slave devices are discarded at this point.
Before attempting to parse the frame with one of the built-in parsing functions, the array of user-defined parsing functions is searched. It is important to mention that functions defined by user override the default ones. That is to say, a NULL pointer in the function array can disable support of specific function.
If matching function is found, it is exected and modbusParseRequest() returns the same error code the parsing function code had returned. Otherwise, an exception informing the master device of illegal function code is constructed, and MODBUS_ERROR_EXCEPTION is returned.
status | The slave structure to work on |
ModbusError modbusSlaveEnd | ( | ModbusSlave * | status | ) |
Frees memory used by slave structure, previously initialized with modbusSlaveInit.
status | The slave structure to work on |
ModbusError modbusSlaveInit | ( | ModbusSlave * | status | ) |
Performs initialization of the ModbusSlave structure.
status | The slave structure to be initialized |