liblightmodbus 3.0
A lightweight, header-only, hardware-agnostic Modbus RTU/TCP library
|
Slave's types and basic functions (implementation) More...
Go to the source code of this file.
Functions | |
ModbusErrorInfo | modbusSlaveInit (ModbusSlave *status, ModbusRegisterCallback registerCallback, ModbusSlaveExceptionCallback exceptionCallback, ModbusAllocator allocator, const ModbusSlaveFunctionHandler *functions, uint8_t functionCount) |
Initializes slave device. | |
void | modbusSlaveDestroy (ModbusSlave *status) |
Frees memory allocated in the ModbusSlave struct. | |
ModbusErrorInfo | modbusBuildException (ModbusSlave *status, uint8_t function, ModbusExceptionCode code) |
Builds an exception response frame. | |
ModbusErrorInfo | modbusBuildExceptionPDU (ModbusSlave *status, uint8_t function, ModbusExceptionCode code) |
Builds an exception PDU. | |
ModbusErrorInfo | modbusBuildExceptionRTU (ModbusSlave *status, uint8_t address, uint8_t function, ModbusExceptionCode code) |
Builds a Modbus RTU exception. | |
ModbusErrorInfo | modbusBuildExceptionTCP (ModbusSlave *status, uint16_t transactionID, uint8_t unitID, uint8_t function, ModbusExceptionCode code) |
Builds a Modbus TCP exception. | |
ModbusErrorInfo | modbusParseRequest (ModbusSlave *status, const uint8_t *request, uint8_t requestLength) |
Parses provided PDU and generates response honorinng pduOffset and padding set in ModbusSlave during response generation. | |
ModbusErrorInfo | modbusParseRequestPDU (ModbusSlave *status, const uint8_t *request, uint8_t requestLength) |
Parses provided PDU and generates PDU for the response frame. | |
ModbusErrorInfo | modbusParseRequestRTU (ModbusSlave *status, uint8_t slaveAddress, const uint8_t *request, uint16_t requestLength) |
Parses provided Modbus RTU request frame and generates a Modbus RTU response. | |
ModbusErrorInfo | modbusParseRequestTCP (ModbusSlave *status, const uint8_t *request, uint16_t requestLength) |
Parses provided Modbus TCP request frame and generates a Modbus TCP response. | |
Variables | |
ModbusSlaveFunctionHandler | modbusSlaveDefaultFunctions [] |
Associates function IDs with pointers to functions responsible for parsing. Length of this array is stored in modbusSlaveDefaultFunctionCount. | |
const uint8_t | modbusSlaveDefaultFunctionCount = sizeof(modbusSlaveDefaultFunctions) / sizeof(modbusSlaveDefaultFunctions[0]) - 1 |
Stores length of modbusSlaveDefaultFunctions. | |
Slave's types and basic functions (implementation)
ModbusErrorInfo modbusBuildException | ( | ModbusSlave * | status, |
uint8_t | function, | ||
ModbusExceptionCode | code | ||
) |
Builds an exception response frame.
function | function that reported the exception |
code | Modbus exception code |
exceptionCallback
from ModbusSlave is called, even if the response frame is going to be discarded (when the request was broadcast).ModbusErrorInfo modbusBuildExceptionPDU | ( | ModbusSlave * | status, |
uint8_t | function, | ||
ModbusExceptionCode | code | ||
) |
Builds an exception PDU.
function | function that reported the exception |
code | Modbus exception code |
ModbusErrorInfo modbusBuildExceptionRTU | ( | ModbusSlave * | status, |
uint8_t | address, | ||
uint8_t | function, | ||
ModbusExceptionCode | code | ||
) |
Builds a Modbus RTU exception.
address | slave address to be reported in the excetion |
function | function that reported the exception |
code | Modbus exception code |
ModbusErrorInfo modbusBuildExceptionTCP | ( | ModbusSlave * | status, |
uint16_t | transactionID, | ||
uint8_t | unitID, | ||
uint8_t | function, | ||
ModbusExceptionCode | code | ||
) |
Builds a Modbus TCP exception.
transactionID | transaction ID |
unitID | unit ID to be reported in the exception |
function | function that reported the exception |
code | Modbus exception code |
ModbusErrorInfo modbusParseRequest | ( | ModbusSlave * | status, |
const uint8_t * | request, | ||
uint8_t | requestLength | ||
) |
Parses provided PDU and generates response honorinng pduOffset
and padding
set in ModbusSlave during response generation.
request | pointer to the PDU data |
requestLength | length of the PDU (valid range: 1 - 253) |
ModbusErrorInfo modbusParseRequestPDU | ( | ModbusSlave * | status, |
const uint8_t * | request, | ||
uint8_t | requestLength | ||
) |
Parses provided PDU and generates PDU for the response frame.
request | pointer to the PDU data |
requestLength | length of the PDU (valid range: 1 - 253) |
requestLength
argument is of type uint8_t
and not uint16_t
as in case of Modbus RTU and TCP. ModbusErrorInfo modbusParseRequestRTU | ( | ModbusSlave * | status, |
uint8_t | slaveAddress, | ||
const uint8_t * | request, | ||
uint16_t | requestLength | ||
) |
Parses provided Modbus RTU request frame and generates a Modbus RTU response.
slaveAddress | ID of the slave to match with the request |
request | pointer to a Modbus RTU frame |
requestLength | length of the frame (valid range: 4 - 256) |
ModbusErrorInfo modbusParseRequestTCP | ( | ModbusSlave * | status, |
const uint8_t * | request, | ||
uint16_t | requestLength | ||
) |
Parses provided Modbus TCP request frame and generates a Modbus TCP response.
request | pointer to a Modbus TCP frame |
requestLength | length of the frame (valid range: 8 - 260) |
void modbusSlaveDestroy | ( | ModbusSlave * | status | ) |
Frees memory allocated in the ModbusSlave struct.
ModbusErrorInfo modbusSlaveInit | ( | ModbusSlave * | status, |
ModbusRegisterCallback | registerCallback, | ||
ModbusSlaveExceptionCallback | exceptionCallback, | ||
ModbusAllocator | allocator, | ||
const ModbusSlaveFunctionHandler * | functions, | ||
uint8_t | functionCount | ||
) |
Initializes slave device.
registerCallback | Callback function for handling all register operations (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 array of supported function handlers (required). The lifetime of this array must not be shorter than the lifetime of the slave. |
functionCount | Number of function handlers in the array (required) |
const uint8_t modbusSlaveDefaultFunctionCount = sizeof(modbusSlaveDefaultFunctions) / sizeof(modbusSlaveDefaultFunctions[0]) - 1 |
Stores length of modbusSlaveDefaultFunctions.
ModbusSlaveFunctionHandler modbusSlaveDefaultFunctions[] |
Associates function IDs with pointers to functions responsible for parsing. Length of this array is stored in modbusSlaveDefaultFunctionCount.
LIGHTMODBUS_FxxS
macros!