QModbusClient#

The QModbusClient class is the interface to send Modbus requests. More

Inheritance diagram of PySide6.QtSerialBus.QModbusClient

Inherited by: QModbusTcpClient, QModbusRtuSerialClient

Synopsis#

Functions#

Signals#

Note

This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE

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.

class PySide6.QtSerialBus.QModbusClient([parent=None])#
Parameters:

parentPySide6.QtCore.QObject

Constructs a Modbus client device with the specified parent.

PySide6.QtSerialBus.QModbusClient.numberOfRetries()#
Return type:

int

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

PySide6.QtSerialBus.QModbusClient.sendRawRequest(request, serverAddress)#
Parameters:
Return type:

PySide6.QtSerialBus.QModbusReply

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 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

rawResult()

PySide6.QtSerialBus.QModbusClient.sendReadRequest(read, serverAddress)#
Parameters:
Return type:

PySide6.QtSerialBus.QModbusReply

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.

PySide6.QtSerialBus.QModbusClient.sendReadWriteRequest(read, write, serverAddress)#
Parameters:
Return type:

PySide6.QtSerialBus.QModbusReply

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 ReadWriteMultipleRegisters . Returns a new valid QModbusReply object if no error occurred, otherwise nullptr. Modbus network may have multiple servers, each server has unique serverAddress.

Note

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

PySide6.QtSerialBus.QModbusClient.sendWriteRequest(write, serverAddress)#
Parameters:
Return type:

PySide6.QtSerialBus.QModbusReply

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.

PySide6.QtSerialBus.QModbusClient.setNumberOfRetries(number)#
Parameters:

number – int

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

Note

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

PySide6.QtSerialBus.QModbusClient.setTimeout(newTimeout)#
Parameters:

newTimeout – int

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.

PySide6.QtSerialBus.QModbusClient.timeout()#
Return type:

int

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

PySide6.QtSerialBus.QModbusClient.timeoutChanged(newTimeout)#
Parameters:

newTimeout – int

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

setTimeout()