liblightmodbus 3.0
A lightweight, header-only, hardware-agnostic Modbus RTU/TCP library
Loading...
Searching...
No Matches
master_func.h File Reference

Master's functions for building requests and parsing responses (header) More...

#include "base.h"
#include "master.h"
+ Include dependency graph for master_func.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define LIGHTMODBUS_DEFINE_BUILD_PDU_HEADER(f_suffix, ...)    LIGHTMODBUS_WARN_UNUSED static inline ModbusErrorInfo modbusBuildRequest##f_suffix##PDU(ModbusMaster *status, __VA_ARGS__)
 Defines a header for a modbusBuildRequest*PDU() function.
 
#define LIGHTMODBUS_DEFINE_BUILD_PDU_BODY(f_suffix, ...)
 Defines a body for a modbusBuildRequest*PDU() function.
 
#define LIGHTMODBUS_DEFINE_BUILD_RTU_HEADER(f_suffix, ...)    LIGHTMODBUS_WARN_UNUSED static inline ModbusErrorInfo modbusBuildRequest##f_suffix##RTU(ModbusMaster *status, uint8_t address, __VA_ARGS__)
 Defines a header for a modbusBuildRequest*RTU() function.
 
#define LIGHTMODBUS_DEFINE_BUILD_RTU_BODY(f_suffix, ...)
 Defines a body for a modbusBuildRequest*RTU() function.
 
#define LIGHTMODBUS_DEFINE_BUILD_TCP_HEADER(f_suffix, ...)    LIGHTMODBUS_WARN_UNUSED static inline ModbusErrorInfo modbusBuildRequest##f_suffix##TCP(ModbusMaster *status, uint16_t transactionID, uint8_t unitID, __VA_ARGS__)
 Defines a header for a modbusBuildRequest*TCP() function.
 
#define LIGHTMODBUS_DEFINE_BUILD_TCP_BODY(f_suffix, ...)
 Defines a body for a modbusBuildRequest*TCP() function.
 

Functions

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.
 
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.
 
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)
 
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.
 
ModbusErrorInfo modbusBuildRequest01020304 (ModbusMaster *status, uint8_t function, uint16_t index, uint16_t count)
 Read mutiple coils/discrete inputs/holding registers/input registers.
 
ModbusErrorInfo modbusBuildRequest0506 (ModbusMaster *status, uint8_t function, uint16_t index, uint16_t value)
 Write single coil/holding register.
 
ModbusErrorInfo modbusBuildRequest15 (ModbusMaster *status, uint16_t index, uint16_t count, const uint8_t *values)
 Write multiple coils.
 
ModbusErrorInfo modbusBuildRequest16 (ModbusMaster *status, uint16_t index, uint16_t count, const uint16_t *values)
 Write multiple holding registers.
 
ModbusErrorInfo modbusBuildRequest22 (ModbusMaster *status, uint16_t index, uint16_t andmask, uint16_t ormask)
 Mask write register request.
 
static ModbusErrorInfo modbusBuildRequest01 (ModbusMaster *status, uint16_t index, uint16_t count)
 Read multiple coils - a wrapper for modbusBuildRequest01020304()
 
static ModbusErrorInfo modbusBuildRequest02 (ModbusMaster *status, uint16_t index, uint16_t count)
 Read multiple discrete inputs - a wrapper for modbusBuildRequest01020304()
 
static ModbusErrorInfo modbusBuildRequest03 (ModbusMaster *status, uint16_t index, uint16_t count)
 Read multiple holding registers - a wrapper for modbusBuildRequest01020304()
 
static ModbusErrorInfo modbusBuildRequest04 (ModbusMaster *status, uint16_t index, uint16_t count)
 Read multiple input registers - a wrapper for modbusBuildRequest01020304()
 
static ModbusErrorInfo modbusBuildRequest05 (ModbusMaster *status, uint16_t index, uint16_t count)
 Write single coil - a wrapper for modbusBuildRequest0506()
 
static ModbusErrorInfo modbusBuildRequest06 (ModbusMaster *status, uint16_t index, uint16_t count)
 Write single holding register - a wrapper for modbusBuildRequest0506()
 
static ModbusErrorInfo modbusBuildRequest01PDU (ModbusMaster *status, uint16_t index, uint16_t count)
 Read multiple coils - a wrapper for modbusBuildRequest01020304()
 
static ModbusErrorInfo modbusBuildRequest01RTU (ModbusMaster *status, uint8_t address, uint16_t index, uint16_t count)
 Read multiple coils - a wrapper for modbusBuildRequest01020304()
 
static ModbusErrorInfo modbusBuildRequest01TCP (ModbusMaster *status, uint16_t transactionID, uint8_t unitID, uint16_t index, uint16_t count)
 Read multiple coils - a wrapper for modbusBuildRequest01020304()
 
static ModbusErrorInfo modbusBuildRequest02PDU (ModbusMaster *status, uint16_t index, uint16_t count)
 Read multiple discrete inputs - a wrapper for modbusBuildRequest01020304()
 
static ModbusErrorInfo modbusBuildRequest02RTU (ModbusMaster *status, uint8_t address, uint16_t index, uint16_t count)
 Read multiple discrete inputs - a wrapper for modbusBuildRequest01020304()
 
static ModbusErrorInfo modbusBuildRequest02TCP (ModbusMaster *status, uint16_t transactionID, uint8_t unitID, uint16_t index, uint16_t count)
 Read multiple discrete inputs - a wrapper for modbusBuildRequest01020304()
 
static ModbusErrorInfo modbusBuildRequest03PDU (ModbusMaster *status, uint16_t index, uint16_t count)
 Read multiple holding registers - a wrapper for modbusBuildRequest01020304()
 
static ModbusErrorInfo modbusBuildRequest03RTU (ModbusMaster *status, uint8_t address, uint16_t index, uint16_t count)
 Read multiple holding registers - a wrapper for modbusBuildRequest01020304()
 
static ModbusErrorInfo modbusBuildRequest03TCP (ModbusMaster *status, uint16_t transactionID, uint8_t unitID, uint16_t index, uint16_t count)
 Read multiple holding registers - a wrapper for modbusBuildRequest01020304()
 
static ModbusErrorInfo modbusBuildRequest04PDU (ModbusMaster *status, uint16_t index, uint16_t count)
 Read multiple input registers - a wrapper for modbusBuildRequest01020304()
 
static ModbusErrorInfo modbusBuildRequest04RTU (ModbusMaster *status, uint8_t address, uint16_t index, uint16_t count)
 Read multiple input registers - a wrapper for modbusBuildRequest01020304()
 
static ModbusErrorInfo modbusBuildRequest04TCP (ModbusMaster *status, uint16_t transactionID, uint8_t unitID, uint16_t index, uint16_t count)
 Read multiple input registers - a wrapper for modbusBuildRequest01020304()
 
static ModbusErrorInfo modbusBuildRequest05PDU (ModbusMaster *status, uint16_t index, uint16_t count)
 Write single coil - a wrapper for modbusBuildRequest0506()
 
static ModbusErrorInfo modbusBuildRequest05RTU (ModbusMaster *status, uint8_t address, uint16_t index, uint16_t count)
 Write single coil - a wrapper for modbusBuildRequest0506()
 
static ModbusErrorInfo modbusBuildRequest05TCP (ModbusMaster *status, uint16_t transactionID, uint8_t unitID, uint16_t index, uint16_t count)
 Write single coil - a wrapper for modbusBuildRequest0506()
 
static ModbusErrorInfo modbusBuildRequest06PDU (ModbusMaster *status, uint16_t index, uint16_t count)
 Write single holding register - a wrapper for modbusBuildRequest0506()
 
static ModbusErrorInfo modbusBuildRequest06RTU (ModbusMaster *status, uint8_t address, uint16_t index, uint16_t count)
 Write single holding register - a wrapper for modbusBuildRequest0506()
 
static ModbusErrorInfo modbusBuildRequest06TCP (ModbusMaster *status, uint16_t transactionID, uint8_t unitID, uint16_t index, uint16_t count)
 Write single holding register - a wrapper for modbusBuildRequest0506()
 
static ModbusErrorInfo modbusBuildRequest15PDU (ModbusMaster *status, uint16_t index, uint16_t count, const uint8_t *values)
 Write multiple coils.
 
static ModbusErrorInfo modbusBuildRequest15RTU (ModbusMaster *status, uint8_t address, uint16_t index, uint16_t count, const uint8_t *values)
 Write multiple coils.
 
static ModbusErrorInfo modbusBuildRequest15TCP (ModbusMaster *status, uint16_t transactionID, uint8_t unitID, uint16_t index, uint16_t count, const uint8_t *values)
 Write multiple coils.
 
static ModbusErrorInfo modbusBuildRequest16PDU (ModbusMaster *status, uint16_t index, uint16_t count, const uint16_t *values)
 Write multiple holding registers.
 
static ModbusErrorInfo modbusBuildRequest16RTU (ModbusMaster *status, uint8_t address, uint16_t index, uint16_t count, const uint16_t *values)
 Write multiple holding registers.
 
static ModbusErrorInfo modbusBuildRequest16TCP (ModbusMaster *status, uint16_t transactionID, uint8_t unitID, uint16_t index, uint16_t count, const uint16_t *values)
 Write multiple holding registers.
 
static ModbusErrorInfo modbusBuildRequest22PDU (ModbusMaster *status, uint16_t index, uint16_t andmask, uint16_t ormask)
 Mask write register request.
 
static ModbusErrorInfo modbusBuildRequest22RTU (ModbusMaster *status, uint8_t address, uint16_t index, uint16_t andmask, uint16_t ormask)
 Mask write register request.
 
static ModbusErrorInfo modbusBuildRequest22TCP (ModbusMaster *status, uint16_t transactionID, uint8_t unitID, uint16_t index, uint16_t andmask, uint16_t ormask)
 Mask write register request.
 

Detailed Description

Master's functions for building requests and parsing responses (header)

Macro Definition Documentation

◆ LIGHTMODBUS_DEFINE_BUILD_PDU_BODY

#define LIGHTMODBUS_DEFINE_BUILD_PDU_BODY (   f_suffix,
  ... 
)
Value:
{ \
if (!modbusIsOk(err = modbusBeginRequestPDU(status))) return err; \
if (!modbusIsOk(err = modbusBuildRequest##f_suffix(status, __VA_ARGS__))) return err; \
return modbusEndRequestPDU(status); \
}
static uint8_t modbusIsOk(ModbusErrorInfo err)
Checks if ModbusErrorInfo contains an error.
Definition base.h:442
ModbusErrorInfo modbusEndRequestPDU(ModbusMaster *status)
Finalizes a PDU-only request.
Definition master.impl.h:121
ModbusErrorInfo modbusBeginRequestPDU(ModbusMaster *status)
Begins a PDU-only request.
Definition master.impl.h:111
Richer error represenation - source and type of error.
Definition base.h:126

Defines a body for a modbusBuildRequest*PDU() function.

◆ LIGHTMODBUS_DEFINE_BUILD_PDU_HEADER

#define LIGHTMODBUS_DEFINE_BUILD_PDU_HEADER (   f_suffix,
  ... 
)     LIGHTMODBUS_WARN_UNUSED static inline ModbusErrorInfo modbusBuildRequest##f_suffix##PDU(ModbusMaster *status, __VA_ARGS__)

Defines a header for a modbusBuildRequest*PDU() function.

◆ LIGHTMODBUS_DEFINE_BUILD_RTU_BODY

#define LIGHTMODBUS_DEFINE_BUILD_RTU_BODY (   f_suffix,
  ... 
)
Value:
{ \
if (!modbusIsOk(err = modbusBeginRequestRTU(status))) return err; \
if (!modbusIsOk(err = modbusBuildRequest##f_suffix(status, __VA_ARGS__))) return err; \
return modbusEndRequestRTU(status, address); \
}
ModbusErrorInfo modbusEndRequestRTU(ModbusMaster *status, uint8_t address)
Finalizes a Modbus RTU request.
Definition master.impl.h:141
ModbusErrorInfo modbusBeginRequestRTU(ModbusMaster *status)
Begins a RTU request.
Definition master.impl.h:130

Defines a body for a modbusBuildRequest*RTU() function.

◆ LIGHTMODBUS_DEFINE_BUILD_RTU_HEADER

#define LIGHTMODBUS_DEFINE_BUILD_RTU_HEADER (   f_suffix,
  ... 
)     LIGHTMODBUS_WARN_UNUSED static inline ModbusErrorInfo modbusBuildRequest##f_suffix##RTU(ModbusMaster *status, uint8_t address, __VA_ARGS__)

Defines a header for a modbusBuildRequest*RTU() function.

◆ LIGHTMODBUS_DEFINE_BUILD_TCP_BODY

#define LIGHTMODBUS_DEFINE_BUILD_TCP_BODY (   f_suffix,
  ... 
)
Value:
{ \
if (!modbusIsOk(err = modbusBeginRequestTCP(status))) return err; \
if (!modbusIsOk(err = modbusBuildRequest##f_suffix(status, __VA_ARGS__))) return err; \
return modbusEndRequestTCP(status, transactionID, unitID); \
}
ModbusErrorInfo modbusEndRequestTCP(ModbusMaster *status, uint16_t transaction, uint8_t unit)
Finalizes a Modbus TCP request.
Definition master.impl.h:171
ModbusErrorInfo modbusBeginRequestTCP(ModbusMaster *status)
Begins a TCP request.
Definition master.impl.h:158

Defines a body for a modbusBuildRequest*TCP() function.

◆ LIGHTMODBUS_DEFINE_BUILD_TCP_HEADER

#define LIGHTMODBUS_DEFINE_BUILD_TCP_HEADER (   f_suffix,
  ... 
)     LIGHTMODBUS_WARN_UNUSED static inline ModbusErrorInfo modbusBuildRequest##f_suffix##TCP(ModbusMaster *status, uint16_t transactionID, uint8_t unitID, __VA_ARGS__)

Defines a header for a modbusBuildRequest*TCP() function.

Function Documentation

◆ modbusBuildRequest01()

static ModbusErrorInfo modbusBuildRequest01 ( ModbusMaster status,
uint16_t  index,
uint16_t  count 
)
inlinestatic

Read multiple coils - a wrapper for modbusBuildRequest01020304()

Parameters
function1 to read coils, 2 to read discrete inputs, 3 to read holding registers, 4 to read input registers
indexIndex of the register to be read
countNumber of registers to be read
valueNew value for the register/coil
Returns
MODBUS_GENERAL_ERROR(FUNCTION) if function is not 1, 2, 3 or 4
MODBUS_GENERAL_ERROR(COUNT) if count is zero or too large
MODBUS_GENERAL_ERROR(RANGE) if the register range wraps aroudthe register space
MODBUS_GENERAL_ERROR(ALLOC) on memory allocation error
MODBUS_NO_ERROR() on success
+ Here is the call graph for this function:

◆ modbusBuildRequest01020304()

ModbusErrorInfo modbusBuildRequest01020304 ( ModbusMaster status,
uint8_t  function,
uint16_t  index,
uint16_t  count 
)

Read mutiple coils/discrete inputs/holding registers/input registers.

Parameters
function1 to read coils, 2 to read discrete inputs, 3 to read holding registers, 4 to read input registers
indexIndex of the register to be read
countNumber of registers to be read
valueNew value for the register/coil
Returns
MODBUS_GENERAL_ERROR(FUNCTION) if function is not 1, 2, 3 or 4
MODBUS_GENERAL_ERROR(COUNT) if count is zero or too large
MODBUS_GENERAL_ERROR(RANGE) if the register range wraps aroudthe register space
MODBUS_GENERAL_ERROR(ALLOC) on memory allocation error
MODBUS_NO_ERROR() on success
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ modbusBuildRequest01PDU()

static ModbusErrorInfo modbusBuildRequest01PDU ( ModbusMaster status,
uint16_t  index,
uint16_t  count 
)
inlinestatic

Read multiple coils - a wrapper for modbusBuildRequest01020304()

Parameters
function1 to read coils, 2 to read discrete inputs, 3 to read holding registers, 4 to read input registers
indexIndex of the register to be read
countNumber of registers to be read
valueNew value for the register/coil
Returns
MODBUS_GENERAL_ERROR(FUNCTION) if function is not 1, 2, 3 or 4
MODBUS_GENERAL_ERROR(COUNT) if count is zero or too large
MODBUS_GENERAL_ERROR(RANGE) if the register range wraps aroudthe register space
MODBUS_GENERAL_ERROR(ALLOC) on memory allocation error
MODBUS_NO_ERROR() on success
Any errors from modbusBeginRequestPDU() or modbusEndRequestPDU()

◆ modbusBuildRequest01RTU()

static ModbusErrorInfo modbusBuildRequest01RTU ( ModbusMaster status,
uint8_t  address,
uint16_t  index,
uint16_t  count 
)
inlinestatic

Read multiple coils - a wrapper for modbusBuildRequest01020304()

Parameters
function1 to read coils, 2 to read discrete inputs, 3 to read holding registers, 4 to read input registers
indexIndex of the register to be read
countNumber of registers to be read
valueNew value for the register/coil
Returns
MODBUS_GENERAL_ERROR(FUNCTION) if function is not 1, 2, 3 or 4
MODBUS_GENERAL_ERROR(COUNT) if count is zero or too large
MODBUS_GENERAL_ERROR(RANGE) if the register range wraps aroudthe register space
MODBUS_GENERAL_ERROR(ALLOC) on memory allocation error
MODBUS_NO_ERROR() on success
Any errors from modbusBeginRequestRTU() or modbusEndRequestRTU()

◆ modbusBuildRequest01TCP()

static ModbusErrorInfo modbusBuildRequest01TCP ( ModbusMaster status,
uint16_t  transactionID,
uint8_t  unitID,
uint16_t  index,
uint16_t  count 
)
inlinestatic

Read multiple coils - a wrapper for modbusBuildRequest01020304()

Parameters
function1 to read coils, 2 to read discrete inputs, 3 to read holding registers, 4 to read input registers
indexIndex of the register to be read
countNumber of registers to be read
valueNew value for the register/coil
Returns
MODBUS_GENERAL_ERROR(FUNCTION) if function is not 1, 2, 3 or 4
MODBUS_GENERAL_ERROR(COUNT) if count is zero or too large
MODBUS_GENERAL_ERROR(RANGE) if the register range wraps aroudthe register space
MODBUS_GENERAL_ERROR(ALLOC) on memory allocation error
MODBUS_NO_ERROR() on success
Any errors from modbusBeginRequestTCP() or modbusEndRequestTCP()

◆ modbusBuildRequest02()

static ModbusErrorInfo modbusBuildRequest02 ( ModbusMaster status,
uint16_t  index,
uint16_t  count 
)
inlinestatic

Read multiple discrete inputs - a wrapper for modbusBuildRequest01020304()

Parameters
function1 to read coils, 2 to read discrete inputs, 3 to read holding registers, 4 to read input registers
indexIndex of the register to be read
countNumber of registers to be read
valueNew value for the register/coil
Returns
MODBUS_GENERAL_ERROR(FUNCTION) if function is not 1, 2, 3 or 4
MODBUS_GENERAL_ERROR(COUNT) if count is zero or too large
MODBUS_GENERAL_ERROR(RANGE) if the register range wraps aroudthe register space
MODBUS_GENERAL_ERROR(ALLOC) on memory allocation error
MODBUS_NO_ERROR() on success
+ Here is the call graph for this function:

◆ modbusBuildRequest02PDU()

static ModbusErrorInfo modbusBuildRequest02PDU ( ModbusMaster status,
uint16_t  index,
uint16_t  count 
)
inlinestatic

Read multiple discrete inputs - a wrapper for modbusBuildRequest01020304()

Parameters
function1 to read coils, 2 to read discrete inputs, 3 to read holding registers, 4 to read input registers
indexIndex of the register to be read
countNumber of registers to be read
valueNew value for the register/coil
Returns
MODBUS_GENERAL_ERROR(FUNCTION) if function is not 1, 2, 3 or 4
MODBUS_GENERAL_ERROR(COUNT) if count is zero or too large
MODBUS_GENERAL_ERROR(RANGE) if the register range wraps aroudthe register space
MODBUS_GENERAL_ERROR(ALLOC) on memory allocation error
MODBUS_NO_ERROR() on success
Any errors from modbusBeginRequestPDU() or modbusEndRequestPDU()

◆ modbusBuildRequest02RTU()

static ModbusErrorInfo modbusBuildRequest02RTU ( ModbusMaster status,
uint8_t  address,
uint16_t  index,
uint16_t  count 
)
inlinestatic

Read multiple discrete inputs - a wrapper for modbusBuildRequest01020304()

Parameters
function1 to read coils, 2 to read discrete inputs, 3 to read holding registers, 4 to read input registers
indexIndex of the register to be read
countNumber of registers to be read
valueNew value for the register/coil
Returns
MODBUS_GENERAL_ERROR(FUNCTION) if function is not 1, 2, 3 or 4
MODBUS_GENERAL_ERROR(COUNT) if count is zero or too large
MODBUS_GENERAL_ERROR(RANGE) if the register range wraps aroudthe register space
MODBUS_GENERAL_ERROR(ALLOC) on memory allocation error
MODBUS_NO_ERROR() on success
Any errors from modbusBeginRequestRTU() or modbusEndRequestRTU()

◆ modbusBuildRequest02TCP()

static ModbusErrorInfo modbusBuildRequest02TCP ( ModbusMaster status,
uint16_t  transactionID,
uint8_t  unitID,
uint16_t  index,
uint16_t  count 
)
inlinestatic

Read multiple discrete inputs - a wrapper for modbusBuildRequest01020304()

Parameters
function1 to read coils, 2 to read discrete inputs, 3 to read holding registers, 4 to read input registers
indexIndex of the register to be read
countNumber of registers to be read
valueNew value for the register/coil
Returns
MODBUS_GENERAL_ERROR(FUNCTION) if function is not 1, 2, 3 or 4
MODBUS_GENERAL_ERROR(COUNT) if count is zero or too large
MODBUS_GENERAL_ERROR(RANGE) if the register range wraps aroudthe register space
MODBUS_GENERAL_ERROR(ALLOC) on memory allocation error
MODBUS_NO_ERROR() on success
Any errors from modbusBeginRequestTCP() or modbusEndRequestTCP()

◆ modbusBuildRequest03()

static ModbusErrorInfo modbusBuildRequest03 ( ModbusMaster status,
uint16_t  index,
uint16_t  count 
)
inlinestatic

Read multiple holding registers - a wrapper for modbusBuildRequest01020304()

Parameters
function1 to read coils, 2 to read discrete inputs, 3 to read holding registers, 4 to read input registers
indexIndex of the register to be read
countNumber of registers to be read
valueNew value for the register/coil
Returns
MODBUS_GENERAL_ERROR(FUNCTION) if function is not 1, 2, 3 or 4
MODBUS_GENERAL_ERROR(COUNT) if count is zero or too large
MODBUS_GENERAL_ERROR(RANGE) if the register range wraps aroudthe register space
MODBUS_GENERAL_ERROR(ALLOC) on memory allocation error
MODBUS_NO_ERROR() on success
+ Here is the call graph for this function:

◆ modbusBuildRequest03PDU()

static ModbusErrorInfo modbusBuildRequest03PDU ( ModbusMaster status,
uint16_t  index,
uint16_t  count 
)
inlinestatic

Read multiple holding registers - a wrapper for modbusBuildRequest01020304()

Parameters
function1 to read coils, 2 to read discrete inputs, 3 to read holding registers, 4 to read input registers
indexIndex of the register to be read
countNumber of registers to be read
valueNew value for the register/coil
Returns
MODBUS_GENERAL_ERROR(FUNCTION) if function is not 1, 2, 3 or 4
MODBUS_GENERAL_ERROR(COUNT) if count is zero or too large
MODBUS_GENERAL_ERROR(RANGE) if the register range wraps aroudthe register space
MODBUS_GENERAL_ERROR(ALLOC) on memory allocation error
MODBUS_NO_ERROR() on success
Any errors from modbusBeginRequestPDU() or modbusEndRequestPDU()

◆ modbusBuildRequest03RTU()

static ModbusErrorInfo modbusBuildRequest03RTU ( ModbusMaster status,
uint8_t  address,
uint16_t  index,
uint16_t  count 
)
inlinestatic

Read multiple holding registers - a wrapper for modbusBuildRequest01020304()

Parameters
function1 to read coils, 2 to read discrete inputs, 3 to read holding registers, 4 to read input registers
indexIndex of the register to be read
countNumber of registers to be read
valueNew value for the register/coil
Returns
MODBUS_GENERAL_ERROR(FUNCTION) if function is not 1, 2, 3 or 4
MODBUS_GENERAL_ERROR(COUNT) if count is zero or too large
MODBUS_GENERAL_ERROR(RANGE) if the register range wraps aroudthe register space
MODBUS_GENERAL_ERROR(ALLOC) on memory allocation error
MODBUS_NO_ERROR() on success
Any errors from modbusBeginRequestRTU() or modbusEndRequestRTU()

◆ modbusBuildRequest03TCP()

static ModbusErrorInfo modbusBuildRequest03TCP ( ModbusMaster status,
uint16_t  transactionID,
uint8_t  unitID,
uint16_t  index,
uint16_t  count 
)
inlinestatic

Read multiple holding registers - a wrapper for modbusBuildRequest01020304()

Parameters
function1 to read coils, 2 to read discrete inputs, 3 to read holding registers, 4 to read input registers
indexIndex of the register to be read
countNumber of registers to be read
valueNew value for the register/coil
Returns
MODBUS_GENERAL_ERROR(FUNCTION) if function is not 1, 2, 3 or 4
MODBUS_GENERAL_ERROR(COUNT) if count is zero or too large
MODBUS_GENERAL_ERROR(RANGE) if the register range wraps aroudthe register space
MODBUS_GENERAL_ERROR(ALLOC) on memory allocation error
MODBUS_NO_ERROR() on success
Any errors from modbusBeginRequestTCP() or modbusEndRequestTCP()

◆ modbusBuildRequest04()

static ModbusErrorInfo modbusBuildRequest04 ( ModbusMaster status,
uint16_t  index,
uint16_t  count 
)
inlinestatic

Read multiple input registers - a wrapper for modbusBuildRequest01020304()

Parameters
function1 to read coils, 2 to read discrete inputs, 3 to read holding registers, 4 to read input registers
indexIndex of the register to be read
countNumber of registers to be read
valueNew value for the register/coil
Returns
MODBUS_GENERAL_ERROR(FUNCTION) if function is not 1, 2, 3 or 4
MODBUS_GENERAL_ERROR(COUNT) if count is zero or too large
MODBUS_GENERAL_ERROR(RANGE) if the register range wraps aroudthe register space
MODBUS_GENERAL_ERROR(ALLOC) on memory allocation error
MODBUS_NO_ERROR() on success
+ Here is the call graph for this function:

◆ modbusBuildRequest04PDU()

static ModbusErrorInfo modbusBuildRequest04PDU ( ModbusMaster status,
uint16_t  index,
uint16_t  count 
)
inlinestatic

Read multiple input registers - a wrapper for modbusBuildRequest01020304()

Parameters
function1 to read coils, 2 to read discrete inputs, 3 to read holding registers, 4 to read input registers
indexIndex of the register to be read
countNumber of registers to be read
valueNew value for the register/coil
Returns
MODBUS_GENERAL_ERROR(FUNCTION) if function is not 1, 2, 3 or 4
MODBUS_GENERAL_ERROR(COUNT) if count is zero or too large
MODBUS_GENERAL_ERROR(RANGE) if the register range wraps aroudthe register space
MODBUS_GENERAL_ERROR(ALLOC) on memory allocation error
MODBUS_NO_ERROR() on success
Any errors from modbusBeginRequestPDU() or modbusEndRequestPDU()

◆ modbusBuildRequest04RTU()

static ModbusErrorInfo modbusBuildRequest04RTU ( ModbusMaster status,
uint8_t  address,
uint16_t  index,
uint16_t  count 
)
inlinestatic

Read multiple input registers - a wrapper for modbusBuildRequest01020304()

Parameters
function1 to read coils, 2 to read discrete inputs, 3 to read holding registers, 4 to read input registers
indexIndex of the register to be read
countNumber of registers to be read
valueNew value for the register/coil
Returns
MODBUS_GENERAL_ERROR(FUNCTION) if function is not 1, 2, 3 or 4
MODBUS_GENERAL_ERROR(COUNT) if count is zero or too large
MODBUS_GENERAL_ERROR(RANGE) if the register range wraps aroudthe register space
MODBUS_GENERAL_ERROR(ALLOC) on memory allocation error
MODBUS_NO_ERROR() on success
Any errors from modbusBeginRequestRTU() or modbusEndRequestRTU()

◆ modbusBuildRequest04TCP()

static ModbusErrorInfo modbusBuildRequest04TCP ( ModbusMaster status,
uint16_t  transactionID,
uint8_t  unitID,
uint16_t  index,
uint16_t  count 
)
inlinestatic

Read multiple input registers - a wrapper for modbusBuildRequest01020304()

Parameters
function1 to read coils, 2 to read discrete inputs, 3 to read holding registers, 4 to read input registers
indexIndex of the register to be read
countNumber of registers to be read
valueNew value for the register/coil
Returns
MODBUS_GENERAL_ERROR(FUNCTION) if function is not 1, 2, 3 or 4
MODBUS_GENERAL_ERROR(COUNT) if count is zero or too large
MODBUS_GENERAL_ERROR(RANGE) if the register range wraps aroudthe register space
MODBUS_GENERAL_ERROR(ALLOC) on memory allocation error
MODBUS_NO_ERROR() on success
Any errors from modbusBeginRequestTCP() or modbusEndRequestTCP()

◆ modbusBuildRequest05()

static ModbusErrorInfo modbusBuildRequest05 ( ModbusMaster status,
uint16_t  index,
uint16_t  count 
)
inlinestatic

Write single coil - a wrapper for modbusBuildRequest0506()

Parameters
function5 to write a coil, 6 to write a holding register
indexIndex of the register/coil to be written
valueNew value for the register/coil
Returns
MODBUS_GENERAL_ERROR(FUNCTION) if function is not 5 or 6
MODBUS_GENERAL_ERROR(ALLOC) on memory allocation error
MODBUS_NO_ERROR() on success
+ Here is the call graph for this function:

◆ modbusBuildRequest0506()

ModbusErrorInfo modbusBuildRequest0506 ( ModbusMaster status,
uint8_t  function,
uint16_t  index,
uint16_t  value 
)

Write single coil/holding register.

Parameters
function5 to write a coil, 6 to write a holding register
indexIndex of the register/coil to be written
valueNew value for the register/coil
Returns
MODBUS_GENERAL_ERROR(FUNCTION) if function is not 5 or 6
MODBUS_GENERAL_ERROR(ALLOC) on memory allocation error
MODBUS_NO_ERROR() on success
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ modbusBuildRequest05PDU()

static ModbusErrorInfo modbusBuildRequest05PDU ( ModbusMaster status,
uint16_t  index,
uint16_t  count 
)
inlinestatic

Write single coil - a wrapper for modbusBuildRequest0506()

Parameters
function5 to write a coil, 6 to write a holding register
indexIndex of the register/coil to be written
valueNew value for the register/coil
Returns
MODBUS_GENERAL_ERROR(FUNCTION) if function is not 5 or 6
MODBUS_GENERAL_ERROR(ALLOC) on memory allocation error
MODBUS_NO_ERROR() on success
Any errors from modbusBeginRequestPDU() or modbusEndRequestPDU()

◆ modbusBuildRequest05RTU()

static ModbusErrorInfo modbusBuildRequest05RTU ( ModbusMaster status,
uint8_t  address,
uint16_t  index,
uint16_t  count 
)
inlinestatic

Write single coil - a wrapper for modbusBuildRequest0506()

Parameters
function5 to write a coil, 6 to write a holding register
indexIndex of the register/coil to be written
valueNew value for the register/coil
Returns
MODBUS_GENERAL_ERROR(FUNCTION) if function is not 5 or 6
MODBUS_GENERAL_ERROR(ALLOC) on memory allocation error
MODBUS_NO_ERROR() on success
Any errors from modbusBeginRequestRTU() or modbusEndRequestRTU()

◆ modbusBuildRequest05TCP()

static ModbusErrorInfo modbusBuildRequest05TCP ( ModbusMaster status,
uint16_t  transactionID,
uint8_t  unitID,
uint16_t  index,
uint16_t  count 
)
inlinestatic

Write single coil - a wrapper for modbusBuildRequest0506()

Parameters
function5 to write a coil, 6 to write a holding register
indexIndex of the register/coil to be written
valueNew value for the register/coil
Returns
MODBUS_GENERAL_ERROR(FUNCTION) if function is not 5 or 6
MODBUS_GENERAL_ERROR(ALLOC) on memory allocation error
MODBUS_NO_ERROR() on success
Any errors from modbusBeginRequestTCP() or modbusEndRequestTCP()

◆ modbusBuildRequest06()

static ModbusErrorInfo modbusBuildRequest06 ( ModbusMaster status,
uint16_t  index,
uint16_t  count 
)
inlinestatic

Write single holding register - a wrapper for modbusBuildRequest0506()

Parameters
function5 to write a coil, 6 to write a holding register
indexIndex of the register/coil to be written
valueNew value for the register/coil
Returns
MODBUS_GENERAL_ERROR(FUNCTION) if function is not 5 or 6
MODBUS_GENERAL_ERROR(ALLOC) on memory allocation error
MODBUS_NO_ERROR() on success
+ Here is the call graph for this function:

◆ modbusBuildRequest06PDU()

static ModbusErrorInfo modbusBuildRequest06PDU ( ModbusMaster status,
uint16_t  index,
uint16_t  count 
)
inlinestatic

Write single holding register - a wrapper for modbusBuildRequest0506()

Parameters
function5 to write a coil, 6 to write a holding register
indexIndex of the register/coil to be written
valueNew value for the register/coil
Returns
MODBUS_GENERAL_ERROR(FUNCTION) if function is not 5 or 6
MODBUS_GENERAL_ERROR(ALLOC) on memory allocation error
MODBUS_NO_ERROR() on success
Any errors from modbusBeginRequestPDU() or modbusEndRequestPDU()

◆ modbusBuildRequest06RTU()

static ModbusErrorInfo modbusBuildRequest06RTU ( ModbusMaster status,
uint8_t  address,
uint16_t  index,
uint16_t  count 
)
inlinestatic

Write single holding register - a wrapper for modbusBuildRequest0506()

Parameters
function5 to write a coil, 6 to write a holding register
indexIndex of the register/coil to be written
valueNew value for the register/coil
Returns
MODBUS_GENERAL_ERROR(FUNCTION) if function is not 5 or 6
MODBUS_GENERAL_ERROR(ALLOC) on memory allocation error
MODBUS_NO_ERROR() on success
Any errors from modbusBeginRequestRTU() or modbusEndRequestRTU()

◆ modbusBuildRequest06TCP()

static ModbusErrorInfo modbusBuildRequest06TCP ( ModbusMaster status,
uint16_t  transactionID,
uint8_t  unitID,
uint16_t  index,
uint16_t  count 
)
inlinestatic

Write single holding register - a wrapper for modbusBuildRequest0506()

Parameters
function5 to write a coil, 6 to write a holding register
indexIndex of the register/coil to be written
valueNew value for the register/coil
Returns
MODBUS_GENERAL_ERROR(FUNCTION) if function is not 5 or 6
MODBUS_GENERAL_ERROR(ALLOC) on memory allocation error
MODBUS_NO_ERROR() on success
Any errors from modbusBeginRequestTCP() or modbusEndRequestTCP()

◆ modbusBuildRequest15()

ModbusErrorInfo modbusBuildRequest15 ( ModbusMaster status,
uint16_t  index,
uint16_t  count,
const uint8_t *  values 
)

Write multiple coils.

Parameters
indexIndex of the first coil to be written
countNumber of coils to be written
valuesPointer to array containing count coil values (each bit corresponds to one coil value)
Returns
MODBUS_GENERAL_ERROR(COUNT) if count is zero or too large
MODBUS_GENERAL_ERROR(RANGE) if the register range wraps around the register space
MODBUS_GENERAL_ERROR(ALLOC) on memory allocation error
MODBUS_NO_ERROR() on success
+ Here is the call graph for this function:

◆ modbusBuildRequest15PDU()

static ModbusErrorInfo modbusBuildRequest15PDU ( ModbusMaster status,
uint16_t  index,
uint16_t  count,
const uint8_t *  values 
)
inlinestatic

Write multiple coils.

Parameters
indexIndex of the first coil to be written
countNumber of coils to be written
valuesPointer to array containing count coil values (each bit corresponds to one coil value)
Returns
MODBUS_GENERAL_ERROR(COUNT) if count is zero or too large
MODBUS_GENERAL_ERROR(RANGE) if the register range wraps around the register space
MODBUS_GENERAL_ERROR(ALLOC) on memory allocation error
MODBUS_NO_ERROR() on success
Any errors from modbusBeginRequestPDU() or modbusEndRequestPDU()

◆ modbusBuildRequest15RTU()

static ModbusErrorInfo modbusBuildRequest15RTU ( ModbusMaster status,
uint8_t  address,
uint16_t  index,
uint16_t  count,
const uint8_t *  values 
)
inlinestatic

Write multiple coils.

Parameters
indexIndex of the first coil to be written
countNumber of coils to be written
valuesPointer to array containing count coil values (each bit corresponds to one coil value)
Returns
MODBUS_GENERAL_ERROR(COUNT) if count is zero or too large
MODBUS_GENERAL_ERROR(RANGE) if the register range wraps around the register space
MODBUS_GENERAL_ERROR(ALLOC) on memory allocation error
MODBUS_NO_ERROR() on success
Any errors from modbusBeginRequestRTU() or modbusEndRequestRTU()

◆ modbusBuildRequest15TCP()

static ModbusErrorInfo modbusBuildRequest15TCP ( ModbusMaster status,
uint16_t  transactionID,
uint8_t  unitID,
uint16_t  index,
uint16_t  count,
const uint8_t *  values 
)
inlinestatic

Write multiple coils.

Parameters
indexIndex of the first coil to be written
countNumber of coils to be written
valuesPointer to array containing count coil values (each bit corresponds to one coil value)
Returns
MODBUS_GENERAL_ERROR(COUNT) if count is zero or too large
MODBUS_GENERAL_ERROR(RANGE) if the register range wraps around the register space
MODBUS_GENERAL_ERROR(ALLOC) on memory allocation error
MODBUS_NO_ERROR() on success
Any errors from modbusBeginRequestTCP() or modbusEndRequestTCP()

◆ modbusBuildRequest16()

ModbusErrorInfo modbusBuildRequest16 ( ModbusMaster status,
uint16_t  index,
uint16_t  count,
const uint16_t *  values 
)

Write multiple holding registers.

Parameters
indexIndex of the first register to be written
countNumber of registers to be written
valuesPointer to array containing count register values. Each 16-bit word corresponds to one register value
Returns
MODBUS_GENERAL_ERROR(COUNT) if count is zero or too large
MODBUS_GENERAL_ERROR(RANGE) if the register range wraps around the register space
MODBUS_GENERAL_ERROR(ALLOC) on memory allocation error
MODBUS_NO_ERROR() on success
+ Here is the call graph for this function:

◆ modbusBuildRequest16PDU()

static ModbusErrorInfo modbusBuildRequest16PDU ( ModbusMaster status,
uint16_t  index,
uint16_t  count,
const uint16_t *  values 
)
inlinestatic

Write multiple holding registers.

Parameters
indexIndex of the first register to be written
countNumber of registers to be written
valuesPointer to array containing count register values. Each 16-bit word corresponds to one register value
Returns
MODBUS_GENERAL_ERROR(COUNT) if count is zero or too large
MODBUS_GENERAL_ERROR(RANGE) if the register range wraps around the register space
MODBUS_GENERAL_ERROR(ALLOC) on memory allocation error
MODBUS_NO_ERROR() on success
Any errors from modbusBeginRequestPDU() or modbusEndRequestPDU()

◆ modbusBuildRequest16RTU()

static ModbusErrorInfo modbusBuildRequest16RTU ( ModbusMaster status,
uint8_t  address,
uint16_t  index,
uint16_t  count,
const uint16_t *  values 
)
inlinestatic

Write multiple holding registers.

Parameters
indexIndex of the first register to be written
countNumber of registers to be written
valuesPointer to array containing count register values. Each 16-bit word corresponds to one register value
Returns
MODBUS_GENERAL_ERROR(COUNT) if count is zero or too large
MODBUS_GENERAL_ERROR(RANGE) if the register range wraps around the register space
MODBUS_GENERAL_ERROR(ALLOC) on memory allocation error
MODBUS_NO_ERROR() on success
Any errors from modbusBeginRequestRTU() or modbusEndRequestRTU()

◆ modbusBuildRequest16TCP()

static ModbusErrorInfo modbusBuildRequest16TCP ( ModbusMaster status,
uint16_t  transactionID,
uint8_t  unitID,
uint16_t  index,
uint16_t  count,
const uint16_t *  values 
)
inlinestatic

Write multiple holding registers.

Parameters
indexIndex of the first register to be written
countNumber of registers to be written
valuesPointer to array containing count register values. Each 16-bit word corresponds to one register value
Returns
MODBUS_GENERAL_ERROR(COUNT) if count is zero or too large
MODBUS_GENERAL_ERROR(RANGE) if the register range wraps around the register space
MODBUS_GENERAL_ERROR(ALLOC) on memory allocation error
MODBUS_NO_ERROR() on success
Any errors from modbusBeginRequestTCP() or modbusEndRequestTCP()

◆ modbusBuildRequest22()

ModbusErrorInfo modbusBuildRequest22 ( ModbusMaster status,
uint16_t  index,
uint16_t  andmask,
uint16_t  ormask 
)

Mask write register request.

Parameters
indexRegister ID
andmaxAND mask
ormaskOR mask
Returns
MODBUS_GENERAL_ERROR(ALLOC) on memory allocation error
MODBUS_NO_ERROR() on success
+ Here is the call graph for this function:

◆ modbusBuildRequest22PDU()

static ModbusErrorInfo modbusBuildRequest22PDU ( ModbusMaster status,
uint16_t  index,
uint16_t  andmask,
uint16_t  ormask 
)
inlinestatic

Mask write register request.

Parameters
indexRegister ID
andmaxAND mask
ormaskOR mask
Returns
MODBUS_GENERAL_ERROR(ALLOC) on memory allocation error
MODBUS_NO_ERROR() on success
Any errors from modbusBeginRequestPDU() or modbusEndRequestPDU()

◆ modbusBuildRequest22RTU()

static ModbusErrorInfo modbusBuildRequest22RTU ( ModbusMaster status,
uint8_t  address,
uint16_t  index,
uint16_t  andmask,
uint16_t  ormask 
)
inlinestatic

Mask write register request.

Parameters
indexRegister ID
andmaxAND mask
ormaskOR mask
Returns
MODBUS_GENERAL_ERROR(ALLOC) on memory allocation error
MODBUS_NO_ERROR() on success
Any errors from modbusBeginRequestRTU() or modbusEndRequestRTU()

◆ modbusBuildRequest22TCP()

static ModbusErrorInfo modbusBuildRequest22TCP ( ModbusMaster status,
uint16_t  transactionID,
uint8_t  unitID,
uint16_t  index,
uint16_t  andmask,
uint16_t  ormask 
)
inlinestatic

Mask write register request.

Parameters
indexRegister ID
andmaxAND mask
ormaskOR mask
Returns
MODBUS_GENERAL_ERROR(ALLOC) on memory allocation error
MODBUS_NO_ERROR() on success
Any errors from modbusBeginRequestTCP() or modbusEndRequestTCP()

◆ modbusParseResponse01020304()

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.

Parameters
addressAddress of the slave
functionResponse function code
requestPDUpointer to the PDU section of the request frame
requestLengthrequest PDU section length
responsePDUpointer to the PDU section of the response frame
responseLengthresponse PDU section length
Returns
MODBUS_REQUEST_ERROR(LENGTH) if request frame has invalid length
MODBUS_RESPONSE_ERROR(LENGTH) if response frame has invalid length
MODBUS_GENERAL_ERROR(FUNCTION) if function is not one of: 01, 02, 03, 04
MODBUS_REQUEST_ERROR(COUNT) if the declared register count is invalid
MODBUS_REQUEST_ERROR(RANGE) if the declared register range wraps around address space
MODBUS_RESPONSE_ERROR(LENGTH) if the response length is not as expected
MODBUS_NO_ERROR() on success
+ Here is the call graph for this function:

◆ modbusParseResponse0506()

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.

Parameters
addressAddress of the slave
functionResponse function code
requestPDUpointer to the PDU section of the request frame
requestLengthrequest PDU section length
responsePDUpointer to the PDU section of the response frame
responseLengthresponse PDU section length
Returns
MODBUS_REQUEST_ERROR(LENGTH) if request frame has invalid length
MODBUS_RESPONSE_ERROR(LENGTH) if response frame has invalid length
MODBUS_RESPONSE_ERROR(INDEX) if the register index is different in request and response
MODBUS_RESPONSE_ERROR(VALUE) if the register value is different in request and response
MODBUS_NO_ERROR() on success
+ Here is the call graph for this function:

◆ modbusParseResponse1516()

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)

Parameters
addressAddress of the slave
functionResponse function code
requestPDUpointer to the PDU section of the request frame
requestLengthrequest PDU section length
responsePDUpointer to the PDU section of the response frame
responseLengthresponse PDU section length
Returns
MODBUS_REQUEST_ERROR(LENGTH) if request frame has invalid length
MODBUS_RESPONSE_ERROR(LENGTH) if response frame has invalid length
MODBUS_REQUEST_ERROR(COUNT) if the declared register count is invalid
MODBUS_REQUEST_ERROR(RANGE) if the declared register range wraps around address space
MODBUS_RESPONSE_ERROR(INDEX) if the index differs between the request and response
MODBUS_RESPONSE_ERROR(COUNT) if the count differs between the request and response
MODBUS_NO_ERROR() on success
+ Here is the call graph for this function:

◆ modbusParseResponse22()

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.

Parameters
addressAddress of the slave
functionResponse function code
requestPDUpointer to the PDU section of the request frame
requestLengthrequest PDU section length
responsePDUpointer to the PDU section of the response frame
responseLengthresponse PDU section length
Returns
MODBUS_REQUEST_ERROR(LENGTH) if request frame has invalid length
MODBUS_RESPONSE_ERROR(LENGTH) if response frame has invalid length
MODBUS_RESPONSE_ERROR(OTHER) if the response is different from the request
MODBUS_NO_ERROR() on success