Created
February 5, 2017 23:08
-
-
Save erossignon/282de0912e32a66f47a41da36a5a9acb to your computer and use it in GitHub Desktop.
This file contains 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
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