pdcomm::modbus::MfcEndpoint
Class
Modbus endpoint that runs CString JSON commands.
class MfcEndpointConstruction 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.
From the MFC consumer (examples/modbus-mfc/main.cpp):
pdcomm::modbus::MfcEndpoint endpoint;
const auto reply =
endpoint.Call(L"{\"action\":\"execute\",\"pdu\":[6,0,0,0,9]}");
if (reply.Find(L"\"response\":[6,0,0,0,9]") < 0)
return 1;Notes
- The adapter creates no thread and never touches a window. A client
requestorconnectblocks the calling thread until the response, the connection or the configured timeout, so run it from an application-owned worker thread and post the result to the UI thread. A server or gateway answers requests only while that worker sends{"action":"poll"}regularly.
Members
Call
Method
Runs one JSON command and returns the complete reply.
CString Call(const CString &command)See pdcomm_modbus_call() for the command set.
Parameters
| Name | Description |
|---|---|
command | UTF-16 JSON command object; converted to UTF-8. |
Returns
The reply {"ok":true,"result":...} converted to UTF-16.
Notes
- Throws
std::runtime_error: whosewhat()is the UTF-8 error reply{"error":"...","ok":false}when the command fails, or a fixed text when the library call itself fails.