TranslateBrowsePaths (C)
TranslateBrowsePathsToNodeIds Service: Take as input a starting node and an array of relative paths (e.g., "/2:Boilers/1:Drum/Level"), and output a string NodeId containing the resolved path for each path. Perform batch RPC resolution; the client Browse then iterates through each path once RPC.
- For chained exploration, we recommend using Browse Single-level browsing.
- This file is required for batch initialization of multiple paths API.
API
OPCUA_API DarraUa_Status OPCUA_CALL DarraUa_Session_TranslateBrowsePaths(
DarraUa_SessionHandle h,
const char* const* starting_node_ids,
const char* const* browse_paths,
uint32_t count,
char*** out_node_ids, /* Exit */
DarraUa_Status* out_status_per_path); /* Output parameter: The caller allocates count */
| Parameters | Note |
|---|---|
| starting_node_ids | Starting point of each path: an array of strings NodeId (length = count) |
| browse_paths | Array of paths, separated by / (length = count) |
| count | Number of paths |
| out_node_ids | Output parameter: char** An array whose elements are the parsed strings NodeId (NULL = failure) |
| out_status_per_path | Output: Per item StatusCode |
Release
out_node_ids The array and each non-NULL string are allocated by Stack malloc:
if (node_ids) {
for (uint32_t i = 0; i < count; ++i) {
if (node_ids[i]) DarraUa_Free(node_ids[i]);
}
DarraUa_Free(node_ids);
}
Path Segment Syntax
| Segment Format | Meaning |
|---|---|
| BrowseName | namespace 0 |
| 2:BrowseName | namespace 2 |
| /A/B/C | The starting point is not included; it starts directly at / |
Example:
| BrowsePath | Meaning |
|---|---|
| /Server | ns=0 Child node Server |
| /2:Boiler1 | ns=2 Child node Boiler1 |
| /Server/2:Boilers/2:Boiler1/2:Temperature | Multi-layer Combination |
/2:Boilers/1:Drum/Level This indicates that, starting from the origin, the path goes first to ns=2;Boilers, then to ns=1;Drum, and then to Level (ns=0).
Press the fixed button once for each segment HierarchicalReferences (i=33) Includes all subtypes, forward When performing type matching, you cannot specify the reference type yourself.
Complete Example
#include <opcua/opcua.h>
#include <stdio.h>
int main(int argc, char** argv)
{
const char* endpoint = (argc >= 2) ? argv[1] : "opc.tcp://localhost:4840";
DarraUa_Initialize();
DarraUa_SessionConfig cfg;
DarraUa_SessionConfig_Init(&cfg);
cfg.endpoint_url = endpoint;
cfg.security_policy_uri = "http://opcfoundation.org/UA/SecurityPolicy#None";
DarraUa_SessionHandle h = UA_INVALID_SESSION_HANDLE;
DarraUa_Session_Create(&cfg, &h);
DarraUa_Session_Connect(h);
/* 4 paths */
const char* starts[] = {
"i=85", "i=85", "ns=2;s=Boiler1", "ns=2;s=Boiler1",
};
const char* paths[] = {
"/Server/ServerStatus/CurrentTime",
"/Server/ServerStatus/State",
"/Temperature",
"/Pressure",
};
uint32_t count = 4;
char** node_ids = NULL;
DarraUa_Status results[4] = { 0 };
DarraUa_Status st = DarraUa_Session_TranslateBrowsePaths(
h, starts, paths, count, &node_ids, results);
if (!UA_STATUS_IS_GOOD(st)) {
fprintf(stderr, "TranslateBrowsePaths failed: 0x%08X (%s)\n",
(unsigned)st, DarraUa_StatusName(st));
} else {
for (uint32_t i = 0; i < count; ++i) {
printf("[%u] %-50s -> ", i, paths[i]);
if (UA_STATUS_IS_GOOD(results[i]) && node_ids && node_ids[i])
printf("%s\n", node_ids[i]);
else
printf("FAILED (%s)\n", DarraUa_StatusName(results[i]));
}
}
/* Release */
if (node_ids) {
for (uint32_t i = 0; i < count; ++i) {
if (node_ids[i]) DarraUa_Free(node_ids[i]);
}
DarraUa_Free(node_ids);
}
DarraUa_Session_Disconnect(h);
DarraUa_Session_Close(h);
DarraUa_Shutdown();
return 0;
}
Comparison with ResolveBrowsePath
| Function | Implementation Methods | Performance | Uses |
|---|---|---|---|
| DarraUa_Session_TranslateBrowsePaths | Server-Native (OPC UA Service) | Single RPC, Bulk | Production |
| DarraUa_Session_ResolveBrowsePath | Client-Side Loop Browse Crawling | N times RPC, single row | TranslateBrowsePaths When the server does not support it, or when there is only one |
ResolveBrowsePath:
OPCUA_API int32_t OPCUA_CALL DarraUa_Session_ResolveBrowsePath(
DarraUa_SessionHandle h,
const char* start_node_id,
const char* path,
char* out_node_id,
int32_t out_buf_size);
| Parameters | Note |
|---|---|
| out_node_id | Buffer provided by the caller |
| out_buf_size | Number of buffer bytes |
Return value: 1 = Success (NodeId string written out_node_id), 0 = Failure (including insufficient buffer or path not found). Not the string length.
char buf[128];
int32_t n = DarraUa_Session_ResolveBrowsePath(
h, "i=85",
"/Server/ServerStatus/CurrentTime",
buf, (int32_t)sizeof(buf));
if (n == 1) printf("Resolved -> %s\n", buf);
Error codes (per path)
out_status_per_path[i] It is initially set to UA_STATUS_BAD_NODE_ID_INVALID, and after receiving a response from the server, it is overwritten StatusCode by the path's own value.
| StatusCode | Meaning |
|---|---|
| Good | Parsing Successful |
| BadNodeIdUnknown | Starting Point NodeId Does Not Exist (UA_STATUS_BAD_NODE_ID_UNKNOWN) |
| BadNodeIdInvalid | Start NodeId String parsing failed, or this path segment did not match (UA_STATUS_BAD_NODE_ID_INVALID) |
Any other status codes returned by the server for each path are passed through as-is. Note: SDK Only common codes are included; codes not included in the scope DarraUa_StatusName will return "Unknown". Please print the raw value directly using 0x%08X.
Best Practices
- When the service starts, translate all required "configuration paths" into the cache NodeId in one go; subsequently, simply read from and write NodeId to the cache.
- Don't re-translate every time you read or write—it's a waste. RPC
- If the list of paths is large, submit it in batches to prevent the server from rejecting it (
BadTooManyOperations(0x80100000=UA_STATUS_BAD_TOO_MANY_OPERATIONS)