Search code examples
opc-uanode-opcua

How can I change value from a node when having a server instance (node-opcua)


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?


Solution

  • 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());