How to create nodes with mirroring on the fly

Created by Vester Business Support Team, Modified on Thu, 18 May 2023 at 01:24 PM by Vester Business Support Team

For some applications, you may need to create nodes by scripting. That can be done using the Ua.createNode function that you can find in the user manual.


In addition, if those variables have to be mirrored to data source variables, some additional configuration must be applied. Let's do two examples:

1. Creating a node with an InputOutput mirror to a variable in a connected OPC DA server.

2. Creating a node with an Input mirror to a variable in a connected OPC UA server.


1. Creating a node with an InputOutput mirror to a variable in a connected OPC DA server


1.1 Create a local connection to an OPC DA server:


1.2 Create a serverside script to create the variable node and the mirror InputOutput sub node. You must know first the address of the variable in your OPC DA server. In our example, it is "Matrikon/Bucket Brigade.Int1" from a local Matrikon OPC DA server:


var node = Ua.createNode("AGENT.OBJECTS.var1_da", {

    nodeClass: Ua.NodeClass.VARIABLE,

    parent: "AGENT.OBJECTS",

    typeDefinition: Ua.VariableType.BASEVARIABLETYPE,

    reference: Ua.Reference.HASCOMPONENT,

    dataType: Ua.DataType.INT32,

    valueRank: Ua.ValueRank.SCALAR,

    value: 1

});


node = Ua.createNode("AGENT.OBJECTS.var1_da.MirrorInputOutput", {

    "browseName":"MirrorInputOutput",

    "dataType":"i=12",

    "description":"MirrorInputOutput",

    "displayName":"MirrorInputOutput",

    "nodeClass":2,

    "parent":"AGENT.OBJECTS.var1_da", 

    "reference":"i=47",

    "typeDefinition":"VariableTypes.ATVISE.Mirror.InputOutput",

    "value":"Matrikon/Bucket Brigade.Int1", // Address of the variable in the OPC DA data source

    "valueRank":-1

});



1.3 Execute the script and test the results:


2. Creating a node with an Input mirror to a variable in a connected OPC UA server


2.1 Create a connection to an OPC UA server:


2.2 Create a serverside script to create the variable node and the mirror Input sub node. You must know first the address of the variable in your OPC UA server. In our example, it is "Prosys/ns=3;i=1001" from a Prosys OPC UA server: 


var node = Ua.createNode("AGENT.OBJECTS.var1_ua", {

    nodeClass: Ua.NodeClass.VARIABLE,

    parent: "AGENT.OBJECTS",

    typeDefinition: Ua.VariableType.BASEVARIABLETYPE,

    reference: Ua.Reference.HASCOMPONENT,

    dataType: Ua.DataType.INT32,

    valueRank: Ua.ValueRank.SCALAR,

    value: 1

});


node = Ua.createNode("AGENT.OBJECTS.var1_ua.MirrorInput", {

    "browseName":"MirrorInput",

    "dataType":"i=12",

    "description":"MirrorInput",

    "displayName":"MirrorInput",

    "nodeClass":2,

    "parent":"AGENT.OBJECTS.var1_ua",

    "reference":"i=47",

    "typeDefinition":"VariableTypes.ATVISE.Mirror.Input",

    "value":"Prosys/ns=3;i=1001",

    "valueRank":-1

});


console.log(node.result);



2.3 Execute the script and test the results:




Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select atleast one of the reasons

Feedback sent

We appreciate your effort and will try to fix the article