![]() |
modbuspp
1.1.40
C++ wrapper for the libmodbus library
|
Modbus Response Message. More...
#include <response.h>
Public Types | |
typedef int(* | Callback) (Message *msg, Device *sender) |
Message callback function. More... | |
Public Member Functions | |
uint8_t * | adu () |
Returns the underlying ADU bytes pointer. | |
const uint8_t * | adu () const |
uint8_t | adu (uint16_t i) |
Returns the ADU byte corresponding to the index provided. More... | |
uint16_t | aduHeaderLength () const |
Return the ADU header length. | |
size_t | aduSize () const |
returns the number of bytes of the ADU | |
bool | bitValue (uint16_t index) const |
Returns a bit value of the response. More... | |
void | bitValues (uint16_t index, uint16_t quantity, bool *values) const |
Returns bit values of the response. More... | |
uint8_t | byte (int pduOffset) const |
Returns the PDU byte corresponding to the offset provided. More... | |
void | clear () |
Empties the message and returns it to the initial state. | |
uint16_t | crc () const |
Return the CRC read in the message. More... | |
ExceptionCode | exceptionCode () const |
Returns the exception code of the response. More... | |
Function | function () const |
Returns the function of the request. More... | |
bool | isResponse () const |
Returns true if the message is a response. | |
uint16_t | maxAduLength () const |
Return the maximum ADU length. | |
Net | net () const |
Underlying layer used (backend) More... | |
bool | operator!= (const Message &other) |
Difference operator. | |
bool | operator== (const Message &other) |
Equality operator. | |
uint8_t * | pdu () |
Returns the underlying ADU bytes pointer. | |
const uint8_t * | pdu () const |
uint8_t | pdu (uint16_t i) const |
Returns the ADU byte corresponding to the index provided. More... | |
bool | prepareToSend () |
Prepare the message before sending. More... | |
void | print (std::ostream &os=std::cout) const |
Prints all bytes of the message on the output stream provided. More... | |
void | print (std::ostream &os, char prefix, char suffix) const |
Prints all bytes of the message on the output stream provided. More... | |
uint16_t | quantity () const |
Returns the number of elements of the request. More... | |
uint16_t | registerValue (uint16_t index) const |
Returns a register value of the response. More... | |
void | registerValues (uint16_t index, uint16_t quantity, uint16_t *values) const |
Returns register values of the response. More... | |
Response (NetLayer &backend) | |
Constructors. | |
Response (const Request &req) | |
Copy Constructors. | |
Response (Request &&req) | |
Move Constructors. | |
void | setAduSize (size_t size) |
Change the size of the ADU. More... | |
void | setBitValue (uint16_t index, bool value) |
Sets a bit value for the response. More... | |
void | setBitValues (uint16_t index, uint16_t quantity, const bool *values) |
Sets bit values for the response. More... | |
void | setByte (int pduOffset, uint8_t value) |
Write a byte in the PDU to the supplied offset. More... | |
void | setByteCount (uint8_t n) |
Sets the byte count for the response. More... | |
void | setExceptionCode (ExceptionCode code) |
Sets the exception code for the response. More... | |
void | setFunction (Function func) |
Sets the function of the request. More... | |
void | setPdu (const uint8_t *data, size_t len) |
Set the PDU data. More... | |
void | setPdu (const Message &src) |
void | setQuantity (uint16_t n) |
Sets the number of elements of the request. More... | |
void | setRegisterValue (uint16_t index, uint16_t value) |
Sets a register value for the response. More... | |
void | setRegisterValues (uint16_t index, uint16_t quantity, const uint16_t *values) |
Sets register values for the response. More... | |
void | setResponseFlag (bool flag=true) |
Sets the response flag. More... | |
void | setSize (size_t size) |
Change the size of the PDU. More... | |
void | setSlaveId (int id) |
Sets the number of the slave concerned by the request. More... | |
void | setStartingAdress (uint16_t addr) |
Sets the starting address of the request. More... | |
void | setTransactionIdentifier (uint16_t tid) |
Sets TCP/IP transaction identifier. More... | |
void | setWord (int pduOffset, uint16_t value) |
Write a word in the PDU to the supplied offset. More... | |
size_t | size () const |
returns the number of bytes of the PDU More... | |
int | slave () const |
Returns the number of the slave concerned by the request. More... | |
uint16_t | startingAddress () const |
Returns the starting address of the request. More... | |
void | swap (Message &other) |
Swaps Message other with this Message. This operation is very fast and never fails. | |
uint16_t | transactionIdentifier () const |
Returns TCP/IP transaction identifier. More... | |
uint16_t | word (int pduOffset) const |
Returns the PDU word corresponding to the offset provided. More... | |
Message callback function.
msg |
|
inherited |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
|
inherited |
Returns the ADU byte corresponding to the index provided.
i must be between 0 and maxAduLength()-1
bool Modbus::Response::bitValue | ( | uint16_t | index | ) | const |
Returns a bit value of the response.
Can be used for the functions Read Coils(01), Read Discrete Inputs(02). This value is at the pdu[2 + index*2].
void Modbus::Response::bitValues | ( | uint16_t | index, |
uint16_t | quantity, | ||
bool * | values | ||
) | const |
Returns bit values of the response.
Can be used for the functions Read Coils(01), Read Discrete Inputs(02). This value is at the pdu[2 + index*2].
|
inherited |
Returns the PDU byte corresponding to the offset provided.
pduOffset has a maximum value of MaxPduLength-1, it can have a negative value in order to access the bytes of the ADU that precedes the PDU.
|
inherited |
ExceptionCode Modbus::Response::exceptionCode | ( | ) | const |
Returns the exception code of the response.
Can be used for all functions. This value is at the pdu[1].
|
inherited |
Returns the function of the request.
Can be used for all functions. This value is at the offset[0] of the PDU
|
inherited |
Underlying layer used (backend)
This function allows to know the underlying layer used.
|
inherited |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
|
inherited |
Returns the ADU byte corresponding to the index provided.
i must be between 0 and (maxAduLength() - aduHeaderLength() - 1)
|
inherited |
Prepare the message before sending.
This function updates the ADU header or adds the CRC at the end depending on the network used.
If the message is a request transmitted over TCP, it needs a transaction identifier. If the backend is defined by the constructor, the TCP transaction identifier is provided by the backend and will therefore be consistent on the network, otherwise, it is the message that provides this value (which may be inconsistent on the network...)
|
inherited |
Prints all bytes of the message on the output stream provided.
The bytes printed are preceded by the character '<' and followed '>' if the message is a request, and preceded by the character '[' and followed '[' if the message is a response.
for debugging.
|
inherited |
Prints all bytes of the message on the output stream provided.
The bytes printed are preceded by the character prefix and followed by the suffix.
for debugging.
|
inherited |
Returns the number of elements of the request.
Can be used for the functions Read Coils(01), Read Discrete Inputs(02), Read Holding Registers(03), Write Multiple Coils(15) and Write Multiple Registers(16). This value is at the offset[3] of the PDU
uint16_t Modbus::Response::registerValue | ( | uint16_t | index | ) | const |
Returns a register value of the response.
Can be used for the functions Read Holding Registers(03) and Read Input Register(04). This value is at the pdu[2 + index*2].
void Modbus::Response::registerValues | ( | uint16_t | index, |
uint16_t | quantity, | ||
uint16_t * | values | ||
) | const |
Returns register values of the response.
Can be used for the functions Read Holding Registers(03) and Read Input Register(04). This value is at the pdu[2 + index*2].
|
inherited |
Change the size of the ADU.
Enables the size of the PDU to be forced if the ADU buffer contains information that must be kept.
void Modbus::Response::setBitValue | ( | uint16_t | index, |
bool | value | ||
) |
Sets a bit value for the response.
Can be used for the functions Read Coils(01), Read Discrete Inputs(02). This value is at the pdu[2 + index*2].
void Modbus::Response::setBitValues | ( | uint16_t | index, |
uint16_t | quantity, | ||
const bool * | values | ||
) |
Sets bit values for the response.
Can be used for the functions Read Coils(01), Read Discrete Inputs(02). This value is at the pdu[2 + index*2].
|
inherited |
Write a byte in the PDU to the supplied offset.
pduOffset has a maximum value of MaxPduLength-1, it can have a negative value in order to access the bytes of the ADU that precedes the PDU.
void Modbus::Response::setByteCount | ( | uint8_t | n | ) |
Sets the byte count for the response.
Can be used for the functions Read Coils(01), Read Discrete Inputs(02), Read Holding Registers(03), Read Input Register(04). This value is at the pdu[1].
void Modbus::Response::setExceptionCode | ( | ExceptionCode | code | ) |
Sets the exception code for the response.
Can be used for all functions. This value is at the pdu[1].
|
inherited |
Sets the function of the request.
Can be used for all functions. This value is at the offset[0] of the PDU
|
inherited |
Set the PDU data.
Copy data to the PDU message, set the PDU size.
|
inherited |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
|
inherited |
Sets the number of elements of the request.
Can be used for the functions Read Coils(01), Read Discrete Inputs(02), Read Holding Registers(03), Read Input Register(04), Write Multiple Coils(15) and Write Multiple Registers(16). This value is at the offset[3] of the PDU
void Modbus::Response::setRegisterValue | ( | uint16_t | index, |
uint16_t | value | ||
) |
Sets a register value for the response.
Can be used for the functions Read Holding Registers(03) and Read Input Register(04). This value is at the pdu[2 + index*2].
void Modbus::Response::setRegisterValues | ( | uint16_t | index, |
uint16_t | quantity, | ||
const uint16_t * | values | ||
) |
Sets register values for the response.
Can be used for the functions Read Holding Registers(03) and Read Input Register(04). This value is at the pdu[2 + index*2].
|
inherited |
Sets the response flag.
This flag indicates that the message is a response, it allows to keep the instance of the request to make a response. This could be useful in order to keep the transaction identifier intact in the case of a TCP ADU.
|
inherited |
Change the size of the PDU.
Enables the size of the PDU to be forced if the ADU buffer contains information that must be kept.
|
inherited |
Sets the number of the slave concerned by the request.
Can be used for all functions. This value is at the offset[-1] of the PDU
|
inherited |
Sets the starting address of the request.
Can be used for the functions Read Coils(01), Read Discrete Inputs(02), Read Holding Registers(03), Read Input Register(04), Write Multiple Coils(15) and Write Multiple Registers(16). This value is at the offset[1] of the PDU
|
inherited |
Sets TCP/IP transaction identifier.
It is used for transaction pairing, the MODBUS server copies in the response the transaction identifier of the request.
This value is at the offset[-7] of the PDU.
Throw an std::domain_error exception if net()!=Tcp,
|
inherited |
Write a word in the PDU to the supplied offset.
pduOffset has a maximum value of MaxPduLength-2, it can have a negative value in order to access the wordss of the ADU that precedes the PDU.
|
inherited |
returns the number of bytes of the PDU
|
inherited |
Returns the number of the slave concerned by the request.
Can be used for all functions. This value is at the offset[-1] of the PDU
|
inherited |
Returns the starting address of the request.
Can be used for the functions Read Coils(01), Read Discrete Inputs(02), Read Holding Registers(03), Write Multiple Coils(15) and Write Multiple Registers(16). This value is at the offset[1] of the PDU
|
inherited |
Returns TCP/IP transaction identifier.
It is used for transaction pairing, the MODBUS server copies in the response the transaction identifier of the request.
This value is at the offset[-7] of the PDU.
Throw an std::domain_error exception if net()!=Tcp,
|
inherited |
Returns the PDU word corresponding to the offset provided.
pduOffset has a maximum value of MaxPduLength-2, it can have a negative value in order to access the words of the ADU that precedes the PDU.