|
liblightmodbus 3.0
A lightweight, header-only, hardware-agnostic Modbus RTU/TCP library
|
Slave's types and basic functions (header) More...
Include dependency graph for slave.h:
This graph shows which files directly or indirectly include this file:Go to the source code of this file.
Data Structures | |
| struct | ModbusSlaveFunctionHandler |
| Associates Modbus function ID with a pointer to a parsing function. More... | |
| struct | ModbusRegisterCallbackArgs |
| Contains arguments for the register callback function. More... | |
| struct | ModbusRegisterCallbackResult |
| Contains values returned by the slave register callback. More... | |
| struct | ModbusSlave |
| Slave device status. More... | |
Typedefs | |
| typedef struct ModbusSlave | ModbusSlave |
| typedef ModbusErrorInfo(* | ModbusRequestParsingFunction) (ModbusSlave *status, uint8_t function, const uint8_t *requestPDU, uint8_t requestLength) |
| A pointer to request parsing function. | |
| typedef struct ModbusSlaveFunctionHandler | ModbusSlaveFunctionHandler |
| Associates Modbus function ID with a pointer to a parsing function. | |
| typedef enum ModbusRegisterQuery | ModbusRegisterQuery |
| Determines type of request made to the register callback function. | |
| typedef struct ModbusRegisterCallbackArgs | ModbusRegisterCallbackArgs |
| Contains arguments for the register callback function. | |
| typedef struct ModbusRegisterCallbackResult | ModbusRegisterCallbackResult |
| Contains values returned by the slave register callback. | |
| typedef ModbusError(* | ModbusRegisterCallback) (const ModbusSlave *status, const ModbusRegisterCallbackArgs *args, ModbusRegisterCallbackResult *out) |
| A pointer to callback for performing all register operations. | |
| typedef ModbusError(* | ModbusSlaveExceptionCallback) (const ModbusSlave *status, uint8_t function, ModbusExceptionCode code) |
| A pointer to a callback called when a Modbus exception is generated (for slave) | |
Enumerations | |
| enum | ModbusRegisterQuery { MODBUS_REGQ_R_CHECK , MODBUS_REGQ_W_CHECK , MODBUS_REGQ_R , MODBUS_REGQ_W } |
| Determines type of request made to the register callback function. More... | |
Functions | |
| ModbusErrorInfomodbusSlaveInit (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. | |
| ModbusErrorInfomodbusBuildException (ModbusSlave *status, uint8_t function, ModbusExceptionCode code) | |
| Builds an exception response frame. | |
| ModbusErrorInfomodbusBuildExceptionPDU (ModbusSlave *status, uint8_t function, ModbusExceptionCode code) | |
| Builds an exception PDU. | |
| ModbusErrorInfomodbusBuildExceptionRTU (ModbusSlave *status, uint8_t address, uint8_t function, ModbusExceptionCode code) | |
| Builds a Modbus RTU exception. | |
| ModbusErrorInfomodbusBuildExceptionTCP (ModbusSlave *status, uint16_t transactionID, uint8_t unitID, uint8_t function, ModbusExceptionCode code) | |
| Builds a Modbus TCP exception. | |
| ModbusErrorInfomodbusParseRequest (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. | |
| ModbusErrorInfomodbusParseRequestPDU (ModbusSlave *status, const uint8_t *request, uint8_t requestLength) | |
| Parses provided PDU and generates PDU for the response frame. | |
| ModbusErrorInfomodbusParseRequestRTU (ModbusSlave *status, uint8_t slaveAddress, const uint8_t *request, uint16_t requestLength) | |
| Parses provided Modbus RTU request frame and generates a Modbus RTU response. | |
| ModbusErrorInfomodbusParseRequestTCP (ModbusSlave *status, const uint8_t *request, uint16_t requestLength) | |
| Parses provided Modbus TCP request frame and generates a Modbus TCP response. | |
| static const uint8_t * | modbusSlaveGetResponse (const ModbusSlave *status) |
| Returns a pointer to the response generated by the slave. | |
| static uint16_t | modbusSlaveGetResponseLength (const ModbusSlave *status) |
| Returns the length of the response generated by the slave. | |
| static void | modbusSlaveSetUserPointer (ModbusSlave *status, void *ptr) |
| Allows user to set the custom context pointer. | |
| static void * | modbusSlaveGetUserPointer (const ModbusSlave *status) |
| Retreieves the custom context pointer. | |
| static ModbusError | modbusSlaveAllocateResponse (ModbusSlave *status, uint16_t pduSize) |
| Allocates memory for slave's response frame. | |
| static void | modbusSlaveFreeResponse (ModbusSlave *status) |
| Frees memory allocated for slave's response frame. | |
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 |
| Stores length of modbusSlaveDefaultFunctions. | |
Slave's types and basic functions (header)
| typedef ModbusError(* ModbusRegisterCallback) (const ModbusSlave *status, const ModbusRegisterCallbackArgs *args, ModbusRegisterCallbackResult *out) |
A pointer to callback for performing all register operations.
| typedef struct ModbusRegisterCallbackArgs ModbusRegisterCallbackArgs |
Contains arguments for the register callback function.
| typedef struct ModbusRegisterCallbackResult ModbusRegisterCallbackResult |
Contains values returned by the slave register callback.
| typedef enum ModbusRegisterQuery ModbusRegisterQuery |
Determines type of request made to the register callback function.
| typedef ModbusErrorInfo(* ModbusRequestParsingFunction) (ModbusSlave *status, uint8_t function, const uint8_t *requestPDU, uint8_t requestLength) |
A pointer to request parsing function.
| typedef struct ModbusSlave ModbusSlave |
| typedef ModbusError(* ModbusSlaveExceptionCallback) (const ModbusSlave *status, uint8_t function, ModbusExceptionCode code) |
A pointer to a callback called when a Modbus exception is generated (for slave)
| typedef struct ModbusSlaveFunctionHandler ModbusSlaveFunctionHandler |
Associates Modbus function ID with a pointer to a parsing function.
| enum ModbusRegisterQuery |
| ModbusErrorInfomodbusBuildException | ( | 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).
Here is the call graph for this function:| ModbusErrorInfomodbusBuildExceptionPDU | ( | ModbusSlave * | status, |
| uint8_t | function, | ||
| ModbusExceptionCode | code ) |
Builds an exception PDU.
| function | function that reported the exception |
| code | Modbus exception code |
Here is the call graph for this function:| ModbusErrorInfomodbusBuildExceptionRTU | ( | 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 |
Here is the call graph for this function:| ModbusErrorInfomodbusBuildExceptionTCP | ( | 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 |
Here is the call graph for this function:| ModbusErrorInfomodbusParseRequest | ( | 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) |
| ModbusErrorInfomodbusParseRequestPDU | ( | 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.
Here is the call graph for this function:| ModbusErrorInfomodbusParseRequestRTU | ( | 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) |
Here is the call graph for this function:| ModbusErrorInfomodbusParseRequestTCP | ( | 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) |
Here is the call graph for this function:| ModbusErrorInfomodbusSlaveInit | ( | 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) |
|
inlinestatic |
Allocates memory for slave's response frame.
| pduSize | size of the PDU section. 0 if the slave doesn't want to respond. |
Here is the call graph for this function:
Here is the caller graph for this function:| void modbusSlaveDestroy | ( | ModbusSlave * | status | ) |
Frees memory allocated in the ModbusSlave struct.
Here is the call graph for this function:
Here is the caller graph for this function:
|
inlinestatic |
Frees memory allocated for slave's response frame.
Here is the call graph for this function:
Here is the caller graph for this function:
|
inlinestatic |
Returns a pointer to the response generated by the slave.
modbusParseRequest*() was successful (i.e. modbusIsOk() was true for the return value)
Here is the caller graph for this function:
|
inlinestatic |
Returns the length of the response generated by the slave.
modbusParseRequest*() was successful (i.e. modbusIsOk() was true for the return value)
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 modbusSlaveDefaultFunctions.
|
extern |
Associates function IDs with pointers to functions responsible for parsing. Length of this array is stored in modbusSlaveDefaultFunctionCount.
LIGHTMODBUS_FxxS macros!