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

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

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

Go to the source code of this file.

Functions

 ModbusErrorInfomodbusParseResponse01020304 (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.
 
 ModbusErrorInfomodbusParseResponse0506 (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.
 
 ModbusErrorInfomodbusParseResponse1516 (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)
 
 ModbusErrorInfomodbusParseResponse22 (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.
 
 ModbusErrorInfomodbusBuildRequest01020304 (ModbusMaster *status, uint8_t function, uint16_t index, uint16_t count)
 Read mutiple coils/discrete inputs/holding registers/input registers.
 
 ModbusErrorInfomodbusBuildRequest0506 (ModbusMaster *status, uint8_t function, uint16_t index, uint16_t value)
 Write single coil/holding register.
 
 ModbusErrorInfomodbusBuildRequest15 (ModbusMaster *status, uint16_t index, uint16_t count, const uint8_t *values)
 Write multiple coils.
 
 ModbusErrorInfomodbusBuildRequest16 (ModbusMaster *status, uint16_t index, uint16_t count, const uint16_t *values)
 Write multiple holding registers.
 
 ModbusErrorInfomodbusBuildRequest22 (ModbusMaster *status, uint16_t index, uint16_t andmask, uint16_t ormask)
 Mask write register request.
 

Detailed Description

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

Function Documentation

◆ ModbusErrorInfomodbusBuildRequest01020304()

ModbusErrorInfomodbusBuildRequest01020304 ( 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:

◆ ModbusErrorInfomodbusBuildRequest0506()

ModbusErrorInfomodbusBuildRequest0506 ( 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:

◆ ModbusErrorInfomodbusBuildRequest15()

ModbusErrorInfomodbusBuildRequest15 ( 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:

◆ ModbusErrorInfomodbusBuildRequest16()

ModbusErrorInfomodbusBuildRequest16 ( 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:

◆ ModbusErrorInfomodbusBuildRequest22()

ModbusErrorInfomodbusBuildRequest22 ( 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:

◆ ModbusErrorInfomodbusParseResponse01020304()

ModbusErrorInfomodbusParseResponse01020304 ( 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:

◆ ModbusErrorInfomodbusParseResponse0506()

ModbusErrorInfomodbusParseResponse0506 ( 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:

◆ ModbusErrorInfomodbusParseResponse1516()

ModbusErrorInfomodbusParseResponse1516 ( 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:

◆ ModbusErrorInfomodbusParseResponse22()

ModbusErrorInfomodbusParseResponse22 ( 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