Last active
December 13, 2016 12:20
-
-
Save erossignon/e5fa4b4133d16be6669411a790f20c61 to your computer and use it in GitHub Desktop.
Test Translate BrowsePath
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /*global require,console,setTimeout */ | |
| var opcua | |
| try { | |
| opcua = require("node-opcua"); | |
| } | |
| catch(e){ | |
| opcua = require("./index"); | |
| } | |
| var async = require("async"); | |
| var client = new opcua.OPCUAClient({ | |
| connectionStrategy: { | |
| maxRetry: 1 | |
| } | |
| }); | |
| var endpointUrl = "opc.tcp://localhost:26543/UA/MyLittleServer"; | |
| endpointUrl = "opc.tcp://192.168.0.9:49320" | |
| var browsePaths =[ | |
| opcua.browse_service.makeBrowsePath("ObjectsFolder", "/2:Channel1"), | |
| opcua.browse_service.makeBrowsePath("ObjectsFolder", "/2:Channel1<Organizes>2:Device1"), | |
| opcua.browse_service.makeBrowsePath("ObjectsFolder", "/2:Channel1/2:Device1"), | |
| opcua.browse_service.makeBrowsePath("ObjectsFolder", "/2:Channel1/2:Device1.2:Tag1"), | |
| opcua.browse_service.makeBrowsePath("ObjectsFolder", "/2:Simulation Examples"), | |
| opcua.browse_service.makeBrowsePath("ObjectsFolder", "/2:Simulation Examples/2:Device1"), | |
| opcua.browse_service.makeBrowsePath("ObjectsFolder", "/2:Simulation Examples/2:Device1/2:Item1"), | |
| opcua.browse_service.makeBrowsePath("ObjectsFolder", "/2:Simulation Examples/2:Device1.2:Item1") | |
| ]; | |
| var the_session, the_subscription; | |
| async.series([ | |
| // step 1 : connect to | |
| function(callback) { | |
| console.log(" connectiong to ",endpointUrl); | |
| client.connect(endpointUrl,function (err) { | |
| if(err) { | |
| console.log(" cannot connect to endpoint :" , endpointUrl ); | |
| } else { | |
| console.log("connected !"); | |
| } | |
| callback(err); | |
| }); | |
| }, | |
| // step 2 : createSession | |
| function(callback) { | |
| client.createSession( function(err,session) { | |
| if(!err) { | |
| the_session = session; | |
| } | |
| callback(err); | |
| }); | |
| }, | |
| function (callback) { | |
| the_session.translateBrowsePath(browsePaths, function (err, results) { | |
| if (err) { | |
| console.log("Err:" + err); | |
| } else { | |
| for(var i=0;i<results.length;i++) { | |
| var browsePath = browsePaths[i]; | |
| var result = results[i]; | |
| console.log("----------------\n",browsePath.toString(),result.toString()); | |
| } | |
| } | |
| callback(); | |
| }); | |
| }, | |
| // close session | |
| function(callback) { | |
| the_session.close(function(err){ | |
| if(err) { | |
| console.log("session closed failed ?"); | |
| } | |
| callback(); | |
| }); | |
| } | |
| ], | |
| function(err) { | |
| if (err) { | |
| console.log(" failure ",err); | |
| } else { | |
| console.log("done!"); | |
| } | |
| client.disconnect(function(){}); | |
| } | |
| ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment