WellKnownNodes (C)
C SDK 在 opcua_node_id.h 提供 UA_WELL_* 宏 (值是 ns=0 的 NodeId 字符串字面量), 用宏代替手写字符串提升可读性。SDK 未覆盖的其它标准节点, 直接写字面量即可。
配套
- 命名空间反查见 Namespaces.
- 通过 NodeId 读取数据见 Read / Write.
SDK 提供的 UA_WELL_* 宏
/* opcua_node_id.h — 标准 OPC UA 节点 (ns=0) */
/* 根 */
#define UA_WELL_ROOT_FOLDER "i=84"
#define UA_WELL_OBJECTS_FOLDER "i=85"
#define UA_WELL_TYPES_FOLDER "i=86"
#define UA_WELL_VIEWS_FOLDER "i=87"
/* Server 自身 */
#define UA_WELL_SERVER "i=2253"
#define UA_WELL_SERVER_STATUS "i=2256"
/* ServerStatus 结构 */
#define UA_WELL_CURRENT_TIME "i=2258"
#define UA_WELL_SERVER_STATE "i=2259"
/* 标准 ReferenceType */
#define UA_WELL_REFERENCES "i=31"
#define UA_WELL_HIERARCHICAL_REFERENCES "i=33"
#define UA_WELL_ORGANIZES "i=35"
#define UA_WELL_HAS_TYPE_DEFINITION "i=40"
#define UA_WELL_HAS_PROPERTY "i=46"
#define UA_WELL_HAS_COMPONENT "i=47"
用法对比
/* 不推荐: 硬编码 */
DarraUa_DataValue* dv = DarraUa_Session_ReadNode(
h, "i=2258", UA_ATTR_VALUE, &st);
/* 推荐: 用宏 */
#include <opcua_node_id.h>
DarraUa_DataValue* dv = DarraUa_Session_ReadNode(
h, UA_WELL_CURRENT_TIME, UA_ATTR_VALUE, &st);
ServerStatus 完整读取示例
const char* nodes[] = {
UA_WELL_SERVER_STATE,
UA_WELL_CURRENT_TIME,
UA_WELL_SERVER_STATUS,
UA_WELL_SERVER,
};
DarraUa_DataValue* dvs[4] = { NULL };
DarraUa_Session_ReadNodes(h, nodes, NULL, 4, dvs);
for (int i = 0; i < 4; ++i) {
if (!dvs[i]) continue;
const DarraUa_Variant* v = DarraUa_DataValue_GetValue(dvs[i]);
printf("%-30s -> ", nodes[i]);
/* 按类型格式化 (略, 详见 Variant 章节) */
DarraUa_DataValue_Delete(dvs[i]);
}
完整列表
带 UA_WELL_* 的行是 SDK 提供的宏; 其余是 OPC UA 标准 NodeId, SDK 未给宏, 直接写字符串字面量。
| 节点 | NodeId | 含义 |
|---|---|---|
| Root | i=84 | UA_WELL_ROOT_FOLDER · Address Space 根 |
| Objects | i=85 | UA_WELL_OBJECTS_FOLDER · 业务数据根 |
| Types | i=86 | UA_WELL_TYPES_FOLDER · 类型定义根 |
| Views | i=87 | UA_WELL_VIEWS_FOLDER · 视图根 |
| Server | i=2253 | UA_WELL_SERVER · Server 自身对象 |
| ServerStatus | i=2256 | UA_WELL_SERVER_STATUS · Server 状态结构 |
| ServerStatus.State | i=2259 | UA_WELL_SERVER_STATE · 状态 (Running / Failed / ...) |
| ServerStatus.CurrentTime | i=2258 | UA_WELL_CURRENT_TIME · 服务端当前时间 |
| References | i=31 | UA_WELL_REFERENCES · ReferenceType 根 |
| HierarchicalReferences | i=33 | UA_WELL_HIERARCHICAL_REFERENCES · 层次引用根 |
| Organizes | i=35 | UA_WELL_ORGANIZES · ReferenceType |
| HasTypeDefinition | i=40 | UA_WELL_HAS_TYPE_DEFINITION · ReferenceType |
| HasProperty | i=46 | UA_WELL_HAS_PROPERTY · ReferenceType |
| HasComponent | i=47 | UA_WELL_HAS_COMPONENT · ReferenceType |
| ServerStatus.StartTime | i=2257 | SDK 无宏 · 服务端启动时间 |
| ServerStatus.BuildInfo | i=2260 | SDK 无宏 · 厂商 / 产品 / 版本 |
| ServerArray | i=2254 | SDK 无宏 · 服务端数组 |
| NamespaceArray | i=2255 | SDK 无宏 · 命名空间数组 |
| HasSubtype | i=45 | SDK 未收录常量 · ReferenceType (手写 "i=45") |
完整 OPC UA 标准 NodeId 详见 OPC UA Part 6 附录与 OPC Foundation 提供的 Opc.Ua.NodeIds.csv 表 (跨语言通用).