Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example ExpandedNodeId Reference to another server #1867

Open
4 of 7 tasks
lehned opened this issue Jun 22, 2018 · 0 comments
Open
4 of 7 tasks

Example ExpandedNodeId Reference to another server #1867

lehned opened this issue Jun 22, 2018 · 0 comments

Comments

@lehned
Copy link

lehned commented Jun 22, 2018

Description

According issue #1010 i'm trying to test or add this functionality. In Server 1 (opc.tcp:https://localhost:4840) i extend the ServerArray with the Server2 (opc.tcp:https://localhost:4841). I add to an ObjectNodeId in Server 1 an ExpandedNodeId Reference to a NodeId ( with serverindex 1) in Server2.
After this configuration i try to browse Server1 in UA Expert, but there is no reference set, or object evaluated.

Background Information / Reproduction Steps

  1. extension for example tutorial_server_object.c as Server1
Index: open62541-0.3/examples/tutorial_server_object.c
===================================================================
--- open62541-0.3/examples/tutorial_server_object.c	(revision 103)
+++ open62541-0.3/examples/tutorial_server_object.c	(working copy)
@@ -104,6 +104,18 @@
                               UA_NODEID_NUMERIC(0, UA_NS0ID_HASCOMPONENT),
                               UA_QUALIFIEDNAME(1, "MotorRPMs"),
                               UA_NODEID_NUMERIC(0, UA_NS0ID_BASEDATAVARIABLETYPE), rpmAttr, NULL, NULL);
+
+    UA_ExpandedNodeId  uaTestInstance;
+    UA_ExpandedNodeId_init(&uaTestInstance);
+
+    uaTestInstance.serverIndex = 1;
+    uaTestInstance.namespaceUri = UA_STRING("http:https://yourorganisation.org/test/");
+    uaTestInstance.nodeId = UA_NODEID_NUMERIC(2,5001);
+
+    UA_StatusCode retval = UA_STATUSCODE_GOOD;
+    retval = UA_Server_addReference(server, UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER), UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES), uaTestInstance, true);
+    UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND, "Added ExpandedNodeId %x", retval);
+
 }
 
 /**
@@ -303,6 +315,64 @@
     UA_Server_setNodeTypeLifecycle(server, pumpTypeId, lifecycle);
 }
 
+static inline char* UA_StringToCString(UA_String *data, char* buffer, size_t size)
+{
+	if (data->length < sizeof(size))
+	{
+		memcpy(buffer,data->data, data->length);
+		buffer[data->length] = 0;
+	} else {
+		buffer[0]=0;
+	}
+	return buffer;
+}
+
+static UA_StatusCode
+extendServerArray(UA_Server *server, const char* ctargertUri) {
+    UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND, "extendServerArray");
+
+    /* Find the NodeId of the status child variable */
+    UA_RelativePathElement rpe;
+    UA_RelativePathElement_init(&rpe);
+    rpe.referenceTypeId = UA_NODEID_NUMERIC(0, UA_NS0ID_HASPROPERTY);
+    rpe.isInverse = false;
+    rpe.includeSubtypes = false;
+    rpe.targetName = UA_QUALIFIEDNAME(0, "ServerArray");
+
+    UA_BrowsePath bp;
+    UA_BrowsePath_init(&bp);
+    bp.startingNode = UA_NODEID_NUMERIC(0, 2253);
+    bp.relativePath.elementsSize = 1;
+    bp.relativePath.elements = &rpe;
+
+    UA_BrowsePathResult bpr =
+        UA_Server_translateBrowsePathToNodeIds(server, &bp);
+    if(bpr.statusCode != UA_STATUSCODE_GOOD ||
+       bpr.targetsSize < 1)
+        return bpr.statusCode;
+
+    UA_Variant Value;
+    UA_String targetUri = UA_String_fromChars(ctargertUri);
+
+    UA_Server_readValue(server, bpr.targets[0].targetId.nodeId,
+                        &Value);
+
+    /** ServerArray */
+    UA_String *uaServerArray = (UA_String*)UA_Array_new(2,Value.type);
+    UA_copy(Value.data, &uaServerArray[0], Value.type);
+    UA_copy(&targetUri, &uaServerArray[1], Value.type);
+
+    /* Add server array the status value */
+    UA_Variant_setArrayCopy(&Value, uaServerArray, 2, Value.type);
+    UA_Server_writeValue(server, bpr.targets[0].targetId.nodeId, Value);
+    UA_BrowsePathResult_deleteMembers(&bpr);
+
+    UA_Array_delete(uaServerArray,2, Value.type);
+    UA_Variant_deleteMembers(&Value);
+
+    return UA_STATUSCODE_GOOD;
+}
+
 /** It follows the main server code, making use of the above definitions. */
 
 UA_Boolean running = true;
@@ -316,8 +386,14 @@
     signal(SIGTERM, stopHandler);
 
     UA_ServerConfig *config = UA_ServerConfig_new_default();
+    /** set Application URI */
+    config->applicationDescription.applicationName =
+        UA_LOCALIZEDTEXT_ALLOC("en", "opc.tcp:https://localhost:4840");
+
     UA_Server *server = UA_Server_new(config);
 
+    extendServerArray(server, "opc.tcp:https://localhost:4841");
+
     manuallyDefinePump(server);
     defineObjectTypes(server);
     addPumpObjectInstance(server, "pump2");
  1. extension for example server_nodeset.c for Server2
Index: open62541-0.3/examples/nodeset/server_nodeset.c
===================================================================
--- open62541-0.3/examples/nodeset/server_nodeset.c	(revision 103)
+++ open62541-0.3/examples/nodeset/server_nodeset.c	(working copy)
@@ -19,7 +19,10 @@
     signal(SIGINT, stopHandler);
     signal(SIGTERM, stopHandler);
     
-    UA_ServerConfig *config = UA_ServerConfig_new_default();
+    UA_ServerConfig *config = UA_ServerConfig_new_minimal(4841, 0);
+    /** set Application URI */
+    config->applicationDescription.applicationName =
+        UA_LOCALIZEDTEXT_ALLOC("en", "opc.tcp:https://localhost:4841");
     UA_Server *server = UA_Server_new(config);
 
     UA_StatusCode retval;
  1. modification Operation_addReference() in ua_service_nodemanagment.c to add ExpandedNodeId reference
Index: open62541-0.3/src/server/ua_services_nodemanagement.c
===================================================================
--- open62541-0.3/src/server/ua_services_nodemanagement.c	(revision 103)
+++ open62541-0.3/src/server/ua_services_nodemanagement.c	(working copy)
@@ -1365,6 +1365,9 @@
     } else if(*retval != UA_STATUSCODE_GOOD)
         return;
 
+    if (item->targetNodeId.serverIndex != 0)
+    	return;
+
     /* Add the second direction */
     UA_AddReferencesItem secondItem;
     UA_AddReferencesItem_init(&secondItem);

Checklist

Please provide the following information:

  • open62541 Version (release number or git tag): 0.3-rc2 808239d
  • Other OPC UA SDKs used (client or server): UA Expert
  • Operating system: MSYS, MINGW32, GCC 6.3.0
  • Logs (with UA_LOGLEVEL set as low as necessary) attached
  • Wireshark network dump attached
  • Self-contained code example attached
  • Critical issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant