Skip to main content

Method (C)

An OPC UA Method node is an RPC interface exposed by the server. It is invoked by calling DarraUa_Session_Call(...).

Subpage Redirect
  • Complete method signature / Memory ownership / Finding methods—please NodeId refer to Call.
  • Alarm Acknowledge is also invoked Call via a call; see Event Subscription.

One-Minute Example​

#include <opcua/opcua.h>

DarraUa_NodeId obj, mtd;
/* Parse "ns=2;s=Calculator" / "ns=2;s=Calculator.Add" into the (NodeId) structure DarraUa_NodeId_ParseString */

const DarraUa_Variant* args[2];
args[0] = DarraUa_Variant_New(); DarraUa_Variant_SetInt32(args[0], 3);
args[1] = DarraUa_Variant_New(); DarraUa_Variant_SetInt32(args[1], 4);

DarraUa_Variant* outs[32] = { NULL }; /* The output buffer is allocated by the caller. */
uint32_t out_n = 0;
DarraUa_Status method_status = 0;

DarraUa_Status st = DarraUa_Session_Call(
h, &obj, &mtd,
args, 2,
outs, &out_n, &method_status);

/* Release Input Parameters */
DarraUa_Variant_Delete(args[0]);
DarraUa_Variant_Delete(args[1]);

/* Using Out Parameters */
if (UA_STATUS_IS_GOOD(st) && UA_STATUS_IS_GOOD(method_status)) {
for (uint32_t i = 0; i < out_n; ++i) {
int32_t r = 0;
DarraUa_Variant_GetInt32(outs[i], &r);
printf("out[%u] = %d\n", i, (int)r);
}
}

/* Releasing arguments: The slot array belongs to the caller; only the individual elements are released one by one. */
for (uint32_t i = 0; i < out_n; ++i) DarraUa_Variant_Delete(outs[i]);

Input and output parameters can also be passed directly as strings NodeId using this convenient method DarraUa_Session_CallSafe; the output parameter group is allocated by the stack. See Call.

Next Step​