liblightmodbus 3.0
A lightweight, header-only, hardware-agnostic Modbus RTU/TCP library
|
Master's types and basic functions (header) More...
Go to the source code of this file.
Data Structures | |
struct | ModbusMasterFunctionHandler |
Associates Modbus function ID with a pointer to a response parsing function. More... | |
struct | ModbusDataCallbackArgs |
Arguments for the data callback. More... | |
struct | ModbusMaster |
Master device status. More... | |
Typedefs | |
typedef struct ModbusMaster | ModbusMaster |
typedef ModbusErrorInfo(* | ModbusResponseParsingFunction) (ModbusMaster *status, uint8_t address, uint8_t function, const uint8_t *requestPDU, uint8_t requestLength, const uint8_t *responsePDU, uint8_t responseLength) |
A pointer to a response parsing function. | |
typedef struct ModbusMasterFunctionHandler | ModbusMasterFunctionHandler |
Associates Modbus function ID with a pointer to a response parsing function. | |
typedef struct ModbusDataCallbackArgs | ModbusDataCallbackArgs |
Arguments for the data callback. | |
typedef ModbusError(* | ModbusDataCallback) (const ModbusMaster *status, const ModbusDataCallbackArgs *args) |
A pointer to a callback used for handling data incoming to master. | |
typedef ModbusError(* | ModbusMasterExceptionCallback) (const ModbusMaster *status, uint8_t address, uint8_t function, ModbusExceptionCode code) |
A pointer to a callback called when a Modbus exception is generated (for master) | |
Functions | |
ModbusErrorInfo | modbusMasterInit (ModbusMaster *status, ModbusDataCallback dataCallback, ModbusMasterExceptionCallback exceptionCallback, ModbusAllocator allocator, const ModbusMasterFunctionHandler *functions, uint8_t functionCount) |
Initializes a ModbusMaster struct. | |
void | modbusMasterDestroy (ModbusMaster *status) |
Deinitializes a ModbusMaster struct. | |
ModbusErrorInfo | modbusBeginRequestPDU (ModbusMaster *status) |
Begins a PDU-only request. | |
ModbusErrorInfo | modbusEndRequestPDU (ModbusMaster *status) |
Finalizes a PDU-only request. | |
ModbusErrorInfo | modbusBeginRequestRTU (ModbusMaster *status) |
Begins a RTU request. | |
ModbusErrorInfo | modbusEndRequestRTU (ModbusMaster *status, uint8_t address) |
Finalizes a Modbus RTU request. | |
ModbusErrorInfo | modbusBeginRequestTCP (ModbusMaster *status) |
Begins a TCP request. | |
ModbusErrorInfo | modbusEndRequestTCP (ModbusMaster *status, uint16_t transaction, uint8_t unit) |
Finalizes a Modbus TCP request. | |
ModbusErrorInfo | modbusParseResponsePDU (ModbusMaster *status, uint8_t address, const uint8_t *request, uint8_t requestLength, const uint8_t *response, uint8_t responseLength) |
Parses a PDU section of a slave response. | |
ModbusErrorInfo | modbusParseResponseRTU (ModbusMaster *status, const uint8_t *request, uint16_t requestLength, const uint8_t *response, uint16_t responseLength) |
Parses a Modbus RTU slave response. | |
ModbusErrorInfo | modbusParseResponseTCP (ModbusMaster *status, const uint8_t *request, uint16_t requestLength, const uint8_t *response, uint16_t responseLength) |
Parses a Modbus TCP slave response. | |
static const uint8_t * | modbusMasterGetRequest (const ModbusMaster *status) |
Returns a pointer to the request generated by the master. | |
static uint16_t | modbusMasterGetRequestLength (const ModbusMaster *status) |
Returns the length of the request generated by the master. | |
static void | modbusMasterSetUserPointer (ModbusMaster *status, void *ptr) |
Allows user to set the custom context pointer. | |
static void * | modbusMasterGetUserPointer (const ModbusMaster *status) |
Retreieves the custom context pointer. | |
static ModbusError | modbusMasterAllocateRequest (ModbusMaster *status, uint16_t pduSize) |
Allocates memory for the request frame. | |
static void | modbusMasterFreeRequest (ModbusMaster *status) |
Frees memory allocated for master's request frame. | |
Variables | |
ModbusMasterFunctionHandler | modbusMasterDefaultFunctions [] |
Default array of supported functions. Length is stored in modbusMasterDefaultFunctionCount. | |
const uint8_t | modbusMasterDefaultFunctionCount |
Stores length of modbusMasterDefaultFunctions array. | |
Master's types and basic functions (header)
typedef ModbusError(* ModbusDataCallback) (const ModbusMaster *status, const ModbusDataCallbackArgs *args) |
A pointer to a callback used for handling data incoming to master.
typedef struct ModbusDataCallbackArgs ModbusDataCallbackArgs |
Arguments for the data callback.
typedef struct ModbusMaster ModbusMaster |
typedef ModbusError(* ModbusMasterExceptionCallback) (const ModbusMaster *status, uint8_t address, uint8_t function, ModbusExceptionCode code) |
A pointer to a callback called when a Modbus exception is generated (for master)
typedef struct ModbusMasterFunctionHandler ModbusMasterFunctionHandler |
Associates Modbus function ID with a pointer to a response parsing function.
typedef ModbusErrorInfo(* ModbusResponseParsingFunction) (ModbusMaster *status, uint8_t address, uint8_t function, const uint8_t *requestPDU, uint8_t requestLength, const uint8_t *responsePDU, uint8_t responseLength) |
A pointer to a response parsing function.
ModbusErrorInfo modbusBeginRequestPDU | ( | ModbusMaster * | status | ) |
ModbusErrorInfo modbusBeginRequestRTU | ( | ModbusMaster * | status | ) |
ModbusErrorInfo modbusBeginRequestTCP | ( | ModbusMaster * | status | ) |
ModbusErrorInfo modbusEndRequestPDU | ( | ModbusMaster * | status | ) |
Finalizes a PDU-only request.
ModbusErrorInfo modbusEndRequestRTU | ( | ModbusMaster * | status, |
uint8_t | address | ||
) |
Finalizes a Modbus RTU request.
ModbusErrorInfo modbusEndRequestTCP | ( | ModbusMaster * | status, |
uint16_t | transactionID, | ||
uint8_t | unitID | ||
) |
Finalizes a Modbus TCP request.
transactionID | Modbus TCP transaction identifier |
unitID | Modbus TCP Unit ID |
|
inlinestatic |
Allocates memory for the request frame.
pduSize | size of the PDU section of the frame. 0 implies no request at all. |
void modbusMasterDestroy | ( | ModbusMaster * | status | ) |
Deinitializes a ModbusMaster struct.
status | ModbusMaster struct to be destroyed |
status
pointer and only cleans up the interals ofthe ModbusMaster struct.
|
inlinestatic |
Frees memory allocated for master's request frame.
|
inlinestatic |
Returns a pointer to the request generated by the master.
|
inlinestatic |
Returns the length of the request generated by the master.
|
inlinestatic |
Retreieves the custom context pointer.
ModbusErrorInfo modbusMasterInit | ( | ModbusMaster * | status, |
ModbusDataCallback | dataCallback, | ||
ModbusMasterExceptionCallback | exceptionCallback, | ||
ModbusAllocator | allocator, | ||
const ModbusMasterFunctionHandler * | functions, | ||
uint8_t | functionCount | ||
) |
Initializes a ModbusMaster struct.
status | ModbusMaster struct to be initialized |
dataCallback | Callback function for handling incoming data (may be required by used parsing functions) |
exceptionCallback | Callback function for handling slave exceptions (optional) |
allocator | Memory allocator to be used (see modbusDefaultAllocator()) (required) |
functions | Pointer to an array of supported function handlers (required). The lifetime of this array must not be shorter than the lifetime of the master. |
functionCount | Number of elements in the functions array (required) |
|
inlinestatic |
Allows user to set the custom context pointer.
ModbusErrorInfo modbusParseResponsePDU | ( | ModbusMaster * | status, |
uint8_t | address, | ||
const uint8_t * | request, | ||
uint8_t | requestLength, | ||
const uint8_t * | response, | ||
uint8_t | responseLength | ||
) |
Parses a PDU section of a slave response.
address | Value to be reported as slave address |
request | Pointer to the PDU section of the request frame |
requestLength | Length of the request PDU (valid range: 1 - 253) |
response | Pointer to the PDU section of the response |
responseLength | Length of the response PDU (valid range: 1 - 253) |
ModbusErrorInfo modbusParseResponseRTU | ( | ModbusMaster * | status, |
const uint8_t * | request, | ||
uint16_t | requestLength, | ||
const uint8_t * | response, | ||
uint16_t | responseLength | ||
) |
Parses a Modbus RTU slave response.
request | Pointer to the request frame |
requestLength | Length of the request (valid range: 4 - 256) |
response | Pointer to the response frame |
responseLength | Length of the response (valid range: 4 - 256) |
ModbusErrorInfo modbusParseResponseTCP | ( | ModbusMaster * | status, |
const uint8_t * | request, | ||
uint16_t | requestLength, | ||
const uint8_t * | response, | ||
uint16_t | responseLength | ||
) |
Parses a Modbus TCP slave response.
request | Pointer to the request frame |
requestLength | Length of the request (valid range: 8 - 260) |
response | Pointer to the response frame |
responseLength | Length of the response (valid range: 8 - 260) |
|
extern |
Stores length of modbusMasterDefaultFunctions array.
|
extern |
Default array of supported functions. Length is stored in modbusMasterDefaultFunctionCount.
Contents are controlled by defining LIGHTMODBUS_FxxM
macros.