QModbusReply Class

The QModbusReply class contains the data for a request sent with a QModbusClient derived class. More...

Header: #include <QModbusReply>
Inherits: QObject

Public Types

enum ReplyType { Raw, Common, Broadcast }

Public Functions

QModbusReply(ReplyType type, int serverAddress, QObject *parent = nullptr)
void addIntermediateError(QModbusDevice::IntermediateError error)
QModbusDevice::Error error() const
QString errorString() const
QList<QModbusDevice::IntermediateError> intermediateErrors() const
bool isFinished() const
QModbusResponse rawResult() const
QModbusDataUnit result() const
int serverAddress() const
void setError(QModbusDevice::Error error, const QString &errorText)
void setFinished(bool isFinished)
void setRawResult(const QModbusResponse &response)
void setResult(const QModbusDataUnit &unit)
ReplyType type() const

Signals

void errorOccurred(QModbusDevice::Error error)
void finished()

Detailed Description

\inmoduleQtSerialBus \since 5.8

Member Type Documentation

enum QModbusReply::ReplyType

This enum describes the possible reply type.

ConstantValueDescription
QModbusReply::Raw0The reply originates from a raw Modbus request. See QModbusClient::sendRawRequest
QModbusReply::Common1The reply originates from a common read, write or read/write request. See QModbusClient::sendReadRequest, QModbusClient::sendWriteRequest and QModbusClient::sendReadWriteRequest
QModbusReply::Broadcast2The reply originates from a Modbus broadcast request. The serverAddress() will return 0 and the finished() signal will be emitted immediately.

Member Function Documentation

QModbusReply::QModbusReply(ReplyType type, int serverAddress, QObject *parent = nullptr)

Constructs a QModbusReply object with a given type and the specified parent.

The reply will be sent to the Modbus client represented by serverAddress.

void QModbusReply::addIntermediateError(QModbusDevice::IntermediateError error)

\internal\since 6.0

Adds an intermediate error to the list of intermediate errors. This will also cause the intermediateErrorOccurred() signal to be emitted.

QModbusDevice::Error QModbusReply::error() const

Returns the error state of this reply.

See also setError(), errorString(), and errorOccurred().

[signal] void QModbusReply::errorOccurred(QModbusDevice::Error error)

This signal is emitted when an error has been detected in the processing of this reply. The finished() signal will probably follow.

The error will be described by the error code error. If errorString is not empty it will contain a textual description of the error. In case of a QModbusDevice::ProtocolError the rawResult() function can be used to obtain the original Modbus exception response to get the exception code.

Note: Do not delete this reply object in the slot connected to this signal. Use deleteLater() instead.

See also error() and errorString().

QString QModbusReply::errorString() const

Returns the textual representation of the error state of this reply.

If no error has occurred this will return an empty string. It is possible that an error occurred which has no associated textual representation, in which case this will also return an empty string.

See also error() and errorOccurred().

[signal] void QModbusReply::finished()

This signal is emitted when the reply has finished processing. The reply may still have returned with an error.

After this signal is emitted, there will be no more updates to the reply's data.

Note: Do not delete the object in the slot connected to this signal. Use deleteLater().

You can also use isFinished() to check if a QNetworkReply has finished even before you receive the finished() signal.

See also setFinished(), isFinished(), and error().

QList<QModbusDevice::IntermediateError> QModbusReply::intermediateErrors() const

\since6.0

Returns the list of intermediate errors that might have happened during the send-receive cycle of a Modbus request until the QModbusReply reports to be finished.

bool QModbusReply::isFinished() const

Returns true when the reply has finished or was aborted.

See also finished() and error().

QModbusResponse QModbusReply::rawResult() const

Returns the raw response of a Modbus request.

If the request has not finished then the returned QModbusResponse instance is invalid.

See also setRawResult(), type(), and result().

QModbusDataUnit QModbusReply::result() const

Returns the preprocessed result of a Modbus request.

For read requests as well as combined read/write requests send via QModbusClient::sendReadWriteRequest() it contains the values read from the server instance.

If the request has not finished, has failed with an error or was a write request then the returned QModbusDataUnit instance is invalid.

Note: If the type() of the reply is QModbusReply::Broadcast, the return value will always be invalid. If the type() of the reply is QModbusReply::Raw, the return value might be invalid depending on the implementation of QModbusClient::processPrivateResponse().

See also setResult(), type(), rawResult(), and QModbusClient::processPrivateResponse().

int QModbusReply::serverAddress() const

Returns the server address that this reply object targets.

void QModbusReply::setError(QModbusDevice::Error error, const QString &errorText)

\internalSets the error state of this reply to error and the textual representation of the error to errorText.

This will also cause the errorOccurred() and finished() signals to be emitted, in that order.

See also error().

void QModbusReply::setFinished(bool isFinished)

\internalSets whether or not this reply has finished to isFinished.

If isFinished is true, this will cause the finished() signal to be emitted.

If the operation completed successfully, setResult() should be called before this function. If an error occurred, setError() should be used instead.

See also finished().

void QModbusReply::setRawResult(const QModbusResponse &response)

\internalSets the result of a Modbus request to a Modbus response.

See also rawResult().

void QModbusReply::setResult(const QModbusDataUnit &unit)

\internalSets the results of a read/write request to a Modbus register data unit.

See also result().

ReplyType QModbusReply::type() const

Returns the type of the reply.

Note: If the type of the reply is QModbusReply::Raw, the return value of result() will always be invalid.

See also result() and rawResult().