WellKnownNodes
darra::opcua::WellKnownNodes This is a set of constants inline constexpr const char* under the namespace—strings NodeId representing predefined standard OPC Foundation nodes. Using these instead of writing them out manually "i=2258" improves code readability and helps avoid typos.
- See Namespace Reverse Lookup Namespaces.
- To NodeId read the data, see Read / Write.
Header Files
#include <darra/opcua/well_known_nodes.hpp>
using namespace darra::opcua;
Common Root Nodes
| Constants | NodeId | Meaning |
|---|---|---|
| WellKnownNodes::RootFolder | "i=84" | Address Space Root |
| WellKnownNodes::ObjectsFolder | "i=85" | Business Data Root |
| WellKnownNodes::TypesFolder | "i=86" | Type Definition Root |
| WellKnownNodes::ViewsFolder | "i=87" | View Root |
| WellKnownNodes::ObjectTypesFolder | "i=88" | ObjectType Root |
| WellKnownNodes::VariableTypesFolder | "i=89" | VariableType Root |
| WellKnownNodes::DataTypesFolder | "i=90" | DataType Root |
| WellKnownNodes::ReferenceTypesFolder | "i=91" | ReferenceType Root |
| WellKnownNodes::Server | "i=2253" | The Server Object Itself |
Server Status
| Constants | NodeId | Meaning |
|---|---|---|
| Server_ServerArray | "i=2254" | ServerArray (String array) |
| Server_NamespaceArray | "i=2255" | NamespaceArray (String array) |
| Server_ServerStatus | "i=2256" | Server Status Structure |
| Server_ServerStatus_StartTime | "i=2257" | Server startup time (DateTime) |
| Server_ServerStatus_CurrentTime | "i=2258" | Current server time (DateTime) |
| Server_ServerStatus_State | "i=2259" | ServerState (Enumeration, Int32) |
| Server_ServerStatus_BuildInfo | "i=2260" | BuildInfo Structure |
| Server_ServerStatus_BuildInfo_ProductName | "i=2261" | Product Name |
| Server_ServerStatus_BuildInfo_ProductUri | "i=2262" | Products URI |
| Server_ServerStatus_BuildInfo_ManufacturerName | "i=2263" | Manufacturer Name |
| Server_ServerStatus_BuildInfo_SoftwareVersion | "i=2264" | Software Version |
| Server_ServerStatus_BuildInfo_BuildNumber | "i=2265" | Build Number |
| Server_ServerStatus_BuildInfo_BuildDate | "i=2266" | Creation Date (DateTime) |
| Server_ServerStatus_SecondsTillShutdown | "i=2992" | Seconds until closure |
| Server_ServerStatus_ShutdownReason | "i=2993" | Reason for Closure |
Standards ReferenceType
| Constants | NodeId |
|---|---|
| References | "i=31" |
| NonHierarchicalReferences | "i=32" |
| HierarchicalReferences | "i=33" |
| HasChild | "i=34" |
| Organizes | "i=35" |
| HasEventSource | "i=36" |
| HasModellingRule | "i=37" |
| HasEncoding | "i=38" |
| HasDescription | "i=39" |
| HasTypeDefinition | "i=40" |
| HasProperty | "i=46" |
| HasComponent | "i=47" |
There is no HasSubtype constant in well_known_nodes.hpp (none in the SDK constant tables of any language either). To use one, write the string "i=45" by hand.
Usage
#include <darra/opcua/client.hpp>
#include <darra/opcua/well_known_nodes.hpp>
#include <iostream>
#include <string>
#include <vector>
using namespace darra::opcua;
Stack::Init();
Session s("opc.tcp://localhost:4840");
s.Connect();
// Not recommended: Hard-coding
DataValue dv1 = s.Read("i=2258");
// Recommendation: Use a constant (a constant is `const char*`; it Session::Read directly holds a `std::string`)
DataValue dv2 = s.Read(WellKnownNodes::Server_ServerStatus_CurrentTime);
std::cout << dv2.Value().AsFileTime() << "\n"; // DateTime For nodes AsFileTime()
Using the indexer s.Nodes() (return Node, then call get Node::Value() DataValue):
// Continuing from the previous text: Session s is connected
DataValue t1 = s.Nodes()[WellKnownNodes::Server_ServerStatus_CurrentTime].Value();
// or
DataValue t2 = s.Nodes().Server().Value(); // NodeCollection::Server() It's a method
ServerStatus Read in Full
// Continuing from the previous text: Session s is connected
std::vector<std::string> ids = {
WellKnownNodes::Server_ServerStatus_State,
WellKnownNodes::Server_ServerStatus_CurrentTime,
WellKnownNodes::Server_ServerStatus_StartTime,
};
std::vector<DataValue> dvs = s.ReadMany(ids); // Throw an Exception if the entire batch fails
for (size_t i = 0; i < ids.size(); ++i) {
if (!dvs[i].IsGood()) continue; // Self-Check for Single-Point Failures
std::cout << ids[i] << " = " << dvs[i].Value().AsFileTime() << "\n";
}
Select the accessor based on the node type when retrieving values (Variant only expose scalar values):
| Node | OPC UA Type | Accessor |
|---|---|---|
| Server_ServerStatus_CurrentTime / StartTime / BuildDate | DateTime | Value().AsFileTime() → int64_t FileTime |
| Server_ServerStatus_State | Int32 (Enumeration) | Value().TryGetInt32(v) |
| Server_ServerStatus_BuildInfo_ProductName, etc. | String | Value().AsString() |
| Server_NamespaceArray / Server_ServerArray | String[] | No choice but to make a decision Value().IsArray(); if the element is leaving, Value().Handle() take the C handle. |
Complete List
darra/opcua/well_known_nodes.hpp has a total of 55 inline constexpr const char* constants: 8 Folders + 16 Servers (status / BuildInfo / off) + 12 ReferenceTypes + 19 commonly used DataTypes, all nodes in the standard OPC Foundation namespace (ns=0). The same header also has WellKnownNamespaces (OpcFoundation = http://opcfoundation.org/UA/ / DI = http://opcfoundation.org/UA/DI/).
Another equivalent package: node_id.hpp provides NodeId::Well static methods NodeId const& that return (Well::RootFolder()/ Well::ServerStatus() / Well::CurrentTime(), etc.—14 in total). Use it NodeId if you want strong typing; use the method on this page if you want string constants WellKnownNodes.