liblightmodbus
2.0
A lightweight, cross-platform Modbus RTU library
|
General Modbus master functions. More...
Go to the source code of this file.
Data Structures | |
struct | modbusMasterUserFunction |
Associates user-defined response parser function with the function ID. More... | |
struct | modbusMaster |
Represents Modbus master device's status and configuration. More... | |
Typedefs | |
typedef struct modbusMasterUserFunction | ModbusMasterUserFunction |
Associates user-defined response parser function with the function ID. More... | |
typedef struct modbusMaster | ModbusMaster |
Represents Modbus master device's status and configuration. More... | |
Functions | |
ModbusError | modbusParseResponse (ModbusMaster *status) |
Interprets the incoming response frame located in the master structure. More... | |
ModbusError | modbusMasterInit (ModbusMaster *status) |
Performs initialization of the ModbusMaster structure. More... | |
ModbusError | modbusMasterEnd (ModbusMaster *status) |
Frees memory used by the ModbusMaster structure, previously initialized with modbusMasterInit. More... | |
General Modbus master functions.
typedef struct modbusMaster ModbusMaster |
Represents Modbus master device's status and configuration.
typedef struct modbusMasterUserFunction ModbusMasterUserFunction |
Associates user-defined response parser function with the function ID.
ModbusError modbusMasterEnd | ( | ModbusMaster * | status | ) |
Frees memory used by the ModbusMaster structure, previously initialized with modbusMasterInit.
status | The master structure to be freed |
ModbusError modbusMasterInit | ( | ModbusMaster * | status | ) |
Performs initialization of the ModbusMaster structure.
status | The master structure to be initialized |
ModbusError modbusParseResponse | ( | ModbusMaster * | status | ) |
Interprets the incoming response frame located in the master structure.
Calling this function results in processing the frame located in ModbusMaster::response. The received data will be located in ModbusMaster::data or ModbusMaster::exception if slave has responded with an exception frame.
Firstly, this function resets and freed data previously stored in ModbusMaster::exception and ModbusMaster::data.
Afterwards, the frame is validated using modbusCRC() function. If it's not consistent, it's discarded at this point and MODBUS_ERROR_PARSE is returned.
Then, array of user-defined functions is searched. It is important to mention that, user functions override built-in functions. That means, one can disable specific function by simply inserting NULL pointer into the array,
If matching function is found among user-defined or built-in functions, the modbusParseResponse() returns the exact error code the parsing function had returned. Otherwise, MODBUS_ERROR_PARSE is returned.
status | The master structure to work on |