Max Ivanov
Max Ivanov

Reputation: 6561

Reading the entire tree from the OPC UA server

OPC UA newbie here!

I want to programmatically read a tree of nodes available on the OPC Server to present the tree to the user. The user would then pick the node they're interested in and the app will fetch the value of that node.

The client I'm going to use is node-opcua.

My initial idea is to use the session.browse() method to recursively read out all of the nodes, starting from the root:

...

const connectionStrategy = {
  initialDelay: 1000,
  maxRetry: 1,
}

const client = OPCUAClient.create({
  applicationName: "MyClient",
  connectionStrategy: connectionStrategy,
  securityMode: MessageSecurityMode.None,
  securityPolicy: SecurityPolicy.None,
  endpoint_must_exist: false,
})

const endpointUrl = "opc.tcp://opcuaserver.com:48010"

async function main() {
  await client.connect(endpointUrl)

  const session = await client.createSession()

  const browseResult = await session.browse("RootFolder") // start with root
  for (const reference of browseResult.references) {
    // recursively session.browse() nodeId of reference
  }

  await session.close();
  await client.disconnect();
}

Does the approach of recursive fetching the tree sound viable? I imagine trees can get large. Is there any better approach?

Upvotes: 0

Views: 2325

Answers (1)

from56
from56

Reputation: 4127

What you propose is as if when you open the windows explorer you had to wait several minutes for it to load the complete tree of directories and files.

The node tree of an OPC UA server can have several thousand nodes, most of them without interest for those who are looking for a variable or a specific group of variables to monitor.

The whole tree will probably take several minutes to load and the opinion that this will cause in the user of your program will not be good.

Child nodes should only be obtained and displayed when the user clicks on them, like the windows explorer.

Maybe you should start by designing the graphical interface first

Upvotes: 1

Related Questions