Content:
Step 1: Implementing Call
Add the following code to header,
and source file, rsp.:
void callMethod()
{
printf("\n\n****************************************************************\n");
printf("** Try to call a method\n");
if ( g_pUaSession == NULL )
{
printf("** Error: Server not connected\n");
printf("****************************************************************\n");
return;
}
CallIn callRequest;
CallOut callResult;
ServiceSettings serviceSettings;
g_ObjectNodeIds.create(1);
g_MethodNodeIds.create(1);
g_ObjectNodeIds[0].
setNodeId( OBJECT_STRING_NODEID, NAMESPACE_INDEX );
g_MethodNodeIds[0].setNodeId( METHOD_STRING_NODEID, NAMESPACE_INDEX );
callRequest.objectId = g_ObjectNodeIds[0];
callRequest.methodId = g_MethodNodeIds[0];
status = g_pUaSession->call(
serviceSettings,
callRequest,
callResult);
{
printf(
"** Error: UaSession::call failed [ret=%s] *********\n", status.
toString().
toUtf8());
}
else
{
printf("** Error: UaSession::call succeeded!\n");
}
printf("****************************************************************\n");
}
call() calls the actual UaSession::call() in order to call a particular Method which belongs to a particular Object. UaSession::call() takes the following parameters:
- serviceSettings: the general Service settings like timeout,
- callRequest: the Object and Method to call and input arguments ( if necessary ),
- callResult: the output arguments and input argument results.
Complete header
Add
to header.
Add define
Add
. . .
#define SERVER_URL "opc.tcp://localhost:4841"
#define OBJECT_STRING_NODEID "AirConditioner_2"
#define METHOD_STRING_NODEID "AirConditioner_2.Stop"
#define NAMESPACE_INDEX 2
#define NAMESPACE_URI "MyUaServer/BuildingAutomation"
. . .
to source file.
Complete main()
Add
to main().