modbuspp
1.1.40
C++ wrapper for the libmodbus library
|
Modbus Request Message. More...
#include <request.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 | |
uint8_t | byte (int pduOffset) const |
Returns the PDU byte corresponding to the offset provided. More... | |
uint8_t | byteCount () const |
Returns the byte count of the request. More... | |
void | clear () |
Empties the message and returns it to the initial state. | |
bool | coilValue () const |
Returns the coil value of the request. More... | |
bool | coilValue (uint16_t index) const |
Returns a coil value of the request. More... | |
void | coilValues (uint16_t index, uint16_t quantity, bool *values) const |
Returns coil values of the request. More... | |
uint16_t | crc () const |
Return the CRC read in the message. 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 () const |
Returns the register value of the request. More... | |
uint16_t | registerValue (uint16_t index) const |
Returns a register value of the request. More... | |
void | registerValues (uint16_t index, uint16_t quantity, uint16_t *values) const |
Returns a register values of the request. More... | |
Request (NetLayer &backend) | |
Constructors. | |
Request (const Request &other) | |
Constructs a copy of other. | |
Request (Request &&other) | |
Move Constructor The object acquires the content managed by other. other becomes an empty object (as if default-constructed). | |
void | setAduSize (size_t size) |
Change the size of the ADU. 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 request. More... | |
void | setCoilValue (bool value) |
Sets the coil value for the request. More... | |
void | setCoilValue (uint16_t index, bool value) |
Sets the coil value for the request. More... | |
void | setCoilValues (uint16_t index, uint16_t quantity, const bool *values) |
Sets register values for the request. 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 value) |
Sets the register value for the request. More... | |
void | setRegisterValue (uint16_t index, uint16_t value) |
Sets a register value for the request. More... | |
void | setRegisterValues (uint16_t index, uint16_t quantity, const uint16_t *values) |
Sets register values for the request. 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
|
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.
uint8_t Modbus::Request::byteCount | ( | ) | const |
Returns the byte count of the request.
Can be used for the functions Write Multiple Coils(15) and Write Multiple Registers(16). This value is at the pdu[5].
bool Modbus::Request::coilValue | ( | ) | const |
Returns the coil value of the request.
Can be used for function Write Single Coil(05). This value is at the pdu[3].
bool Modbus::Request::coilValue | ( | uint16_t | index | ) | const |
Returns a coil value of the request.
Can be used for function Write Multiple Coils(15). This values are at the pdu[6+index/8].
void Modbus::Request::coilValues | ( | uint16_t | index, |
uint16_t | quantity, | ||
bool * | values | ||
) | const |
Returns coil values of the request.
Can be used for function Write Multiple Coils(15). This values are at the pdu[6+index/8].
|
inherited |
|
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::Request::registerValue | ( | ) | const |
Returns the register value of the request.
Can be used for function Write Single Register(06). This value is at the pdu[3].
uint16_t Modbus::Request::registerValue | ( | uint16_t | index | ) | const |
Returns a register value of the request.
Can be used for function Write Multiple registers(16). This value is at the pdu[6+index].
void Modbus::Request::registerValues | ( | uint16_t | index, |
uint16_t | quantity, | ||
uint16_t * | values | ||
) | const |
Returns a register values of the request.
Can be used for function Write Multiple registers(16). This values are at the pdu[6+index].
|
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.
|
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::Request::setByteCount | ( | uint8_t | n | ) |
Sets the byte count for the request.
Can be used for the functions Write Multiple Coils(15) and Write Multiple Registers(16). This value is at the pdu[5].
void Modbus::Request::setCoilValue | ( | bool | value | ) |
Sets the coil value for the request.
Can be used for function Write Single Coil(05). This value is at the pdu[3].
void Modbus::Request::setCoilValue | ( | uint16_t | index, |
bool | value | ||
) |
Sets the coil value for the request.
Can be used for function Write Multiple Coils(15). This values are at the pdu[6+index/8].
void Modbus::Request::setCoilValues | ( | uint16_t | index, |
uint16_t | quantity, | ||
const bool * | values | ||
) |
Sets register values for the request.
Can be used for function Write Multiple Coils(15). This values are at the pdu[6+index/8].
|
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::Request::setRegisterValue | ( | uint16_t | value | ) |
Sets the register value for the request.
Can be used for function Write Single Register(06). This value is at the pdu[3].
void Modbus::Request::setRegisterValue | ( | uint16_t | index, |
uint16_t | value | ||
) |
Sets a register value for the request.
Can be used for function Write Multiple registers(16). This value is at the pdu[6+index].
void Modbus::Request::setRegisterValues | ( | uint16_t | index, |
uint16_t | quantity, | ||
const uint16_t * | values | ||
) |
Sets register values for the request.
Can be used for function Write Multiple registers(16). This value is at the pdu[6+index].
|
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.