QModbusPdu Class
QModbusPdu is a abstract container class containing the function code and payload that is stored inside a Modbus ADU. More...
Header: | #include <QModbusPdu> |
qmake: | QT += serialbus |
Since: | Qt 5.8 |
Inherited By: |
Public Types
enum | ExceptionCode { IllegalFunction, IllegalDataAddress, IllegalDataValue, ServerDeviceFailure, ..., ExtendedException } |
enum | FunctionCode { Invalid, ReadCoils, ReadDiscreteInputs, ReadHoldingRegisters, ..., UndefinedFunctionCode } |
Public Functions
QModbusPdu() | |
virtual | ~QModbusPdu() |
QByteArray | data() const |
qint16 | dataSize() const |
void | decodeData(Args &&... newData) const |
void | encodeData(Args... newData) |
QModbusPdu::ExceptionCode | exceptionCode() const |
QModbusPdu::FunctionCode | functionCode() const |
bool | isException() const |
bool | isValid() const |
void | setData(const QByteArray &newData) |
virtual void | setFunctionCode(QModbusPdu::FunctionCode code) |
qint16 | size() const |
Static Public Members
const quint8 | ExceptionByte |
Protected Functions
QModbusPdu(QModbusPdu::FunctionCode code, const QByteArray &newData) | |
QModbusPdu(const QModbusPdu &) | |
QModbusPdu(QModbusPdu::FunctionCode code, Args... newData) | |
QModbusPdu & | operator=(const QModbusPdu &) |
Detailed Description
QModbusPdu is a abstract container class containing the function code and payload that is stored inside a Modbus ADU.
The class provides access to the raw Modbus protocol packets as defined by the Modbus Application Protocol Specification 1.1b.
Member Type Documentation
enum QModbusPdu::ExceptionCode
This enum describes all the possible error conditions as defined by Modbus Exception Codes. They are set by the server after checking the appropriate error conditions in the reply to a request and must be decoded by the client to operate on the exception code.
Constant | Value | Description |
---|---|---|
QModbusPdu::IllegalFunction | 0x01 | Function code is not supported by device. |
QModbusPdu::IllegalDataAddress | 0x02 | The received data address in the query is not an allowable address for the Modbus server. |
QModbusPdu::IllegalDataValue | 0x03 | The contained value in the request data field is not an allowable value for the Modbus server. |
QModbusPdu::ServerDeviceFailure | 0x04 | An irrecoverable error occurred while the server was attempting to perform the requested action. |
QModbusPdu::Acknowledge | 0x05 | Specialized use in conjunction with programming commands. |
QModbusPdu::ServerDeviceBusy | 0x06 | The server is engaged in processing a long duration program command. |
QModbusPdu::NegativeAcknowledge | 0x07 | The server cannot perform the program function received in the query. This code is returned for an unsuccessful programming request. The client should request diagnostic or error information from the server. |
QModbusPdu::MemoryParityError | 0x08 | Indicates that the extended file area failed to pass a consistency check. Used in conjunction with function codes 20 and 21. The exception code does not refer to any parity settings of the transmission line but only to the servers' internal memory of file records. |
QModbusPdu::GatewayPathUnavailable | 0x0A | Indicates that the gateway was unable to allocate an internal communication path from the input port to the output port for processing the request. |
QModbusPdu::GatewayTargetDeviceFailedToRespond | 0x0B | Indicates that no response was obtained from the target device behind a gateway. Usually this means the target device is not online on the network. |
QModbusPdu::ExtendedException | 0xFF | This is an extended exception as per Modbus specification. Generally this code is used to describe an exception that is otherwise further described. |
enum QModbusPdu::FunctionCode
Defines the function code and the implicit type of action required by the server. Not all Modbus devices can handle the same set of function codes.
Constant | Value | Description |
---|---|---|
QModbusPdu::Invalid | 0x00 | Set by the default constructor, do not use. |
QModbusPdu::ReadCoils | 0x01 | Requests the status of one or more coils from a device. |
QModbusPdu::ReadDiscreteInputs | 0x02 | Requests the status of one or more input registers from a device. |
QModbusPdu::ReadHoldingRegisters | 0x03 | Requests the status of one or more holding register values from a device. |
QModbusPdu::ReadInputRegisters | 0x04 | Requests the status of one or more input register values from a device. |
QModbusPdu::WriteSingleCoil | 0x05 | Requests to write a single coil on a device. |
QModbusPdu::WriteSingleRegister | 0x06 | Requests to write a single holding register on a device. |
QModbusPdu::ReadExceptionStatus | 0x07 | Requests the status of the eight Exception Status outputs on a device. |
QModbusPdu::Diagnostics | 0x08 | Used to provide a series of tests for checking the client server communication system, or checking internal |
QModbusPdu::GetCommEventCounter | 0x0B | Requests a status word and an event count from the device's communication event counter. |
QModbusPdu::GetCommEventLog | 0x0C | Requests a status word, event count, message count, and a field of event bytes from a device. |
QModbusPdu::WriteMultipleCoils | 0x0F | Requests to write one or more coils on a device. |
QModbusPdu::WriteMultipleRegisters | 0x10 | Requests to write one or more holding registers on a device. |
QModbusPdu::ReportServerId | 0x11 | Requests the description of the type, the current status, and other information specific to a device. |
QModbusPdu::ReadFileRecord | 0x14 | Requests a file record read. |
QModbusPdu::WriteFileRecord | 0x15 | Requests a file record write. |
QModbusPdu::MaskWriteRegister | 0x16 | Requests to modify the contents of a specified holding register using a combination of an AND or OR mask, and the register's current contents. |
QModbusPdu::ReadWriteMultipleRegisters | 0x17 | Requests the status of one or more holding register and at the same time to write one or more holding registers on a device. |
QModbusPdu::ReadFifoQueue | 0x18 | Requests to read the contents of a First-In-First-Out (FIFO) queue of register in a remote device. |
QModbusPdu::EncapsulatedInterfaceTransport | 0x2B | Please refer to Annex A of the Modbus specification. |
QModbusPdu::UndefinedFunctionCode | 0x100 | Do not use. |
Member Function Documentation
QModbusPdu::QModbusPdu()
Default constructs an instance of QModbusPdu.
[protected]
QModbusPdu::QModbusPdu(QModbusPdu::FunctionCode code, const QByteArray &newData)
Default constructs an instance of QModbusPdu.
[protected]
QModbusPdu::QModbusPdu(const QModbusPdu &)
Default constructs an instance of QModbusPdu.
[protected]
QModbusPdu::QModbusPdu(QModbusPdu::FunctionCode code, Args... newData)
Default constructs an instance of QModbusPdu.
[virtual]
QModbusPdu::~QModbusPdu()
Destroys the instance of QModbusPdu. The destructor is virtual.
QByteArray QModbusPdu::data() const
See also setData().
qint16 QModbusPdu::dataSize() const
void QModbusPdu::decodeData(Args &&... newData) const
void QModbusPdu::encodeData(Args... newData)
QModbusPdu::ExceptionCode QModbusPdu::exceptionCode() const
QModbusPdu::FunctionCode QModbusPdu::functionCode() const
See also setFunctionCode().
bool QModbusPdu::isException() const
bool QModbusPdu::isValid() const
void QModbusPdu::setData(const QByteArray &newData)
See also data().
[virtual]
void QModbusPdu::setFunctionCode(QModbusPdu::FunctionCode code)
See also functionCode().
qint16 QModbusPdu::size() const
[protected]
QModbusPdu &QModbusPdu::operator=(const QModbusPdu &)
Copy-assignment operator.
Member Variable Documentation
const quint8 QModbusPdu::ExceptionByte
The variable is initialized to 0x80.
Exceptions are reported in a defined packet format. A function code is returned to the requesting client equal to the original function code, except with its most significant bit set. This is equivalent to adding 0x80 to the value of the original function code.
This field may be used to mask the exception bit in the function field of a raw Modbus packet.