Skip to main content

NodeCollection — ua.nodes

NodeCollection This is the entry point for accessing Session nodes; it returns get(String nodeId) OpcUaNode Items to be packaged, Not triggered immediately RPC (Lazy Load).

Prerequisite Reading

Input Methods​

MethodsReturnNote
nodes.get(String nodeId)OpcUaNodeString NodeId Access (corresponding to the C# Nodes[nodeId] indexer)
nodes.makeNumeric(String nsUri, long id)OpcUaNodePress ns URI + Numeric Id Construct (internal implementation uses namespaces.indexOf)
nodes.makeString(String nsUri, String id)OpcUaNodeConstruct using ns URI + String Id

Predefined Entry Methods (Standard Nodes)​

For your convenience, here are some commonly used shortcuts:

CategoryPropertyTypeAccessDescription
Standard Entryroot()OpcUaNodeRAddress Space Root (i=84)
objects()OpcUaNodeRBusiness Data Root (i=85)
types()OpcUaNodeRType definition root (i=86)
views()OpcUaNodeRView root (i=87)
server()OpcUaNodeRServer object (i=2253)
// These two lines are equivalent.
try (OpcUaDataValue t1 = ua.nodes.server().get("ServerStatus").get("CurrentTime").getValue()) {
// ...
}
try (OpcUaDataValue t2 = ua.nodes.get("i=2253").get("ServerStatus").get("CurrentTime").getValue()) {
// ...
}

Lazy Load Mechanism​

OpcUaNode node = ua.nodes.get("ns=2;s=Temperature");  // ← Do not trigger RPC
try (OpcUaDataValue dv = node.getValue()) { // ← First time .getValue() Just triggered Read
// ...
}

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

Child Node BrowseName Index​

OpcUaNode sub = node.get("ChildName");  // Browse BrowseName child nodes

Underlying Logic:

  1. Use browse(currentNodeId) to get the list of child nodes immediately
  2. Find the child of ( BrowseName == "ChildName" or DisplayName), and return the wrapper OpcUaNode
  3. Cannot find return null (Java style, no exceptions thrown)

The first request incurs a one-time RPC overhead (the time taken varies depending on the network and server; test it in your own environment), while subsequent path requests all return results Browse in a single call.

NamespaceIndex Unstable; use the production code NamespaceUri:

// The server-side index ns may be 2, 3, or 5; it is unstable—use a reverse lookup URI .
OpcUaNode temp = ua.nodes.makeString("urn:my-company:plc1", "Temperature");
try (OpcUaDataValue dv = temp.getValue()) {
// ...
}
The namespace must exist

makeNumeric / makeString; if it does not URI, an exception is thrown OpcUaException(DarraInvalidArgument). Ensure thatNamespaceArray it has been successfully ua.connect() loaded before calling this function.

When to Use the Input Method, and When to Use a String​

ScenarioRecommendations
Known with precision NodeIdString (ua.read("ns=2;s=..."))
Standard Nodes (Server Status, etc.)nodes.server().get(...)
Browse Tree / Write a One-Time ScriptIndexer (nodes.get("...").get("..."))
Cross-Server Porting NamespaceUrinodes.makeString(uri, id)
Batch (100+ nodes)readMany / browseMany, Do not loop

Next Step​