瀏覽代碼

Add variable that can be written but not read to the CTT examples

Julius Pfrommer 6 年之前
父節點
當前提交
8911d0a308
共有 1 個文件被更改,包括 14 次插入0 次删除
  1. 14 0
      examples/server_ctt.c

+ 14 - 0
examples/server_ctt.c

@@ -177,6 +177,20 @@ main(int argc, char **argv) {
                               myIntegerName, baseDataVariableType, myVar, NULL, NULL);
     UA_Variant_deleteMembers(&myVar.value);
 
+    /* add a static variable that is readable but not writable*/
+    myVar = UA_VariableAttributes_default;
+    myVar.description = UA_LOCALIZEDTEXT("en-US", "the answer - not readable");
+    myVar.displayName = UA_LOCALIZEDTEXT("en-US", "the answer - not readable");
+    myVar.accessLevel = UA_ACCESSLEVELMASK_WRITE;
+    myVar.dataType = UA_TYPES[UA_TYPES_INT32].typeId;
+    myVar.valueRank = -1;
+    UA_Variant_setScalarCopy(&myVar.value, &myInteger, &UA_TYPES[UA_TYPES_INT32]);
+    const UA_QualifiedName myInteger2Name = UA_QUALIFIEDNAME(1, "the answer - not readable");
+    const UA_NodeId myInteger2NodeId = UA_NODEID_STRING(1, "the.answer.no.read");
+    UA_Server_addVariableNode(server, myInteger2NodeId, parentNodeId, parentReferenceNodeId,
+                              myInteger2Name, baseDataVariableType, myVar, NULL, NULL);
+    UA_Variant_deleteMembers(&myVar.value);
+
     /* add a variable with the datetime data source */
     UA_DataSource dateDataSource;
     dateDataSource.read = readTimeData;