Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const opcua = require("node-opcua");
- const userName = "user1"
- const password = "password1"
- //xx const endpointUrl = "opc.tcp://192.168.249.31:4840";
- const endpointUrl = "opc.tcp://localhost:26543";
- //xx const nodeId = "ns=4;s=opctest1_Copy1";
- const nodeId = "ns=411;s=Scalar_Static_UInt16";
- async function CreateConnection(){
- console.log('Trying to connect ...');
- const client = new opcua.OPCUAClient({endpoint_must_exist: false });
- await client.connect(endpointUrl);
- console.log('Connected!');
- const session = await client.createSession({userName: userName, password: password});
- let dataValue = await session.read({nodeId: nodeId })
- console.log(dataValue.toString());
- const nodeToWrite = {
- nodeId: nodeId,
- attributeId: opcua.AttributeIds.Value,
- value: /* DataValue */{
- statusCode: opcua.StatusCodes.Good,
- value: /* Variant */{
- dataType: opcua.DataType.UInt16,
- value: 1098
- }
- },
- }
- let risultato = await session.write(nodeToWrite);
- console.log(risultato.toString());
- dataValue = await session.read({nodeId: nodeId })
- console.log(dataValue.toString());
- await client.closeSession(session,true);
- await client.disconnect();
- };
- CreateConnection();
Add Comment
Please, Sign In to add comment