Differences

This shows you the differences between two versions of the page.

Link to this comparison view

sdk:scripts:opcua-write [2015/07/07 06:58] – created mollsdk:scripts:opcua-write [2022/09/05 12:12] (current) schmitt
Line 2: Line 2:
 <code c opcua-write.are> <code c opcua-write.are>
  
-/* DESC: This script will write a new Value to a Node at a OPC-UA-Server+/* DESC: This script will write a new value to a node at a OPC-UA server
- * Copyright (C) 2012 NetModule AG+ * Copyright (C) 2015 NetModule AG, Switzerland
  */  */
  
-void usage () { +void usage () 
-    printf("usage: opcua-write.are <opcuaserver> <nodeIndex> <nodeId> <newValue>\n");+
 +    printf("usage: opcua-write.are <server> <port> <node-index> <node-id> <new-value>\n");
     exit(1);     exit(1);
 } }
Line 15: Line 16:
 } }
  
-opcuaserver = argv[1]; +server = argv[1];               /* hostname or address */ 
-nodeIndex = (int) argv[2]; +port = (int) argv[2];           /* TCP port */ 
-nodeId = (int) argv[3]; +nindex = (int) argv[3];         /* node index (e.g. 0) */ 
-newValue = (int) argv[4];+nid = (int) argv[4];            /* node id (e.g. 85 = root) */ 
 +value = argv[5];                /* new value */
  
-client_0 = nb_opcua_connect(opcuaserver); +url = sprintf("opc.tcp://%s:%d", server, port); 
-if(client_0 >= 0) { + 
- ret = nb_opcua_write(client_0nodeIndexnodeIdnewValue); +client = nb_opcua_connect(url); 
- if(ret < 0) { +if (client < 0) { 
- printf("could not change value of Node Index: %d, Id: %d \n",nodeIndexnodeId); +    printf("unable to connect to %s", url); 
- } else { +    exit(0); 
- printf("succesfully connected and changed to value to %d\n", ret); +
-+ 
- nb_opcua_disconnect(client_0);+ret = nb_opcua_write(clientnindexnidvalue); 
 + 
 +if (ret < 0) { 
 +    printf("unable to write value of node %d:%d", nindexnid);
 } else { } else {
- printf("could not connect to server %s\n", opcuaserver);+    printf("node %d:%d has been written", nindex, nid);
 } }
 +
 +nb_opcua_disconnect(client);
  
 exit(0); exit(0);
 +
  
 </code> </code>