IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)

QModbusRequest Class

QModbusRequest is a container class containing the function code and payload that is stored inside a Modbus ADU.

This class was introduced in Qt 5.8.

Article lu   fois.

L'auteur

Liens sociaux

Viadeo Twitter Facebook Share on Google+   

QModbusRequest Class

  • Header: QModbusRequest

  • Since: Qt 5.8

  • CMake:

    find_package(Qt6 REQUIRED COMPONENTS SerialBus)

    target_link_libraries(mytarget PRIVATE Qt6::SerialBus)

  • qmake: QT += serialbus

  • Inherits: QModbusPdu

Detailed Description

A Modbus request usually consists of a single byte describing the FunctionCode and N bytes of payload

A typical Modbus request can looks like this:

 
Sélectionnez
QModbusRequest request(QModbusRequest::WriteMultipleCoils,
    QByteArray::fromHex("0013000a02cd01"));

When using the constructor taking the QByteArray, please make sure to convert the containing data to big-endian byte order before creating the request.

The same request can be created like this, if the values are known at compile time:

 
Sélectionnez
quint16 startAddress = 19, numberOfCoils = 10;
quint8 payloadInBytes = 2, outputHigh = 0xcd, outputLow = 0x01;
QModbusRequest request(QModbusRequest::WriteMultipleCoils, startAddress, numberOfCoils,
    payloadInBytes, outputHigh, outputLow);

Member Type Documentation

 

[alias] QModbusRequest::CalcFuncPtr

Typedef for a pointer to a custom calculator function with the same signature as QModbusRequest::calculateDataSize.

Member Function Documentation

 

QModbusRequest::QModbusRequest()

Constructs an invalid QModbusRequest.

QModbusRequest::QModbusRequest(const QModbusPdu &pdu)

Constructs a copy of pdu.

[explicit] QModbusRequest::QModbusRequest(QModbusPdu::FunctionCode code, const QByteArray &data = QByteArray())

Constructs a QModbusResponse with function code set to code and payload set to data. The data is expected to be stored in big-endian byte order already.

QModbusRequest::QModbusRequest(QModbusPdu::FunctionCode code, Args... data)

Constructs a QModbusRequest with function code set to code and payload set to data. The data is converted and stored in big-endian byte order.

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.

[static] int QModbusRequest::calculateDataSize(const QModbusRequest &request)

Calculates the expected data size for request based on the request's function code and data. Returns the full size of the request's data part; -1 if the size could not be properly calculated.

See Also

[static] int QModbusRequest::minimumDataSize(const QModbusRequest &request)

Returns the expected minimum data size for request based on the request's function code; -1 if the function code is not known.

[static] void QModbusRequest::registerDataSizeCalculator(QModbusPdu::FunctionCode fc, QModbusRequest::CalcFuncPtr calculator)

This function registers a user-defined implementation to calculate the request data size for function code fc. It can be used to extend or override the implementation inside QModbusRequest::calculateDataSize().

The CalcFuncPtr is a typedef for a pointer to a custom calculator function with the following signature:

 
Sélectionnez
int myCalculateDataSize(const QModbusRequest &pdu);

Related Non-Members

 

QDataStream &operator>>(QDataStream &stream, QModbusRequest &pdu)

Reads a pdu from the stream and returns a reference to the stream.

The function might fail to properly stream PDU's with function code QModbusPdu::Diagnostics or QModbusPdu::EncapsulatedInterfaceTransport because of the missing size indicator inside the PDU. In particular this may happen when the PDU is embedded into a stream that doesn't end with the diagnostic/encapsulated request itself.

Vous avez aimé ce tutoriel ? Alors partagez-le en cliquant sur les boutons suivants : Viadeo Twitter Facebook Share on Google+