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

QModbusClient Class

The QModbusClient class is the interface to send Modbus requests.

This class was introduced in Qt 5.8.

Article lu   fois.

L'auteur

Liens sociaux

Viadeo Twitter Facebook Share on Google+   

QModbusClient Class

Detailed Description

The QModbusClient API is constructed around one QModbusClient object, which holds the common configuration and settings for the requests it sends. One QModbusClient should be enough for the whole Qt application.

Once a QModbusClient object has been created, the application can use it to send requests. The returned object is used to obtain any data returned in response to the corresponding request.

QModbusClient has an asynchronous API. When the finished slot is called, the parameter it takes is the QModbusReply object containing the PDU as well as meta-data (Addressing, etc.).

Note: QModbusClient queues the requests it receives. The number of requests executed in parallel is dependent on the protocol. For example, the HTTP protocol on desktop platforms issues 6 requests in parallel for one host/port combination.

Member Function Documentation

 

[explicit] QModbusClient::QModbusClient(QObject *parent = nullptr)

Constructs a Modbus client device with the specified parent.

int QModbusClient::numberOfRetries() const

Returns the number of retries a client will perform before a request fails. The default value is set to 3.

See Also

See also setNumberOfRetries()

[virtual protected] bool QModbusClient::processPrivateResponse(const QModbusResponse &response, QModbusDataUnit *data)

To be implemented by custom Modbus client implementation. The default implementation ignores response and data. It always returns false to indicate error.

[virtual protected] bool QModbusClient::processResponse(const QModbusResponse &response, QModbusDataUnit *data)

Processes a Modbus server response and stores the decoded information in data. Returns true on success; otherwise false.

The default implementation does not support all FunctionCodes. Override this method in a custom Modbus client implementations to handle the needed functions.

QModbusReply *QModbusClient::sendRawRequest(const QModbusRequest &request, int serverAddress)

Sends a raw Modbus request. A raw request can contain anything that fits inside the Modbus PDU data section and has a valid function code. The only check performed before sending is therefore the validity check, see QModbusPdu::isValid. If no error occurred the function returns a new valid QModbusReply; nullptr otherwise. Modbus networks may have multiple servers, each server has a unique serverAddress.

See Also

QModbusReply *QModbusClient::sendReadRequest(const QModbusDataUnit &read, int serverAddress)

Sends a request to read the contents of the data pointed by read. Returns a new valid QModbusReply object if no error occurred, otherwise nullptr. Modbus network may have multiple servers, each server has unique serverAddress.

QModbusReply *QModbusClient::sendReadWriteRequest(const QModbusDataUnit &read, const QModbusDataUnit &write, int serverAddress)

Sends a request to read the contents of the data pointed by read and to modify the contents of the data pointed by write using Modbus function code QModbusPdu::ReadWriteMultipleRegisters. Returns a new valid QModbusReply object if no error occurred, otherwise nullptr. Modbus network may have multiple servers, each server has unique serverAddress.

: Sending this kind of request is only valid of both read and write are of type QModbusDataUnit::HoldingRegisters.

QModbusReply *QModbusClient::sendWriteRequest(const QModbusDataUnit &write, int serverAddress)

Sends a request to modify the contents of the data pointed by write. Returns a new valid QModbusReply object if no error occurred, otherwise nullptr. Modbus network may have multiple servers, each server has unique serverAddress.

void QModbusClient::setNumberOfRetries(int number)

Sets the number of retries a client will perform before a request fails. The default value is set to 3.

The new value must be greater than or equal to 0. Changing this property will only effect new requests, not already scheduled ones.

See Also

See also numberOfRetries()

void QModbusClient::setTimeout(int newTimeout)

Sets the newTimeout for this QModbusClient instance. The minimum timeout is 10 ms.

The timeout is used by the client to determine how long it waits for a response from the server. If the response is not received within the required timeout, the TimeoutError is set.

Already active/running timeouts are not affected by such timeout duration changes.

See Also

See also timeout, timeoutChanged()

int QModbusClient::timeout() const

Returns the timeout value used by this QModbusClient instance in ms. A timeout is indicated by a TimeoutError. The default value is 1000 ms.

See Also

void QModbusClient::timeoutChanged(int newTimeout)

This signal is emitted when the timeout used by this QModbusClient instance is changed. The new response timeout for the device is passed as newTimeout.

See Also

See also setTimeout()

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