NodeCollection (C에는 이에 상응하는 항목이 없음)
C#은 이러한 ua.Nodes["ns=2;s=Foo"] Lazy Load 인덱서를 제공하며, C SDK 상응하는 대상이 없음 — C 언어에는 연산자 오버로딩이 없으며, 영구 노드 객체도 유지하지 않습니다. 모든 작업은 문자열에 직접 메서드를 NodeId 호출하는 방식으로 이루어집니다 API.
사전 읽기
- 단일 노드 보기를 보시려면 여기를 클릭하세요 Browse.
- 체인 방식 호출의 대안은 다음을 참조하십시오. TranslateBrowsePaths.
C# 작성법 → C 작성법 대조표
문자열 NodeId 직접 읽기
// 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);
/* 다 쓰고 나면 */
DarraUa_DataValue_Delete(dv);
체인 인덱서 (서버ServerStatus.CurrentTime)
// C# - 4회 Browse + 1회 조회
using var dv = ua.Nodes.Server["ServerStatus"]["CurrentTime"].Value;
C. 권장 방식: 를 사용하여 ResolveBrowsePath 경로를 한 번에 명확히 명시하고(내부적으로는 경로 구간별로 계층을 나누어 Browse, 한 구간씩 처리 RPC), 호출 측에서는 한 줄만 작성합니다:
/* C - ResolveBrowsePath (N 구간 = N회 Browse RPC) + 1회의 읽기 */
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 = 성공, 0 = 실패 */
DarraUa_Status st = 0;
DarraUa_DataValue* dv = DarraUa_Session_ReadNode(
h, node_id, UA_ATTR_VALUE, &st);
DarraUa_DataValue_Delete(dv);
}
또는 더 직접적인 방법 — 표준 노드인 Server.ServerStatus.CurrentTime 경우, 매크로를 직접 사용합니다:
DarraUa_DataValue* dv = DarraUa_Session_ReadNode(
h, "i=2258" /* CurrentTime */, UA_ATTR_VALUE, &st);
간단한 캐시 구현하기 (권장)
업무상 자주 를 기준으로 BrowsePath 검색해야 한다면 NodeId, 직접 path → NodeId 맵을 작성하세요:
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. 캐시 확인 */
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. 파싱 후 캐시에 저장 */
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 = 성공, 0 = 실패 */
snprintf(e->path, sizeof(e->path), "%s", key);
g_cache_count++;
return e->node_id;
}
언제 어떤 방식으로
| 시나리오 | 추천 |
|---|---|
| 정확히 알려져 있다 NodeId | 문자열 DarraUa_Session_ReadNode |
| 표준 노드 (서버 상태 등) | ~를 사용하여 WellKnownNodes 홍 |
| 트리 탐색 / 일회용 스크립트 작성 | DarraUa_Session_BrowseNode |
| 여러 노드를 일괄 처리 | DarraUa_Session_ReadNodes / _BrowseNodes, 반복하지 마세요 |
| 여러 경로의 일괄 초기화 | DarraUa_Session_TranslateBrowsePaths |