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).
- Single node API Please see OpcUaNode.
- For standard node constants, see WellKnownNodes.
Input Methods
| Methods | Return | Note |
|---|---|---|
| nodes.get(String nodeId) | OpcUaNode | String NodeId Access (corresponding to the C# Nodes[nodeId] indexer) |
| nodes.makeNumeric(String nsUri, long id) | OpcUaNode | Press ns URI + Numeric Id Construct (internal implementation uses namespaces.indexOf) |
| nodes.makeString(String nsUri, String id) | OpcUaNode | Construct using ns URI + String Id |
Predefined Entry Methods (Standard Nodes)
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 (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:
- Use
browse(currentNodeId)to get the list of child nodes immediately - Find the child of (
BrowseName == "ChildName"or DisplayName), and return the wrapperOpcUaNode - 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.
By Structure NamespaceUri ( NodeId Recommended)
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()) {
// ...
}
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
| Scenario | Recommendations |
|---|---|
| Known with precision NodeId | String (ua.read("ns=2;s=...")) |
| Standard Nodes (Server Status, etc.) | nodes.server().get(...) |
| Browse Tree / Write a One-Time Script | Indexer (nodes.get("...").get("...")) |
| Cross-Server Porting NamespaceUri | nodes.makeString(uri, id) |
| Batch (100+ nodes) | readMany / browseMany, Do not loop |