liblightmodbus  2.0
A lightweight, cross-platform Modbus RTU library
Data Structures | Typedefs | Functions
master.h File Reference

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...
 

Detailed Description

General Modbus master functions.

Note
This header file is suitable for C++

Typedef Documentation

◆ ModbusMaster

typedef struct modbusMaster ModbusMaster

Represents Modbus master device's status and configuration.

◆ ModbusMasterUserFunction

Associates user-defined response parser function with the function ID.

Function Documentation

◆ modbusMasterEnd()

ModbusError modbusMasterEnd ( ModbusMaster status)

Frees memory used by the ModbusMaster structure, previously initialized with modbusMasterInit.

Parameters
statusThe master structure to be freed
Returns
A ModbusError error code

◆ modbusMasterInit()

ModbusError modbusMasterInit ( ModbusMaster status)

Performs initialization of the ModbusMaster structure.

Parameters
statusThe master structure to be initialized
Returns
A ModbusError error code

◆ modbusParseResponse()

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.

Parameters
statusThe master structure to work on
Returns
A ModbusError error code
+ Here is the call graph for this function: