Pular para o conteúdo principal

NodeCollection (Não há equivalente em C)

O C# oferece esse ua.Nodes["ns=2;s=Foo"] indexador de carregamento diferido, C SDK Não há equivalente — Em C, não há sobrecarga de operadores, nem são mantidos objetos de nós persistentes; tudo é feito diretamente sobre as strings NodeId API.

Leitura prévia

Comparação entre a sintaxe do C# e a do C​

String Leitura NodeId direta​

// 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);
/* Acabou */
DarraUa_DataValue_Delete(dv);

Indexador em cadeia (Server.ServerStatus.CurrentTime)​

// C# - 4 vezes Browse + 1 vez lida
using var dv = ua.Nodes.Server["ServerStatus"]["CurrentTime"].Value;

C. Recomendação: ResolveBrowsePath especifique o caminho de forma clara e completa (dividindo-o internamente em segmentos Browse, um por vez RPC), de modo que o chamador precise escrever apenas uma linha:

/* C - ResolveBrowsePath (N trechos do caminho = N vezes Browse RPC) + 1 leitura */
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 = sucesso, 0 = falha */
DarraUa_Status st = 0;
DarraUa_DataValue* dv = DarraUa_Session_ReadNode(
h, node_id, UA_ATTR_VALUE, &st);
DarraUa_DataValue_Delete(dv);
}

Ou, de forma mais direta — Server.ServerStatus.CurrentTime se for um nó padrão, use diretamente a macro:

DarraUa_DataValue* dv = DarraUa_Session_ReadNode(
h, "i=2258" /* CurrentTime */, UA_ATTR_VALUE, &st);

Implementar um cache simples (recomendado)​

Se, no trabalho NodeId, você costuma BrowsePath procurar por , crie seu próprio mapeamento NodeId de caminho → :

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. Verificar o 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. Após a análise, inserir no cache */
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 = sucesso, 0 = falha */
snprintf(e->path, sizeof(e->path), "%s", key);
g_cache_count++;
return e->node_id;
}

Quando usar os diversos métodos​

CenárioRecomendações
É sabido com precisão NodeIdSequência de caracteres DarraUa_Session_ReadNode
Nó padrão (estado do servidor, etc.)Usar WellKnownNodes Hong
Navegar pela árvore / Escrever um script de uso únicoDarraUa_Session_BrowseNode
Processar vários nós em loteDarraUa_Session_ReadNodes / _BrowseNodes, sem loop
Inicialização em lote de várias rotasDarraUa_Session_TranslateBrowsePaths

Próximo passo​