Skip to main content

NodeCollection — ua.Nodes

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

Prerequisite Reading

Indexer​

IndexReturnNote
Nodes[string nodeId]OpcUaNodeString NodeId Access

Predefined Entry Properties​

For your convenience, here are some commonly used shortcuts:

CategoryPropertyTypeAccessDescription
Standard EntryRootOpcUaNodeRAddress Space Root (i=84)
ObjectsOpcUaNodeRBusiness Data Root (i=85)
TypesOpcUaNodeRType definition root (i=86)
ViewsOpcUaNodeRView root (i=87)
ServerOpcUaNodeRServer object itself (i=2253)
// These two lines are equivalent.
using var t1 = ua.Nodes.Server["ServerStatus"]["CurrentTime"].Value;
using var t2 = ua.Nodes["i=2253"]["ServerStatus"]["CurrentTime"].Value;

Lazy Load Mechanism​

var node = ua.Nodes["ns=2;s=Temperature"];  // ← Do not trigger RPC
using var dv = node.Value; // ← The first time .Value is called, Read is triggered

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​

var sub = node["ChildName"];   // Find Direct Child Nodes by Name
if (sub == null) { /* Couldn't find it */ }

Search Rules:

  1. Use Browse(当前节点) to get the list of child nodes immediately (once RPC)
  2. Find the first one sequentially BrowseName == "ChildName"orDisplayName == "ChildName" the child, return that OpcUaNode
  3. Not found returns null — No exceptions are thrown; the caller must check for null.
Name matching uses the raw name.

The here is BrowseNameBare Name (no prefix ns ), and OpcUaNode.BrowseName Format ns:Name in which properties are returnedDifferent: node["ServerStatus"] May match, node["0:ServerStatus"] may not match. When child nodes with the same name exist across namespaces, only the first one is selected.

Each index level requires one operation Browse; a linked list a["b"]["c"]["d"] requires 3 operations ( Browse without a cache), plus reading the value at the end.

Construct URI by namespace NodeId​

If a node is in a namespace but you only have URI and not the index, use MakeNumeric / MakeString:

var n1 = ua.Nodes.MakeNumeric("http://opcfoundation.org/UA/DI/", 1001);  // "ns=<index>;i=1001"
var n2 = ua.Nodes.MakeString("urn:myserver", "Boiler1"); // "ns=<index>;s=Boiler1"
MethodsNote
MakeNumeric(namespaceUri, uint identifier)Numeric type NodeId: if index=0 then i=1001; otherwise ns=N;i=1001
MakeString(namespaceUri, string identifier)String type NodeId: index=0 s=Foo, otherwise ns=N;s=Foo

Check both first Namespaces Get index: If not URI found, throw an exception OpcUaException (DarraInvalidArgument), No Returns null. The namespace table is automatically loaded when Connect(); to load a new namespace dynamically, you must first ua.Namespaces.Reload().

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

ScenarioRecommendations
Known with precision NodeIdString (ua.Read("ns=2;s=..."))
Standard Nodes (Server Status, etc.)Nodes.Server[...]
Browse Tree / Write a One-Time ScriptIndexer (Nodes["..."]["..."])
A group of nodes needs to be operated on togetherReadMany / BrowseMany, Do not loop

Next Step​