Skip to main content

NodeCollection — s.Nodes()

darra::opcua::NodeCollection This is the entry point for accessing Session nodes, returned via the indexer. Node Items to be packaged, Not triggered immediately RPC (Lazy Load).

Prerequisite Reading

Indexer​

IndexReturnNote
Nodes()[std::string const& node_id]NodeString NodeId Access

Predefined Entry Methods​

For your convenience, here are some commonly used shortcuts:

CategoryPropertyTypeAccessDescription
Standard EntryRoot()NodeRAddress Space Root (i=84)
Objects()NodeRBusiness Data Root (i=85)
Types()NodeRRoot of type definitions (i=86)
Views()NodeRView root (i=87)
Server()NodeRServer object (i=2253)
// These two lines are equivalent.
auto t1 = s.Nodes().Server()["ServerStatus"]["CurrentTime"].Value();
auto t2 = s.Nodes()["i=2253"]["ServerStatus"]["CurrentTime"].Value();

Lazy Load Mechanism​

auto node = s.Nodes()["ns=2;s=Temperature"];  // ← Do not trigger RPC
auto dv = node.Value(); // ← The first call to .Value() triggers a Read

On the second access, it will still .Value() re-read (without caching) because the variable value can change at any time. I want to cache the variable myself.

Child Node BrowseName Index​

auto sub = node["ChildName"];   // Browse BrowseName child nodes

The process of selecting nodes:

  1. Use Browse(currentNodeId) to get the list of child nodes immediately (1 time Browse RPC)
  2. Find the child that BrowseName is or DisplayName "ChildName" equal to, and return the wrapper Node
  3. Cannot find a return value that is null NodeId Node; a exception will .Value() be thrown later. Exception

Each operator[] is a Browse; there is no cache: a["b"]["c"]["d"] is 3 Browses, not 1. The deeper the chain, the more RPCs; to save RPCs, switch to TranslateBrowsePaths or get the NodeId directly.

When to Use an Indexer, When to Use a String​

ScenarioRecommendations
Known with precision NodeIdString (s.Read("ns=2;s=..."))
Standard Nodes (Server Status, etc.)Nodes().Server()[...]
Browse Tree / Write a One-Time ScriptIndexer (Nodes()["..."]["..."])
Batch (100+ nodes)ReadMany / BrowseMany, Do not loop

Next Step​