liblightmodbus 3.0
A lightweight, header-only, hardware-agnostic Modbus RTU/TCP library
|
Master's types and basic functions (implementation) More...
Go to the source code of this file.
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 transactionID, uint8_t unitID) |
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. | |
Variables | |
ModbusMasterFunctionHandler | modbusMasterDefaultFunctions [] |
Default array of supported functions. Length is stored in modbusMasterDefaultFunctionCount. | |
const uint8_t | modbusMasterDefaultFunctionCount = sizeof(modbusMasterDefaultFunctions) / sizeof(modbusMasterDefaultFunctions[0]) - 1 |
Stores length of modbusMasterDefaultFunctions array. | |
Master's types and basic functions (implementation)
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 |
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. 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) |
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) |
const uint8_t modbusMasterDefaultFunctionCount = sizeof(modbusMasterDefaultFunctions) / sizeof(modbusMasterDefaultFunctions[0]) - 1 |
Stores length of modbusMasterDefaultFunctions array.
ModbusMasterFunctionHandler modbusMasterDefaultFunctions[] |
Default array of supported functions. Length is stored in modbusMasterDefaultFunctionCount.
Contents are controlled by defining LIGHTMODBUS_FxxM
macros.