NodeCollection (No equivalent in C)
C# provides this ua.Nodes["ns=2;s=Foo"] kind of lazy-load indexer, C SDK No equivalent — C does not support operator overloading and does not maintain persistent node objects; everything is done by directly calling methods on NodeId strings API.
Prerequisite Reading
- For single-node browsing, please see Browse.
- For alternatives to chained access, see TranslateBrowsePaths.
C# Syntax → C Syntax Comparison
String NodeId Direct Read
// C#
using var dv = ua.Nodes["ns=2;s=Temperature"].Value;
/* C */
DarraUa_Status st = 0;
DarraUa_DataValue* dv = DarraUa_Session_ReadNode(
h, "ns=2;s=Temperature", UA_ATTR_VALUE, &st);
/* Used up */
DarraUa_DataValue_Delete(dv);
Chain Indexer (Server.ServerStatus.CurrentTime)
// C# - 4 times Browse + 1 time Read
using var dv = ua.Nodes.Server["ServerStatus"]["CurrentTime"].Value;
C Recommended approach: Use ResolveBrowsePath to specify the entire path clearly in one go (breaking it down internally into path segments Browse, one segment at a time RPC), so that the caller only needs to write one line:
/* C - ResolveBrowsePath (N segments of the path = N times Browse RPC) + 1 Read */
char node_id[128];
int32_t n = DarraUa_Session_ResolveBrowsePath(
h, "i=2253" /* Server */,
"/ServerStatus/CurrentTime",
node_id, (int32_t)sizeof(node_id));
if (n == 1) { /* 1 = Success, 0 = Failure */
DarraUa_Status st = 0;
DarraUa_DataValue* dv = DarraUa_Session_ReadNode(
h, node_id, UA_ATTR_VALUE, &st);
DarraUa_DataValue_Delete(dv);
}
Or, more simply—if it's Server.ServerStatus.CurrentTime a standard node, just use the macro:
DarraUa_DataValue* dv = DarraUa_Session_ReadNode(
h, "i=2258" /* CurrentTime */, UA_ATTR_VALUE, &st);
Implementing a Simple Cache (Recommended)
If you frequently search BrowsePath by in your business logic NodeId, write your own path → NodeId map:
typedef struct {
char path[256];
char node_id[128];
} PathCacheEntry;
static PathCacheEntry g_cache[1024];
static int g_cache_count = 0;
static const char* resolve_cached(DarraUa_SessionHandle h,
const char* start, const char* path)
{
/* 1. Check the cache */
char key[256];
snprintf(key, sizeof(key), "%s|%s", start, path);
for (int i = 0; i < g_cache_count; ++i) {
if (strcmp(g_cache[i].path, key) == 0)
return g_cache[i].node_id;
}
/* 2. Caching after parsing */
if (g_cache_count >= 1024) return NULL;
PathCacheEntry* e = &g_cache[g_cache_count];
int32_t n = DarraUa_Session_ResolveBrowsePath(
h, start, path, e->node_id, (int32_t)sizeof(e->node_id));
if (n != 1) return NULL; /* 1 = Success, 0 = Failure */
snprintf(e->path, sizeof(e->path), "%s", key);
g_cache_count++;
return e->node_id;
}
When to Use Various Methods
| Scenario | Recommendations |
|---|---|
| Known with precision NodeId | String DarraUa_Session_ReadNode |
| Standard Nodes (Server Status, etc.) | Use WellKnownNodes Hong |
| Browse Tree / Write a One-Time Script | DarraUa_Session_BrowseNode |
| Batch Process Multiple Nodes | DarraUa_Session_ReadNodes / _BrowseNodes, do not loop |
| Batch Initialization of Multiple Paths | DarraUa_Session_TranslateBrowsePaths |