Skip to content

Instantly share code, notes, and snippets.

@erossignon
Created February 5, 2017 23:08
Show Gist options
  • Save erossignon/282de0912e32a66f47a41da36a5a9acb to your computer and use it in GitHub Desktop.
Save erossignon/282de0912e32a66f47a41da36a5a9acb to your computer and use it in GitHub Desktop.
import {
BrowseResult,
BrowseDescription,
BrowseDirection,
OPCUAClient,
MessageSecurityMode,
SecurityPolicy,
ClientSession
} from "node-opcua";
import async = require("async");
const client = new OPCUAClient({
securityMode: MessageSecurityMode.None,
securityPolicy: SecurityPolicy.NONE,
connectionStrategy: {
maxRetry:0
}
});
type Callback = (err?: Error) => void;
let session: ClientSession= null;
async.series([
function (callback: Callback) {
client.connect("opc.tcp://localhost:48010", function (err?:Error) {
callback(err);
});
},
function (callback: Callback) {
client.createSession(function(err: Error|null,result?: ClientSession){
if (err) return callback(err);
session = result;
callback();
})
},
function (callback: Callback) {
session.browse("RootFolder",function(err: Error|null,result: BrowseResult) {
if(err) return callback(err);
console.log(result.toString());
callback();
});
},
function (callback: Callback) {
session.browse(["RootFolder"],function(err: Error|null,result: Array<BrowseResult>) {
if(err) return callback(err);
console.log(result[0].toString());
callback();
});
},
function (callback: Callback) {
let browseDescription: BrowseDescription={
browseDirection: BrowseDirection.Forward,
nodeId: "RootFolder"
};
session.browse(browseDescription,function(err: Error|null,result: Array<BrowseResult>) {
if(err) return callback(err);
console.log(result[0].toString());
callback();
});
},
function (callback: Callback) {
client.closeSession(session,false,callback);
},
function (callback: Callback) {
client.disconnect(function (err?:Error|null) {
callback(err);
});
},
], function (err:Error) {
console.log("done",err);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment