The QModbusClient class is the interface to send Modbus requests. 更多...
| 頭: | #include <QModbusClient> |
| qmake: | QT += serialbus |
| Since: | Qt 5.8 |
| 繼承: | QModbusDevice |
| 繼承者: | QModbusRtuSerialMaster and QModbusTcpClient |
| QModbusClient (QObject * parent = nullptr) | |
| int | numberOfRetries () const |
| QModbusReply * | sendRawRequest (const QModbusRequest & request , int serverAddress ) |
| QModbusReply * | sendReadRequest (const QModbusDataUnit & read , int serverAddress ) |
| QModbusReply * | sendReadWriteRequest (const QModbusDataUnit & read , const QModbusDataUnit & write , int serverAddress ) |
| QModbusReply * | sendWriteRequest (const QModbusDataUnit & write , int serverAddress ) |
| void | setNumberOfRetries (int number ) |
| void | setTimeout (int newTimeout ) |
| int | timeout () const |
| void | timeoutChanged (int newTimeout ) |
| const QMetaObject | staticMetaObject |
| virtual bool | processPrivateResponse (const QModbusResponse & response , QModbusDataUnit * data ) |
| virtual bool | processResponse (const QModbusResponse & response , QModbusDataUnit * data ) |
The QModbusClient class is the interface to send Modbus requests.
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.
一旦 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.).
注意: 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.
This property holds the timeout value used by this client
返迴的超時值用於此 QModbusClient 實例以 ms 為單位。超時的指示是通過 TimeoutError 。默認值是 1000 ms。
訪問函數:
| int | timeout () const |
| void | setTimeout (int newTimeout ) |
通知程序信號:
| void | timeoutChanged (int newTimeout ) |
另請參閱 setTimeout .
Constructs a Modbus client device with the specified parent .
Returns the number of retries a client will perform before a request fails. The default value is set to
3
.
另請參閱 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
)
處理 Modbus 服務器 response 並把解碼信息存儲於 data . Returns true on success; otherwise false.
發送原生 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 a new valid QModbusReply ; nullptr otherwise. Modbus networks may have multiple servers, each server has a unique serverAddress .
另請參閱 QModbusReply::rawResult ().
Sends a request to read the contents of the data pointed by read 。返迴新的有效 QModbusReply object if no error occurred, otherwise nullptr. Modbus network may have multiple servers, each server has unique 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 。返迴新的有效 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 .
Sends a request to modify the contents of the data pointed by write 。返迴新的有效 QModbusReply object if no error occurred, otherwise nullptr. Modbus network may have multiple servers, each server has unique serverAddress .
設置
number
of retries a client will perform before a request fails. The default value is set to
3
.
注意:
新值必須 >=
0
. Changing this property will only effect new requests, not already scheduled ones.
另請參閱 numberOfRetries ().
設置 newTimeout 為此 QModbusClient instance. The minimum timeout is 50 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 有設置。
Already active/running timeouts are not affected by such timeout duration changes.
注意: setter 函數對於特性 timeout .
另請參閱 timeout and timeoutChanged ().
[signal]
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 .
注意: 通知程序信號對於特性 timeout .
另請參閱 setTimeout ().