4

I'm using node-opcua library. I have instance of OPCUAServer. How can I get node value and edit it?

I assume OPC client should be able to do it, but I want to interact with OPC server since I'm responding to an internal event.

Should I maybe use something like WriteRequest to perform such operation?

Astrowie
  • 195
  • 2
  • 17

2 Answers2

5

alternatively you can use the setValueFromSource method on the variable. This will bypass all Read/Write access checking that takes place in writeValue. It is also synchronous

nodeToChange.setValueFromSource({ dataType: "Double", value: 3.14});

setValueFromSource can take an optional statusCode

nodeToChange.setValueFromSource(
     { dataType: "Double", value: 3.14}, 
     opcua.StatusCodes.BadWaitingForInitialData
);

if not specified StatusCodes.Good is assumed.

and a optional source timestamp

nodeToChange.setValueFromSource(
    { dataType: "Double", value: 3.14},
     opcua.StatusCodes.Good, new Date());
Etienne
  • 16,249
  • 3
  • 26
  • 31
1

I manage to resolve it with UAVariable's writeValue() method:

var opcua = require('node-opcua');

var server = new opcua.OPCUAServer({
  port: OpcServerConfig.port, 
  resourcePath: OpcServerConfig.resourcePath, 
  buildInfo: OpcServerConfig.buildInfo
});

var nodeToChange = server.engine.addressSpace.findNode('ns=1;b=1020FFAA');

nodeToChange.writeValue(
      null, 
      new opcua.DataValue({
        value: new opcua.Variant({dataType: opcua.DataType.Double, value: 5})
      }),
      null, 
      () => { }
);
Astrowie
  • 195
  • 2
  • 17