본문으로 건너뛰기

네임스페이스 (C)

OPC UA 노드는 NodeId 로 NamespaceIndex + Identifier 구성되지만, NamespaceIndex 불안정 — 서버 재시작 시 변경될 수 있습니다. 프로덕션 코드에서는 인덱스를 NamespaceUri 역조회해야 하며, 하드코딩해서는 안 됩니다 ns=2.

사전 읽기
  • 표준 = ns0, 노드 상수에 대해서는 다음을 참조하십시오. WellKnownNodes.
  • 노드 Browse / 경로 분석에 대해서는 다음을 참조하십시오. Nodes.

API 빠른 조회​

함수설명
DarraUa_Session_LoadNamespaceArray(h)서버 측 능동 재읽기 i=2255
DarraUa_Session_GetNamespaceCount(h)네임스페이스 수 ( ns0 포함)
DarraUa_Session_GetNamespaceUri(h, idx)URI 조회 (내부 포인터를 반환하며, free하지 마십시오)
DarraUa_Session_FindNamespaceIndex(h, uri)역조회 URI → 인덱스, 찾을 수 없으면 -1을 반환

Connect 성공하면 LoadNamespaceArray가 한 번 자동으로 SDK 호출되며, 이후에는 수동으로 호출할 필요가 없습니다.

API 자세히 알아보기​

OPCUA_API DarraUa_Status OPCUA_CALL
DarraUa_Session_LoadNamespaceArray(DarraUa_SessionHandle h);

OPCUA_API uint32_t OPCUA_CALL
DarraUa_Session_GetNamespaceCount(DarraUa_SessionHandle h);

OPCUA_API const char* OPCUA_CALL
DarraUa_Session_GetNamespaceUri(DarraUa_SessionHandle h, uint32_t index);

OPCUA_API int32_t OPCUA_CALL
DarraUa_Session_FindNamespaceIndex(DarraUa_SessionHandle h, const char* uri);

GetNamespaceUri은 Stack 내부의 const char*을 반환합니다, 수명 주기는 세션에 따라 결정되며, 해제할 필요도 없고(해제할 수도 없습니다). 저장하려면 직접 처리해야 합니다 strdup.

역조회 Index 철자 NodeId​

int32_t idx = DarraUa_Session_FindNamespaceIndex(h, "urn:my-company:plc1");
if (idx < 0) {
fprintf(stderr, "Server does not have my namespace\n");
return -1;
}

char node_id[64];
snprintf(node_id, sizeof(node_id), "ns=%d;s=Temperature", (int)idx);

DarraUa_Status st = 0;
DarraUa_DataValue* dv = DarraUa_Session_ReadNode(
h, node_id, UA_ATTR_VALUE, &st);
/* ... */
DarraUa_DataValue_Delete(dv);

모든 네임스페이스 나열 (디버깅)​

uint32_t n = DarraUa_Session_GetNamespaceCount(h);
for (uint32_t i = 0; i < n; ++i) {
const char* uri = DarraUa_Session_GetNamespaceUri(h, i);
printf(" [%u] %s\n", (unsigned)i, uri ? uri : "");
}

출력 예시:

[0] http://opcfoundation.org/UA/
[1] urn:server-host
[2] urn:my-company:plc1
[3] http://my-company.com/UA/

동적 네임스페이스 변경​

일부 서버는 시작된 후에야 네임스페이스를 등록하므로(플러그인 방식), Connect가 가져오는 정보가 NamespaceArray 불완전할 수 있습니다. 이 경우 다음을 호출하여 다시 LoadNamespaceArray 읽으십시오:

DarraUa_Session_LoadNamespaceArray(h);
int32_t idx = DarraUa_Session_FindNamespaceIndex(h,
"urn:plugin:loaded-after-startup");

표준 네임스페이스 (ns=0)​

OPC Foundation Index 0은 항상 로 규정하며 http://opcfoundation.org/UA/, 모든 표준 노드는 ns=0에 위치한다:

노드NodeId설명
Rooti=84뿌리
Objectsi=85비즈니스 데이터 루트
Typesi=86유형 정의 루트
Serveri=2253Server 자체 객체
ServerStatusi=2256서버 상태 구조
ServerStatus.CurrentTimei=2258서버의 현재 시간
NamespaceArrayi=2255네임스페이스 배열
ServerArrayi=2254서버 측 배열

자세한 내용은 WellKnownNodes.

다음 단계​