Created
December 16, 2018 15:23
-
-
Save erossignon/bfa0cc6dc9249ca7af397249cb1882a7 to your computer and use it in GitHub Desktop.
withSession in typescript
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
// tslint:disable:no-console | |
import { AttributeIds, ClientSession, OPCUAClient } from "node-opcua"; | |
const endpointUrl = "opc.tcp://opcuademo.sterfive.com:26543"; | |
async function main() { | |
try { | |
const client = OPCUAClient.create({clientName: "DemoClient"}); | |
await client.withSessionAsync(endpointUrl, async (session: ClientSession) => { | |
console.log("sessionId = ", session.sessionId.toString()); | |
const dataValue = await session.read({nodeId: session.sessionId, attributeId: AttributeIds.Value}); | |
console.log("value = ", dataValue.toString()); | |
}); | |
} catch (err) { | |
console.log("Error = ", err); | |
} | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment