pdcomm_opcua_client_begin
Function
Queues one UA Binary service request without waiting for its response.
int32_t pdcomm_opcua_client_begin(pdcomm_opcua_handle client, const uint8_t *request, size_t size, uint32_t *out_request)request is a complete UA Binary service request that starts with its namespace zero encoding NodeId, for example ReadRequest (631). The library decodes the whole message before it queues anything, then replaces the RequestHeader's authenticationToken, timestamp and requestHandle; a zero timeoutHint becomes timeout_ms, while returnDiagnostics, auditEntryId, a non-zero timeoutHint and additionalHeader are kept.
Supported services: FindServers, GetEndpoints, Cancel, Browse, BrowseNext, TranslateBrowsePathsToNodeIds, RegisterNodes, UnregisterNodes, Read, Write, Call, HistoryRead, HistoryUpdate, the Subscription services (Create, Modify, SetPublishingMode, Publish, Republish, Transfer, Delete), the MonitoredItem services (Create, Modify, SetMonitoringMode, SetTriggering, Delete) and AddNodes, AddReferences, DeleteNodes and DeleteReferences. Secure channel and session requests are rejected: they have their own functions.
The bytes are sent by pdcomm_opcua_client_poll(). Each request must be answered within timeout_ms.
Send a request and poll until its response is available (examples/opcua/opcua_client.c):
int32_t status = pdcomm_opcua_client_begin(client, request, size, &id);
*body = NULL;
*body_size = 0;
if (status != PDCOMM_OPCUA_OK) return status;
for (;;) {
status = pdcomm_opcua_client_poll(client);
if (status != PDCOMM_OPCUA_OK) return status;
status = pdcomm_opcua_client_take_response(client, id, &response);
if (status == PDCOMM_OPCUA_OK) break;
if (status != PDCOMM_OPCUA_EMPTY) return status;
if (waited++ >= timeout_ms) return PDCOMM_OPCUA_RUNTIME_ERROR;
example_sleep_ms(1);
}
status = pdcomm_opcua_buffer_copy(response, NULL, 0, &required);
if (status == PDCOMM_OPCUA_BUFFER_TOO_SMALL && required > 0) {
*body = (uint8_t *)malloc(required);
status = *body ? pdcomm_opcua_buffer_copy(response, *body, required, body_size)
: PDCOMM_OPCUA_INTERNAL_ERROR;
}
pdcomm_opcua_release(response);
return status;Parameters
| Name | Description |
|---|---|
client | Client handle. |
request | Encoded request, at most 4 MiB; copied during the call. |
size | Size of request in bytes. |
out_request | Receives the request ID (the requestHandle), unique for this client; zero on failure. |
Returns
#PDCOMM_OPCUA_OK; #PDCOMM_OPCUA_INVALID_INPUT for an unsupported service or an invalid encoding; #PDCOMM_OPCUA_LIMIT when 64 requests are outstanding or too many bytes are queued (nothing was sent); #PDCOMM_OPCUA_BUSY while a response is held; #PDCOMM_OPCUA_CLOSED; #PDCOMM_OPCUA_RUNTIME_ERROR; #PDCOMM_OPCUA_INVALID_HANDLE or #PDCOMM_OPCUA_POISONED.