Created
March 23, 2018 13:11
-
-
Save davidemess/eeb2d8eee624c448cc4ac76c9bbdb70a to your computer and use it in GitHub Desktop.
Revisions
-
davidemess created this gist
Mar 23, 2018 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,45 @@ const endpointUrl = "opc.tcp://192.168.249.31:4840"; const opcua = require("node-opcua"); const StatusCodes = opcua.StatusCodes; const AttributeIds = opcua.AttributeIds; const DataTypes = opcua.DataType; let client; let session; async function CreateConnection(){ const OPCUAClient = opcua.OPCUAClient; console.log('Trying to connect ...'); client = new OPCUAClient({}); await client.connect(endpointUrl); console.log('Connected!'); session = await client.createSession({userName: "Davide", password: "davide"}); let val = await session.read({nodeId: "ns=4;s=opctest1_Copy1"}) console.log(val.value.value); let nodeToWrite = { nodeId: "ns=4;s=opctest1_Copy1", attributeIds: opcua.AttributeIds.Value, value: { value: { dataType: opcua.DataType.UInt16, value: 1098 } }, statusCode: opcua.StatusCodes.Good // <==== } let risultato = await session.write(nodeToWrite); console.log(risultato); val = await session.read({nodeId: "ns=4;s=opctest1_Copy1"}) console.log(val.value.value) await client.closeSession(session,true); await client.disconnect(); }; CreateConnection();