pdcomm::modbus::QtEndpoint
Class
Modbus endpoint that takes a QJsonObject command and returns the result object of the reply.
class QtEndpointConstruction creates a disconnected endpoint with the default configuration and throws std::runtime_error if the library cannot create it. The object is movable but not copyable.
Write holding register 0 in the local data model, as the MFC consumer examples/modbus-mfc/main.cpp does:
#include <QJsonArray>
// ...
pdcomm::modbus::QtEndpoint endpoint;
const QJsonObject result = endpoint.call(
QJsonObject{{"action", "execute"}, {"pdu", QJsonArray{6, 0, 0, 0, 9}}});
// result: {"response":[6,0,0,0,9],"source":"local","status":"success"}Notes
- A client
requestorconnectblocks until the response, the connection or the configured timeout. Run such commands in a worker thread (for example aQThreadthat owns the endpoint) and hand the results to the GUI thread with a queued signal; never block the GUI thread. A server or gateway answers requests only while that worker sends{"action":"poll"}regularly.
Members
call
Method
Runs one JSON command and returns its result object.
QJsonObject call(const QJsonObject &command)The command is serialized as compact UTF-8 JSON and passed to Endpoint::call(); see pdcomm_modbus_call() for the command set.
Parameters
| Name | Description |
|---|---|
command | Command object with an action member. |
Returns
The result member of the {"ok":true,"result":...} reply.
Notes
- Throws
std::runtime_error: whosewhat()is the error reply{"error":"...","ok":false}when the command fails, or a fixed text when the library call itself fails.