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).
- Single node API Please see OpcUaNode.
- For standard node constants, see WellKnownNodes.
Indexer
| Index | Return | Note |
|---|---|---|
| Nodes[string nodeId] | OpcUaNode | String NodeId Access |
Predefined Entry Properties
For your convenience, here are some commonly used shortcuts:
| Category | Property | Type | Access | Description |
|---|---|---|---|---|
| Standard Entry | Root | OpcUaNode | R | Address Space Root (i=84) |
Objects | OpcUaNode | R | Business Data Root (i=85) | |
Types | OpcUaNode | R | Type definition root (i=86) | |
Views | OpcUaNode | R | View root (i=87) | |
Server | OpcUaNode | R | Server 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:
- Use
Browse(当前节点)to get the list of child nodes immediately (once RPC) - Find the first one sequentially
BrowseName == "ChildName"orDisplayName == "ChildName"the child, return thatOpcUaNode - Not found returns
null— No exceptions are thrown; the caller must check for null.
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"
| Methods | Note |
|---|---|
| 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
| Scenario | Recommendations |
|---|---|
| Known with precision NodeId | String (ua.Read("ns=2;s=...")) |
| Standard Nodes (Server Status, etc.) | Nodes.Server[...] |
| Browse Tree / Write a One-Time Script | Indexer (Nodes["..."]["..."]) |
| A group of nodes needs to be operated on together | ReadMany / BrowseMany, Do not loop |