|
liblightmodbus 3.0
A lightweight, header-only, hardware-agnostic Modbus RTU/TCP library
|
Master's types and basic functions (header) More...
Include dependency graph for master.h:
This graph shows which files directly or indirectly include this file: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 | |
| ModbusErrorInfomodbusMasterInit (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. | |
| ModbusErrorInfomodbusBeginRequestPDU (ModbusMaster *status) | |
| Begins a PDU-only request. | |
| ModbusErrorInfomodbusEndRequestPDU (ModbusMaster *status) | |
| Finalizes a PDU-only request. | |
| ModbusErrorInfomodbusBeginRequestRTU (ModbusMaster *status) | |
| Begins a RTU request. | |
| ModbusErrorInfomodbusEndRequestRTU (ModbusMaster *status, uint8_t address) | |
| Finalizes a Modbus RTU request. | |
| ModbusErrorInfomodbusBeginRequestTCP (ModbusMaster *status) | |
| Begins a TCP request. | |
| ModbusErrorInfomodbusEndRequestTCP (ModbusMaster *status, uint16_t transaction, uint8_t unit) | |
| Finalizes a Modbus TCP request. | |
| ModbusErrorInfomodbusParseResponsePDU (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. | |
| ModbusErrorInfomodbusParseResponseRTU (ModbusMaster *status, const uint8_t *request, uint16_t requestLength, const uint8_t *response, uint16_t responseLength) | |
| Parses a Modbus RTU slave response. | |
| ModbusErrorInfomodbusParseResponseTCP (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.
| ModbusErrorInfomodbusBeginRequestPDU | ( | ModbusMaster * | status | ) |
| ModbusErrorInfomodbusBeginRequestRTU | ( | ModbusMaster * | status | ) |
| ModbusErrorInfomodbusBeginRequestTCP | ( | ModbusMaster * | status | ) |
| ModbusErrorInfomodbusEndRequestPDU | ( | ModbusMaster * | status | ) |
Finalizes a PDU-only request.
| ModbusErrorInfomodbusEndRequestRTU | ( | ModbusMaster * | status, |
| uint8_t | address ) |
Finalizes a Modbus RTU request.
Here is the call graph for this function:| ModbusErrorInfomodbusEndRequestTCP | ( | ModbusMaster * | status, |
| uint16_t | transactionID, | ||
| uint8_t | unitID ) |
Finalizes a Modbus TCP request.
| transactionID | Modbus TCP transaction identifier |
| unitID | Modbus TCP Unit ID |
Here is the call graph for this function:| ModbusErrorInfomodbusMasterInit | ( | 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) |
| ModbusErrorInfomodbusParseResponsePDU | ( | 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) |
| ModbusErrorInfomodbusParseResponseRTU | ( | 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) |
Here is the call graph for this function:| ModbusErrorInfomodbusParseResponseTCP | ( | 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) |
Here is the call graph for this function:
|
inlinestatic |
Allocates memory for the request frame.
| pduSize | size of the PDU section of the frame. 0 implies no request at all. |
Here is the call graph for this function:
Here is the caller graph for this function:| 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.
Here is the call graph for this function:
Here is the caller graph for this function:
|
inlinestatic |
Frees memory allocated for master's request frame.
Here is the call graph for this function:
Here is the caller graph for this function:
|
inlinestatic |
Returns a pointer to the request generated by the master.
Here is the caller graph for this function:
|
inlinestatic |
Returns the length of the request generated by the master.
Here is the caller graph for this function:
|
inlinestatic |
Retreieves the custom context pointer.
Here is the caller graph for this function:
|
inlinestatic |
Allows user to set the custom context pointer.
Here is the caller graph for this function:
|
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.