Skip to main content

OpcUaNode

OpcUaNode Yes NodeCollection The wrapper object returned by the indexer represents a remote node. Lazy Load — Only access properties trigger RPC.

Prerequisite Reading

Public Attributes​

CategoryPropertyTypeAccessDescription
Tags (None RPC)NodeIdstringRNode ID string
Data (Trigger RPC)ValueDataValueRCurrent value — triggers Read(Value)
DisplayNamestringRDisplay name text — triggers Read(DisplayName)
BrowseNamestringRView name — Triggers Read(BrowseName), returns a format `ns:Name` (e.g., `0:ServerStatus`)
DescriptionstringRDescription text — triggers a Read(Description) operation
NodeClassNodeClassRNode category — Triggers Read(NodeClass); if the read fails, `Unspecified`
DataTypeNodeIdstringRData type NodeId — triggers Read(DataType)
IsReadableboolRAccessLevel bit0; false AccessLevel when unreadable
IsWritableboolRAccessLevel bit1; false when AccessLevel not readable
Child Nodes (Triggered RPC)ChildrenIReadOnlyList<OpcUaReference>RList of child nodes — Trigger Browse

Indexer​

IndexReturnNote
node[browseName]OpcUaNodeSearch by NameDirect child nodes, triggered once Browse

Name Matching Rules: BrowseName == browseName or DisplayName == browseName, take the first match; Cannot find the return null (No exceptions are thrown). The matching usesBare Name —— node["ServerStatus"] Hit, node["0:ServerStatus"] Miss (different from the form ns:Name of BrowseName the attribute above).

Public Methods​

MethodsReturnNote
ReadAttribute(AttributeId attr)DataValueRead Specified Attribute (Value / DisplayName / ...)
Write(Variant v)StatusCodeWrite the Value property
WriteAttribute(AttributeId attr, Variant v)StatusCodeWrite a Specified Attribute
Resolve(string path)OpcUaNodeSearch along the path starting from this node (segment by segment Browse); Cannot find; returns null
Call(string parentObjectNodeId, params Variant[] inputs)IReadOnlyList<Variant>PutThis node When a method is called; parentObjectNodeId it is the object on which the method resides. NodeId

Call Equivalent to ua.Call(parentObjectNodeId, 本节点.NodeId, inputs), and the output parameters must also Variant be disposed of one by one.

Examples​

// 1. Get Node (None RPC)
var temp = ua.Nodes["ns=2;s=Temperature"];

// 2. Read the basic information (1 RPC each)
Console.WriteLine($"NodeId = {temp.NodeId}");
Console.WriteLine($"DisplayName = {temp.DisplayName}");
Console.WriteLine($"DataTypeNodeId= {temp.DataTypeNodeId}");
Console.WriteLine($"NodeClass = {temp.NodeClass}");

// 3. Read the value
using var dv = temp.Value;
Console.WriteLine($"Value = {dv.Value.AsDouble ?? double.NaN} °C @ {dv.SourceTimestamp}");
// AsDouble Is it a double?: Returns null if the value is not of type Double; passing it directly to a double parameter will result in a compilation error.

// 4. Write
using var v = new Variant();
v.Double = 25.5;

StatusCode st = temp.Write(v);

// 5. Browse Subnodes
foreach (var child in temp.Children)
Console.WriteLine($" {child.BrowseName} -> {child.NodeId}");

// 6. Chained Access (Server.ServerStatus.CurrentTime)
using var time = ua.Nodes.Server["ServerStatus"]["CurrentTime"].Value;
Console.WriteLine($"Server time = {time.Value.AsDateTime}");

Important Notes​

  • All properties RPC that are triggered are "read-once, return-once," Do not cache. I want to cache a variable I've stored myself
  • Chain-based access: One access a["b"]["c"] per segment Browse RPC, for a total of N accesses
  • DataValue You must call Dispose; otherwise, a memory leak will occur.
  • IsReadable / IsWritable Not a permission check: They read the node's AccessLevel bit, not the current user's UserAccessLevel. If you see IsWritable == true and write to it, the server can still return BadUserAccessDenied — you must handle the status code before writing; you cannot treat these two attributes as proof that "I have permission."

Comparison with Resolve​

// Method A: Chain Indexer — 3 times RPC
using var ta = ua.Nodes.Server["ServerStatus"]["CurrentTime"].Value;
// ^Nodes.Server Do not post RPC
// ^1st Browse ^2nd Browse ^3rd Read

// Method B: Path Resolution — 5 times RPC (1 time for each of the 4 segments Browse + 1 Read)
var nb = ua.Resolve("/Objects/Server/ServerStatus/CurrentTime"); // 4 times Browse, one paragraph at a time
if (nb != null) // Cannot find; returns null
{
using var tb = nb.Value; // 1 view
Console.WriteLine($"server time = {tb.Value.AsDateTime}");
}

// Method C: Directly NodeId — 1 time RPC
using var tc = ua.Read("i=2258");

Known path → Method C (done in 1 call); Exploratory development → Method A; Don't use Method B just to "save a few lines." —— Resolve It's priced by section Browse; the deeper it goes, the more expensive it is.

Next Step​