Browse Source

Created executable serverside UA_Server_setAttributeValue(); instanitated node manipulation tutorial. Tutorials now called tutorial_xy.rst to keep some order in /doc.

ichrispa 9 years ago
parent
commit
34a3c98e90

doc/firstSteps.rst → doc/tutorial_firstSteps.rst


+ 86 - 0
doc/tutorial_nodescontents.rst

@@ -0,0 +1,86 @@
+Manipulating node attributes
+============================
+
+In our last tutorial, we created some nodes using both the server and the client side API. In this tutorial, we will explore how to manipulate the contents of nodes.
+
+Getting and setting node attributes
+-----------------------------------
+
+```UA_(Server|Client)_(get|set)AttributeValue( ..., UA_AttributeId attributeId, void* value);```
+  
+
+
++----------------------------------------+-----+-----+-------------------------+
+| Attribute Name                         | get | set | Expected type for void* |
++========================================+=====+=====+=========================+
+| UA_ATTRIBUTEID_NODEID                  |  ✔  |  ✘  | UA_NodeId               |
++----------------------------------------+-----+-----+-------------------------+
+| UA_ATTRIBUTEID_NODECLASS               |  ✔  |  ✘  | UA_NodeClass | UA_UInt32|
++----------------------------------------+-----+-----+-------------------------+
+| UA_ATTRIBUTEID_BROWSENAME              |  ✔  |  ✔  | UA_QualifiedName        |
++----------------------------------------+-----+-----+-------------------------+
+| UA_ATTRIBUTEID_DISPLAYNAME             |  ✔  |  ✔  | UA_LocalizedText        |
++----------------------------------------+-----+-----+-------------------------+
+| UA_ATTRIBUTEID_DESCRIPTION             |  ✔  |  ✔  | UA_LocalizedText        |
++----------------------------------------+-----+-----+-------------------------+
+| UA_ATTRIBUTEID_WRITEMASK               |  ✔  |  ✔  | UA_UInt32               |
++----------------------------------------+-----+-----+-------------------------+
+| UA_ATTRIBUTEID_USERWRITEMASK           |  ✔  |  ✔  | UA_UInt32               |
++----------------------------------------+-----+-----+-------------------------+
+| UA_ATTRIBUTEID_ISABSTRACT              |  ✔  |  ✔  | UA_Boolean              |
++----------------------------------------+-----+-----+-------------------------+
+| UA_ATTRIBUTEID_SYMMETRIC               |  ✔  |  ✔  | UA_Boolean              |
++----------------------------------------+-----+-----+-------------------------+
+| UA_ATTRIBUTEID_INVERSENAME             |  ✔  |  ✔  | UA_LocalizedText        |
++----------------------------------------+-----+-----+-------------------------+
+| UA_ATTRIBUTEID_CONTAINSNOLOOPS         |  ✔  |  ✔  | UA_Boolean              |
++----------------------------------------+-----+-----+-------------------------+
+| UA_ATTRIBUTEID_EVENTNOTIFIER           |  ✔  |  ✔  | UA_Byte                 |
++----------------------------------------+-----+-----+-------------------------+
+| UA_ATTRIBUTEID_VALUE                   |  ✔  |  ✔  | UA_Variant              |
++----------------------------------------+-----+-----+-------------------------+
+| UA_ATTRIBUTEID_DATATYPE                |  ✔  |  ✘  | UA_NodeId               |
++----------------------------------------+-----+-----+-------------------------+
+| UA_ATTRIBUTEID_VALUERANK               |  ✔  |  ✘  | UA_Int32                |
++----------------------------------------+-----+-----+-------------------------+
+| UA_ATTRIBUTEID_ARRAYDIMENSIONS         |  ✔  |  ✘  | UA_UInt32               |
++----------------------------------------+-----+-----+-------------------------+
+| UA_ATTRIBUTEID_ACCESSLEVEL             |  ✔  |  ✔  | UA_UInt32               |
++----------------------------------------+-----+-----+-------------------------+
+| UA_ATTRIBUTEID_USERACCESSLEVEL         |  ✔  |  ✔  | UA_UInt32               |
++----------------------------------------+-----+-----+-------------------------+
+| UA_ATTRIBUTEID_MINIMUMSAMPLINGINTERVAL |  ✔  |  ✔  | UA_Double               |
++----------------------------------------+-----+-----+-------------------------+
+| UA_ATTRIBUTEID_HISTORIZING             |  ✔  |  ✔  | UA_Boolean              |
++----------------------------------------+-----+-----+-------------------------+
+| UA_ATTRIBUTEID_EXECUTABLE              |  ✔  |  ✔  | UA_Boolean              |
++----------------------------------------+-----+-----+-------------------------+
+| UA_ATTRIBUTEID_USEREXECUTABLE          |  ✔  |  ✔  | UA_Boolean              |
++----------------------------------------+-----+-----+-------------------------+
+
+The Basenode attributes NodeId and NodeClass uniquely identify that node and cannot be changed (changing them is equal to creating a new node). The DataType, ValueRank and ArrayDimensions are not part of the node attributes in open62541, but instead contained in the UA_Variant data value of that a variable or variableType node (change the value to change these as well).
+
+Setting Variable contents
+-------------------------
+
+DataSource nodes and callbacks
+------------------------------
+
+```UA_Server_addDataSourceVariableNode()```
+
+Iterating over Child nodes
+--------------------------
+
+``` UA_(Server|Client)_forEachChildNodeCall();```
+
+Examining node copies
+---------------------
+
+``` UA_(Server|Client)_getNodeCopy()```
+
+``` UA_(Server|Client)_destroyNodeCopy()```
+
+Creating object instances
+-------------------------
+
+``` UA_(Server|Client)_createInstanceOf()```

+ 5 - 1
examples/server.c

@@ -353,6 +353,10 @@ int main(int argc, char** argv) {
   printf("Nodes connected to 'Objects':\n=============================\n");
   UA_Server_forEachChildNodeCall(server, UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER), nodeIter);
   
+  // Some easy localization
+  UA_LocalizedText objectsName = UA_LOCALIZEDTEXT("de_DE", "Objekte");
+  UA_Server_setAttributeValue(server, UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER), UA_ATTRIBUTEID_DISPLAYNAME, (void *) &objectsName);
+  
   //start server
   UA_StatusCode retval = UA_Server_run(server, 1, &running); //blocks until running=false
 
@@ -368,7 +372,7 @@ int main(int argc, char** argv) {
           fprintf(triggerFile, "%s", "mmc0");
           fclose(triggerFile);
   }
-
+  
   if(ledFile)
     fclose(ledFile);
 

+ 12 - 1
src/server/ua_server_addressspace.c

@@ -861,6 +861,8 @@ UA_StatusCode UA_Server_setAttributeValue(UA_Server *server, UA_NodeId nodeId, U
     UA_ViewNode *vwObj;
   } anyTypeNode;
   retval = UA_Server_getNodeCopy(server, nodeId, (void **) &anyTypeNode.node);
+  if (retval)
+    return retval;
   
   UA_UInt32  *nInt;
   UA_Boolean *nBool;
@@ -925,6 +927,8 @@ UA_StatusCode UA_Server_setAttributeValue(UA_Server *server, UA_NodeId nodeId, U
       break;
     case UA_ATTRIBUTEID_INVERSENAME:
       SETATTRIBUTE_ASSERTNODECLASS(UA_NODECLASS_REFERENCETYPE)
+      UA_LocalizedText_deleteMembers(&anyTypeNode.rtObj->inverseName);
+      UA_LocalizedText_copy((UA_LocalizedText *) value, &anyTypeNode.rtObj->inverseName);
       break;
     case UA_ATTRIBUTEID_CONTAINSNOLOOPS:
       SETATTRIBUTE_ASSERTNODECLASS(UA_NODECLASS_VIEW)
@@ -1000,7 +1004,14 @@ UA_StatusCode UA_Server_setAttributeValue(UA_Server *server, UA_NodeId nodeId, U
       anyTypeNode.mObj->userExecutable= *nBool;
       break;
   }
-  UA_Server_deleteNodeCopy(server, (void **) &anyTypeNode.node);
+  
+  const UA_Node *oldNode = UA_NodeStore_get(server->nodestore, &nodeId);
+  const UA_Node **inserted = UA_NULL;
+  retval |= UA_NodeStore_replace(server->nodestore, oldNode, anyTypeNode.node, inserted);
+  UA_NodeStore_release(oldNode);
+  
+  // Node Copy deleted by nodeEntryFromNode() during nodestore_replace()!
+  //UA_Server_deleteNodeCopy(server, (void **) &anyTypeNode.node);
   return retval;
 }
 #endif