28 #ifndef LIGHTMODBUS_SLAVE_H 29 #define LIGHTMODBUS_SLAVE_H 42 #ifdef LIGHTMODBUS_SLAVE_BASE 44 #ifdef LIGHTMODBUS_SLAVE_USER_FUNCTIONS 64 #if defined( LIGHTMODBUS_REGISTER_CALLBACK ) || defined( LIGHTMODBUS_COIL_CALLBACK ) 65 #ifndef LIGHTMODBUS_EXPERIMENTAL 66 #error Register callback functions are an experimental feature that may cause problems. Please define LIGHTMODBUS_EXPERIMENTAL to dismiss this error message. 101 #if defined( LIGHTMODBUS_COIL_CALLBACK ) || defined( LIGHTMODBUS_REGISTER_CALLBACK ) 118 #ifndef LIGHTMODBUS_REGISTER_CALLBACK 128 #ifndef LIGHTMODBUS_COIL_CALLBACK 152 #ifdef LIGHTMODBUS_SLAVE_USER_FUNCTIONS 174 #ifdef LIGHTMODBUS_STATIC_MEM_SLAVE_RESPONSE 175 uint8_t frame[LIGHTMODBUS_STATIC_MEM_SLAVE_RESPONSE];
197 #ifdef LIGHTMODBUS_STATIC_MEM_SLAVE_REQUEST 198 uint8_t frame[LIGHTMODBUS_STATIC_MEM_SLAVE_REQUEST];
201 const uint8_t *frame;
213 #ifdef LIGHTMODBUS_SLAVE_BASE static ModbusError modbusBuildExceptionErr(ModbusSlave *status, uint8_t function, ModbusExceptionCode code, ModbusFrameError parseError)
Handles Modbus parsing errors.
Definition: slave.h:292
uint16_t * inputRegisters
Pointer to input registers data.
Definition: slave.h:120
uint16_t registerCount
Slave's register count.
Definition: slave.h:124
ModbusError modbusSlaveInit(ModbusSlave *status)
Performs initialization of the ModbusSlave structure.
Definition: slave.c:222
ModbusSlaveUserFunction * userFunctions
A pointer to user defined Modbus functions array.
Definition: slave.h:159
uint8_t * coilMask
Masks for coil write protection (each bit corresponds to one coil)
Definition: slave.h:131
Asks callback function if register can be read.
Definition: slave.h:77
ModbusFrameError parseError
More specific error code of problem encountered during frame parsing.
Definition: slave.h:149
Asks callback function if register can be written.
Definition: slave.h:78
A NULL pointer provided as some crucial parameter.
Definition: lightmodbus.h:73
uint16_t userFunctionCount
Number of user-defined Modbus functions /see userFunctions.
Definition: slave.h:160
Represents Modbus slave device's status and configuration.
Definition: slave.h:96
ModbusExceptionCode lastException
Exception code of the last exception generated by modbusBuildException.
Definition: slave.h:141
uint16_t * registers
Pointer to registers data.
Definition: slave.h:119
A big union of structures used for parsing standard Modbus requests and building responses.
Definition: parser.h:43
Requests callback function to write the register.
Definition: slave.h:76
Requests callback function to return register value.
Definition: slave.h:75
Contains the modbusParser union used during frame creation and parsing.
uint16_t(* ModbusRegisterCallbackFunction)(ModbusRegisterQuery query, ModbusDataType datatype, uint16_t index, uint16_t value, void *ctx)
Type representing a pointer to the user-defined register callback function.
Definition: slave.h:90
ModbusError modbusSlaveEnd(ModbusSlave *status)
Frees memory used by slave structure, previously initialized with modbusSlaveInit.
Definition: slave.c:287
enum modbusExceptionCode ModbusExceptionCode
Represents a Modbus exception code, defined by the standart.
struct modbusSlaveUserFunction ModbusSlaveUserFunction
Associates user defined parser function with the function ID.
enum modbusFrameError ModbusFrameError
Provides more information on frame building/parsing error.
void * registerCallbackContext
The user data pointer passed to the callback function each time it's used.
Definition: slave.h:114
Definition: lightmodbus.h:81
uint8_t length
Frame length in bytes.
Definition: slave.h:183
ModbusError modbusBuildException(ModbusSlave *status, uint8_t function, ModbusExceptionCode code)
Builds an exception frame and stores it in the ModbusSlave structure.
Definition: slave.c:30
Associates user defined parser function with the function ID.
Definition: slave.h:51
ModbusRegisterCallbackFunction registerCallback
The pointer to the user-defined register callback function.
Definition: slave.h:107
uint8_t address
The slave's address.
Definition: slave.h:98
ModbusError(* handler)(struct modbusSlave *status, ModbusParser *parser)
Pointer to the user defined function.
Definition: slave.h:60
No error.
Definition: lightmodbus.h:51
uint8_t * registerMask
Mask for register write protection (each bit corresponds to one register)
Definition: slave.h:121
uint16_t discreteInputCount
Slave's discrete input count.
Definition: slave.h:135
struct modbusSlave ModbusSlave
Represents Modbus slave device's status and configuration.
uint16_t coilMaskLength
Write protection mask (coilMask) length in bytes (each byte covers 8 coils)
Definition: slave.h:132
uint8_t * discreteInputs
Pointer to discrete inputs data.
Definition: slave.h:130
modbusRegisterQuery
Represents register callback function.
Definition: slave.h:73
enum modbusRegisterQuery ModbusRegisterQuery
Represents register callback function.
uint16_t coilCount
Slave's coil count.
Definition: slave.h:134
uint16_t registerMaskLength
Write protection mask (registerMask) length in bytes (each byte covers 8 registers) ...
Definition: slave.h:122
uint16_t inputRegisterCount
Slave's input register count.
Definition: slave.h:125
uint8_t * coils
Pointer to coils data.
Definition: slave.h:129
ModbusError modbusParseRequest(ModbusSlave *status)
Interprets incoming Modbus request frame located in the slave structure.
Definition: slave.c:75
enum modbusDataType ModbusDataType
Stores information about Modbus data types.
enum modbusError ModbusError
Represents a library runtime error code.