QModbusPdu is a abstract container class containing the function code and payload that is stored inside a Modbus ADU. 更多...
头: | #include <QModbusPdu> |
qmake: | QT += serialbus |
Since: | Qt 5.8 |
继承者: | QModbusRequest and QModbusResponse |
enum | ExceptionCode { IllegalFunction, IllegalDataAddress, IllegalDataValue, ServerDeviceFailure, Acknowledge, …, ExtendedException } |
enum | FunctionCode { Invalid, ReadCoils, ReadDiscreteInputs, ReadHoldingRegisters, ReadInputRegisters, …, UndefinedFunctionCode } |
QModbusPdu () | |
virtual | ~QModbusPdu () |
QByteArray | data () const |
qint16 | dataSize () const |
void | decodeData (Args &&... data ) const |
void | encodeData (Args... data ) |
QModbusPdu::ExceptionCode | exceptionCode () const |
QModbusPdu::FunctionCode | functionCode () const |
bool | isException () const |
bool | isValid () const |
void | setData (const QByteArray & data ) |
virtual void | setFunctionCode (QModbusPdu::FunctionCode code ) |
qint16 | size () const |
const quint8 | ExceptionByte |
QModbusPdu (const QModbusPdu & other ) | |
QModbusPdu (QModbusPdu::FunctionCode code , const QByteArray & data ) | |
QModbusPdu & | operator= (const QModbusPdu & other ) |
QDebug | operator<< (QDebug debug , const QModbusPdu & pdu ) |
QDataStream & | operator<< (QDataStream & stream , const QModbusPdu & pdu ) |
The class provides access to the raw Modbus protocol packets as defined by the Modbus Application Protocol Specification 1.1b.
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.
常量 | 值 | 描述 |
---|---|---|
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. |
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.
常量 | 值 | 描述 |
---|---|---|
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. |
[protected]
QModbusPdu::
QModbusPdu
(const
QModbusPdu
&
other
)
Constructs a QModbusPdu that is a copy of other .
[protected]
QModbusPdu::
QModbusPdu
(
QModbusPdu::FunctionCode
code
, const
QByteArray
&
data
)
Constructs a QModbusPdu with function code set to code and payload set to data . The data is expected to be stored in big-endian byte order already.
Constructs an invalid QModbusPdu.
[protected]
QModbusPdu
&QModbusPdu::
operator=
(const
QModbusPdu
&
other
)
Makes a copy of the other 并将其赋值给此 QModbusPdu 对象。
[虚拟]
QModbusPdu::
~QModbusPdu
()
销毁 QModbusPdu .
Returns the PDU's payload, excluding the function code. The payload is stored in big-endian byte order.
另请参阅 setData ().
Returns the PDU's data size, excluding the function code.
Converts the payload into host endianness and reads it into data . Data can be a variable length argument list.
QModbusResponsePdu response(QModbusPdu::ReportServerId); response.encodeData(quint8(0x02), quint8(0x01), quint8(0xff)); quint8 count, id, run; response.decodeData(&count, &id, &run);
注意:
Usage is limited
quint8
and
quint16
only. This is because
QDataStream
stream operators will not only append raw data, but also e.g. size, count, etc. for complex types.
Sets the payload to data . The data is converted and stored in big-endian byte order.
QModbusRequestPdu request(QModbusPdu::ReadCoils); // starting address and quantity of coils request.encodeData(quint16(0x0c), quint16(0x0a));
注意:
Usage is limited
quint8
and
quint16
only. This is because
QDataStream
stream operators will not only append raw data, but also e.g. size, count, etc. for complex types.
Returns the response's exception code.
Returns the PDU's function code.
另请参阅 setFunctionCode ().
Returns true if the PDU contains an exception code; otherwise false.
Returns true if the PDU is valid; otherwise false.
A PDU is considered valid if the message code is in the range of 1 to 255 decimal and the PDU's compound size (function code + data) does not exceed 253 bytes. A default constructed PDU is invalid.
Sets the PDU's function payload to data . The data is expected to be stored in big-endian byte order already.
另请参阅 data ().
[虚拟]
void
QModbusPdu::
setFunctionCode
(
QModbusPdu::FunctionCode
code
)
Sets the PDU's function code to code .
另请参阅 functionCode ().
Returns the PDU's full size, including function code and data size.
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.
Writes the Modbus pdu 到 debug stream.
写入 pdu 到 stream 并返回流引用。