1#ifndef LIGHTMODBUS_MASTER_FUNC_H
2#define LIGHTMODBUS_MASTER_FUNC_H
16#define LIGHTMODBUS_DEFINE_BUILD_PDU_HEADER(f_suffix, ...) \
17 LIGHTMODBUS_WARN_UNUSED static inline ModbusErrorInfo modbusBuildRequest##f_suffix##PDU(ModbusMaster *status, __VA_ARGS__)
23#define LIGHTMODBUS_DEFINE_BUILD_PDU_BODY(f_suffix, ...) \
25 ModbusErrorInfo err; \
26 if (!modbusIsOk(err = modbusBeginRequestPDU(status))) return err; \
27 if (!modbusIsOk(err = modbusBuildRequest##f_suffix(status, __VA_ARGS__))) return err; \
28 return modbusEndRequestPDU(status); \
35#define LIGHTMODBUS_DEFINE_BUILD_RTU_HEADER(f_suffix, ...) \
36 LIGHTMODBUS_WARN_UNUSED static inline ModbusErrorInfo modbusBuildRequest##f_suffix##RTU(ModbusMaster *status, uint8_t address, __VA_ARGS__)
42#define LIGHTMODBUS_DEFINE_BUILD_RTU_BODY(f_suffix, ...) \
44 ModbusErrorInfo err; \
45 if (!modbusIsOk(err = modbusBeginRequestRTU(status))) return err; \
46 if (!modbusIsOk(err = modbusBuildRequest##f_suffix(status, __VA_ARGS__))) return err; \
47 return modbusEndRequestRTU(status, address); \
54#define LIGHTMODBUS_DEFINE_BUILD_TCP_HEADER(f_suffix, ...) \
55 LIGHTMODBUS_WARN_UNUSED static inline ModbusErrorInfo modbusBuildRequest##f_suffix##TCP(ModbusMaster *status, uint16_t transactionID, uint8_t unitID, __VA_ARGS__)
61#define LIGHTMODBUS_DEFINE_BUILD_TCP_BODY(f_suffix, ...) \
63 ModbusErrorInfo err; \
64 if (!modbusIsOk(err = modbusBeginRequestTCP(status))) return err; \
65 if (!modbusIsOk(err = modbusBuildRequest##f_suffix(status, __VA_ARGS__))) return err; \
66 return modbusEndRequestTCP(status, transactionID, unitID); \
73 const uint8_t *requestPDU,
74 uint8_t requestLength,
75 const uint8_t *responsePDU,
76 uint8_t responseLength);
82 const uint8_t *requestPDU,
83 uint8_t requestLength,
84 const uint8_t *responsePDU,
85 uint8_t responseLength);
91 const uint8_t *requestPDU,
92 uint8_t requestLength,
93 const uint8_t *responsePDU,
94 uint8_t responseLength);
100 const uint8_t *requestPDU,
101 uint8_t requestLength,
102 const uint8_t *responsePDU,
103 uint8_t responseLength);
121 const uint8_t *values);
127 const uint16_t *values);
Common types and functions (header)
#define LIGHTMODBUS_WARN_UNUSED
Definition base.h:19
#define LIGHTMODBUS_RET_ERROR
Return type for library functions returning ModbusErrorInfo that should be handled properly.
Definition base.h:49
Master's types and basic functions (header)
#define LIGHTMODBUS_DEFINE_BUILD_TCP_BODY(f_suffix,...)
Defines a body for a modbusBuildRequest*TCP() function.
Definition master_func.h:61
ModbusErrorInfo modbusParseResponse1516(ModbusMaster *status, uint8_t address, uint8_t function, const uint8_t *requestPDU, uint8_t requestLength, const uint8_t *responsePDU, uint8_t responseLength)
Parses response to requests 15 and 16 (write mutliple regsiters/coils)
Definition master_func.impl.h:172
#define LIGHTMODBUS_DEFINE_BUILD_RTU_BODY(f_suffix,...)
Defines a body for a modbusBuildRequest*RTU() function.
Definition master_func.h:42
ModbusErrorInfo modbusParseResponse0506(ModbusMaster *status, uint8_t address, uint8_t function, const uint8_t *requestPDU, uint8_t requestLength, const uint8_t *responsePDU, uint8_t responseLength)
Parses response to requests 05 and 06.
Definition master_func.impl.h:132
static ModbusErrorInfo modbusBuildRequest03(ModbusMaster *status, uint16_t index, uint16_t count)
Read multiple holding registers - a wrapper for modbusBuildRequest01020304()
Definition master_func.h:163
static ModbusErrorInfo modbusBuildRequest04(ModbusMaster *status, uint16_t index, uint16_t count)
Read multiple input registers - a wrapper for modbusBuildRequest01020304()
Definition master_func.h:175
static ModbusErrorInfo modbusBuildRequest02(ModbusMaster *status, uint16_t index, uint16_t count)
Read multiple discrete inputs - a wrapper for modbusBuildRequest01020304()
Definition master_func.h:151
#define LIGHTMODBUS_DEFINE_BUILD_TCP_HEADER(f_suffix,...)
Defines a header for a modbusBuildRequest*TCP() function.
Definition master_func.h:54
ModbusErrorInfo modbusBuildRequest0506(ModbusMaster *status, uint8_t function, uint16_t index, uint16_t value)
Write single coil/holding register.
Definition master_func.impl.h:311
static ModbusErrorInfo modbusBuildRequest06(ModbusMaster *status, uint16_t index, uint16_t count)
Write single holding register - a wrapper for modbusBuildRequest0506()
Definition master_func.h:199
ModbusErrorInfo modbusBuildRequest22(ModbusMaster *status, uint16_t index, uint16_t andmask, uint16_t ormask)
Mask write register request.
Definition master_func.impl.h:438
static ModbusErrorInfo modbusBuildRequest05(ModbusMaster *status, uint16_t index, uint16_t count)
Write single coil - a wrapper for modbusBuildRequest0506()
Definition master_func.h:187
#define LIGHTMODBUS_DEFINE_BUILD_RTU_HEADER(f_suffix,...)
Defines a header for a modbusBuildRequest*RTU() function.
Definition master_func.h:35
#define LIGHTMODBUS_DEFINE_BUILD_PDU_BODY(f_suffix,...)
Defines a body for a modbusBuildRequest*PDU() function.
Definition master_func.h:23
static ModbusErrorInfo modbusBuildRequest01(ModbusMaster *status, uint16_t index, uint16_t count)
Read multiple coils - a wrapper for modbusBuildRequest01020304()
Definition master_func.h:139
ModbusErrorInfo modbusParseResponse22(ModbusMaster *status, uint8_t address, uint8_t function, const uint8_t *requestPDU, uint8_t requestLength, const uint8_t *responsePDU, uint8_t responseLength)
Parses response to request 22.
Definition master_func.impl.h:226
ModbusErrorInfo modbusBuildRequest16(ModbusMaster *status, uint16_t index, uint16_t count, const uint16_t *values)
Write multiple holding registers.
Definition master_func.impl.h:400
ModbusErrorInfo modbusBuildRequest01020304(ModbusMaster *status, uint8_t function, uint16_t index, uint16_t count)
Read mutiple coils/discrete inputs/holding registers/input registers.
Definition master_func.impl.h:261
ModbusErrorInfo modbusParseResponse01020304(ModbusMaster *status, uint8_t address, uint8_t function, const uint8_t *requestPDU, uint8_t requestLength, const uint8_t *responsePDU, uint8_t responseLength)
Parses response to requests 01, 02, 03 and 04.
Definition master_func.impl.h:28
ModbusErrorInfo modbusBuildRequest15(ModbusMaster *status, uint16_t index, uint16_t count, const uint8_t *values)
Write multiple coils.
Definition master_func.impl.h:344
#define LIGHTMODBUS_DEFINE_BUILD_PDU_HEADER(f_suffix,...)
Defines a header for a modbusBuildRequest*PDU() function.
Definition master_func.h:16
Richer error represenation - source and type of error.
Definition base.h:126
Master device status.
Definition master.h:73