PySide6.QtSerialBus.QModbusClient¶
- class QModbusClient¶
The
QModbusClientclass is the interface to send Modbus requests. More…Inherited by:
QModbusTcpClient,QModbusRtuSerialClientSynopsis¶
Methods¶
def
__init__()def
sendRawRequest()def
setTimeout()def
timeout()
Virtual methods¶
Signals¶
def
timeoutChanged()
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
QModbusClientAPI is constructed around oneQModbusClientobject, which holds the common configuration and settings for the requests it sends. OneQModbusClientshould be enough for the whole Qt application.Once a
QModbusClientobject 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.QModbusClienthas an asynchronous API. When the finished slot is called, the parameter it takes is theQModbusReplyobject containing the PDU as well as meta-data (Addressing, etc.).Note:
QModbusClientqueues 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.Constructs a Modbus client device with the specified
parent.- numberOfRetries()¶
- Return type:
int
Returns the number of retries a client will perform before a request fails. The default value is set to
3.See also
- processPrivateResponse(response, data)¶
- Parameters:
response –
QModbusResponsedata –
QModbusDataUnit
- Return type:
bool
To be implemented by custom Modbus client implementation. The default implementation ignores
responseanddata. It always returns false to indicate error.- processResponse(response, data)¶
- Parameters:
response –
QModbusResponsedata –
QModbusDataUnit
- Return type:
bool
Processes a Modbus server
responseand stores the decoded information indata. Returnstrueon success; otherwisefalse.Note
The default implementation does not support all
FunctionCodes. Override this method in a custom Modbus client implementations to handle the needed functions.- sendRawRequest(request, serverAddress)¶
- Parameters:
request –
QModbusRequestserverAddress – int
- Return type:
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, seeisValid. If no error occurred the function returns a new validQModbusReply; nullptr otherwise. Modbus networks may have multiple servers, each server has a uniqueserverAddress.See also
- sendReadRequest(read, serverAddress)¶
- Parameters:
read –
QModbusDataUnitserverAddress – int
- Return type:
Sends a request to read the contents of the data pointed by
read. Returns a new validQModbusReplyobject if no error occurred, otherwise nullptr. Modbus network may have multiple servers, each server has uniqueserverAddress.- sendReadWriteRequest(read, write, serverAddress)¶
- Parameters:
read –
QModbusDataUnitwrite –
QModbusDataUnitserverAddress – int
- Return type:
Sends a request to read the contents of the data pointed by
readand to modify the contents of the data pointed bywriteusing Modbus function codeReadWriteMultipleRegisters. Returns a new validQModbusReplyobject if no error occurred, otherwise nullptr. Modbus network may have multiple servers, each server has uniqueserverAddress.Note
: Sending this kind of request is only valid of both
readandwriteare of typeHoldingRegisters.- sendWriteRequest(write, serverAddress)¶
- Parameters:
write –
QModbusDataUnitserverAddress – int
- Return type:
Sends a request to modify the contents of the data pointed by
write. Returns a new validQModbusReplyobject if no error occurred, otherwise nullptr. Modbus network may have multiple servers, each server has uniqueserverAddress.- setNumberOfRetries(number)¶
- Parameters:
number – int
Sets the
numberof retries a client will perform before a request fails. The default value is set to3.Note
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
- setTimeout(newTimeout)¶
- Parameters:
newTimeout – int
Sets the
newTimeoutfor thisQModbusClientinstance. 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
TimeoutErroris set.Already active/running timeouts are not affected by such timeout duration changes.
See also
- timeout()¶
- Return type:
int
Returns the timeout value used by this
QModbusClientinstance in ms. A timeout is indicated by aTimeoutError. The default value is 1000 ms.See also
- timeoutChanged(newTimeout)¶
- Parameters:
newTimeout – int
This signal is emitted when the timeout used by this
QModbusClientinstance is changed. The new response timeout for the device is passed asnewTimeout.See also