Content:
Due to the fact that Read and Write are called with NodeIds, not with handles like in COM DA, UaSession provides registerNodes() to allow a client to optimize the cyclic access to Nodes for example for writing variable values or for calling methods.
Step 1: Implementing registerNodes()
Add the following code to header,
. . .
void registerNodes();
and source file, rsp.:
void registerNodes()
{
printf("\n\n****************************************************************\n");
printf("** Try to call registerNodes for configured node ids\n");
if ( g_pUaSession == NULL )
{
printf("** Error: Server not connected\n");
printf("****************************************************************\n");
return;
}
OpcUa_UInt32 i;
OpcUa_UInt32 count;
UaNodeIdArray nodesToRegister;
UaNodeIdArray registeredNodes;
ServiceSettings serviceSettings;
count = g_VariableNodeIds.length();
nodesToRegister.create(count);
for ( i=0; i<count; i++ )
{
g_VariableNodeIds[i].copyTo(&nodesToRegister[i]);
}
status = g_pUaSession->registerNodes(
serviceSettings,
nodesToRegister,
registeredNodes);
{
printf(
"** Error: UaSession::registerNodes failed [ret=%s] **\n", status.
toString().
toUtf8());
}
else
{
printf("** UaSession::registerNodes succeeded\n");
for ( i=0; i<count; i++ )
{
g_VariableNodeIds[i] = registeredNodes[i];
}
printf("****************************************************************\n");
}
}
Finally call setupSecurity in main() :
whereas the placement of this statement can be in any order after the platformlayer has been initialized.
Step 2: Implementing unregisterNodes()
In order to delete shortcuts in the server created by registerNodes() add the following code to header,
. . .
void unregisterNodes();
and source file, rsp.:
void unregisterNodes()
{
printf("\n\n****************************************************************\n");
printf("** Try to call unregisterNodes for removing node ids\n");
if ( g_pUaSession == NULL )
{
printf("** Error: Server not connected\n");
printf("****************************************************************\n");
return;
}
OpcUa_UInt32 i;
OpcUa_UInt32 count;
UaNodeIdArray nodesToUnregister;
ServiceSettings serviceSettings;
count = g_VariableNodeIds.length();
nodesToUnregister.create(count);
for ( i=0; i<count; i++ )
{
g_VariableNodeIds[i].copyTo(&nodesToUnregister[i]);
}
status = g_pUaSession->unregisterNodes(
serviceSettings,
nodesToUnregister);
{
printf(
"** Error: UaSession::unregisterNodes failed [ret=%s] **\n", status.
toString().
toUtf8());
}
else
{
printf("** UaSession::unregisterNodes succeeded\n");
}
buildNodeIds();
printf("****************************************************************\n");
}
Finally call unregisterNodes() in main():
registerNodes();
. . .
unregisterNodes();