Differences

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

Link to this comparison view

sdk:scripts:opcua-read [2015/07/07 06:55] – created mollsdk:scripts:opcua-read [2022/09/05 12:10] (current) schmitt
Line 1: Line 1:
 ====== SDK Script opcua-read.are ====== ====== SDK Script opcua-read.are ======
 <code c opcua-read.are> <code c opcua-read.are>
-/* DESC: This script will read the Value from a Node at a OPC-UA-Server+/* DESC: This script will read the node value at a OPC-UA server
- * Copyright (C) 2012 NetModule AG+ * Copyright (C) 2015 NetModule AG, Switzerland
  */  */
  
-void usage () { +void usage ()  
-    printf("usage: opcua-read.are <opcuaserver> <nodeIndex> <nodeId>\n");+
 +    printf("usage: opcua-read.are <server> <port> <node-index> <node-id>\n");
     exit(1);     exit(1);
 } }
Line 14: Line 15:
 } }
  
-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) */ 
 +nid = (int) argv[4];            /* node id (e.g. 85 = root) */
  
-client_0 nb_opcua_connect(opcuaserver); +url sprintf("opc.tcp://%s:%d", server, port); 
-if(client_0 >= 0) { + 
- ret nb_opcua_read(client_0, nodeIndex, nodeId); +client nb_opcua_connect(url); 
- if(ret < 0) { +if (client < 0) { 
- printf("could not read value of Node Index: %d, Id: %d \n",nodeIndex, nodeId); +    printf("unable to connect to %s", url); 
-else +    exit(0); 
- printf("succesfully connected and read the value from %d\n", ret); +} 
-+ 
- nb_opcua_disconnect(client_0);+value = nb_opcua_read(client, nindex, nid); 
 +if (is_void(value)) 
 +    printf("unable to read value of node %d:%d", nindex, nid);
 } else { } else {
- printf("could not connect to server %s\n", opcuaserver);+    dump(value);
 } }
 +
 +nb_opcua_disconnect(client);
  
 exit(0); exit(0);