OPC UA Entegrasyonu
NetModule ve OPC UA
NetModule yönlendiricilerle ücretsiz gelen SDK ile hazırlanmış aşağıdaki betikleri kullanarak bir OPC UA sunucu ile veri bağlantısı kurup sunucu tarafında size verilen yetkiler çerçevesinde veri alış verişi gerçekleştirebilirsiniz.
SDK hakkında detaylı bilgi için tıklayın
OPC UA - Browse
/* DESC: This script will browse for Nodes, it will start at the given
* Node for the given depth.
* Copyright (C) 2012 NetModule AG
*/
void usage () {
printf("usage: opcua-browse.are <opcuaserver> <nodeIndex> <nodeId> <depth>\n");
exit(1);
}
if (argc != 3) {
usage();
}
opcuaserver = argv[1];
nodeIndex = (int) argv[2];
nodeId = (int) argv[3];
depth = (int) argv[4];
client_0 = nb_opcua_connect(opcuaserver);
if(client_0 >= 0) {
ret = nb_opcua_browse(client_0, nodeIndex, nodeId, depth);
if(ret == -1) {
printf("could not search for %s\n", searchingString);
} else {
printf("succesfully connected and searched for %s\n", searchingString);
printf("the result is:\n");
dump(ret);
}
nb_opcua_disconnect(client_0);
} else {
printf("could not connect to server %s\n", opcuaserver);
}
exit(0);OPC UA - Search
/* DESC: This script will search for Nodes similar to the given String.
* Copyright (C) 2012 NetModule AG
*/
void usage () {
printf("usage: opcua-search.are <opcuaserver> <searchingString>\n");
exit(1);
}
if (argc != 2) {
usage();
}
opcuaserver = argv[1];
searchingString = argv[2];
client_0 = nb_opcua_connect(opcuaserver);
if(client_0 >= 0) {
ret = nb_opcua_search(client_0, searchingString);
if(ret == -1) {
printf("could not search for %s\n", searchingString);
} else {
printf("succesfully connected and searched for %s\n", searchingString);
printf("the result is:\n");
dump(ret);
}
nb_opcua_disconnect(client_0);
} else {
printf("could not connect to server %s\n", opcuaserver);
}
exit(0);OPC UA - Read
/* DESC: This script will read the node value at a OPC-UA server.
* Copyright (C) 2015 NetModule AG, Switzerland
*/
void usage ()
{
printf("usage: opcua-read.are <server> <port> <node-index> <node-id>\n");
exit(1);
}
if (argc != 4) {
usage();
}
server = argv[1]; /* hostname or address */
port = (int) argv[2]; /* TCP port */
nindex = (int) argv[3]; /* node index (e.g. 0) */
nid = (int) argv[4]; /* node id (e.g. 85 = root) */
url = sprintf("opc.tcp://%s:%d", server, port);
client = nb_opcua_connect(url);
if (client < 0) {
printf("unable to connect to %s", url);
exit(0);
}
value = nb_opcua_read(client, nindex, nid);
if (is_void(value)) {
printf("unable to read value of node %d:%d", nindex, nid);
} else {
dump(value);
}
nb_opcua_disconnect(client);
exit(0);OPC UA - Write
/* DESC: This script will write a new value to a node at a OPC-UA server.
* Copyright (C) 2015 NetModule AG, Switzerland
*/
void usage ()
{
printf("usage: opcua-write.are <server> <port> <node-index> <node-id> <new-value>\n");
exit(1);
}
if (argc != 5) {
usage();
}
server = argv[1]; /* hostname or address */
port = (int) argv[2]; /* TCP port */
nindex = (int) argv[3]; /* node index (e.g. 0) */
nid = (int) argv[4]; /* node id (e.g. 85 = root) */
value = argv[5]; /* new value */
url = sprintf("opc.tcp://%s:%d", server, port);
client = nb_opcua_connect(url);
if (client < 0) {
printf("unable to connect to %s", url);
exit(0);
}
ret = nb_opcua_write(client, nindex, nid, value);
if (ret < 0) {
printf("unable to write value of node %d:%d", nindex, nid);
} else {
printf("node %d:%d has been written", nindex, nid);
}
nb_opcua_disconnect(client);
exit(0);