browse
browse(node_id, filter = NodeClass.Unspecified) — 지정된 노드의 직접 자식 노드(한 단계)를 나열합니다.
- 큰 노드의 페이징에는 다음을 사용하십시오 browse_with_paging + browse_next.
- 경로 기반 일괄 분석은 다음을 사용하십시오. translate_browse_paths.
서명
def browse(self,
node_id: str,
filter: NodeClass = NodeClass.Unspecified) -> List[Reference]: ...
def browse_many(self,
node_ids: List[str],
filter: NodeClass = NodeClass.Unspecified) -> List[List[Reference]]: ...
Reference 필드
| 필드 | 유형 | 설명 |
|---|---|---|
| node_id | str | 자식 노드 NodeId |
| browse_name | str | 열람명 |
| display_name | str | 표시 이름 |
| node_class | NodeClass | 자식 노드 유형 |
Reference.to_node(session) 실행 가능한 형태로 전환 OpcUaNode.
예시
from darra_opcua import NodeClass
# Boiler1 아래의 모든 자노드를 나열합니다.
children = ua.browse("ns=2;s=Boiler1")
for c in children:
print(f" {c.node_class.name} {c.browse_name} -> {c.node_id}")
# Variable 유형만 보기
vars_ = ua.browse("ns=2;s=Boiler1", filter=NodeClass.Variable)
# Method만 보기
methods = ua.browse("ns=2;s=Calculator", filter=NodeClass.Method)
일괄 열람 (browse_many)
여러 노드를 동시에 탐색해야 하는 경우(예: 트리를 처음 GUI 펼칠 때), 다음을 한 번 browse_many 사용하면 됩니다 RPC:
roots = ["i=85", "i=86"] # Objects / Types
results = ua.browse_many(roots)
for nid, refs in zip(roots, results):
print(f"{nid}:")
for c in refs:
print(f" {c.browse_name}")
특정 노드의 탐색에 실패(NodeId 오류)할 경우, 해당 슬롯은 다음을 반환합니다.빈 목록, 예외를 던지지 않음; 하지만 전체 프로세스 RPC 자체가 실패하면 (하위 레벨에서 0이 아닌 값을 반환하면) 예외가 발생합니다 OpcUaException.
NodeClass filter
| 값 | 포함 |
|---|---|
| Unspecified (0) | 전체 |
| Object (1) | Object만 |
| Variable (2) | Variable만 |
| Method (4) | Method만 |
| Object | Variable (비트별 OR) | 조합 |
filter BrowseDescription으로 그대로 nodeClassMask 전달되므로, 비트별 OR 연산을 통해 조합할 수 있습니다(0 = 제한 없음).
예외
OpcUaException(BadNodeIdUnknown) / OpcUaException(BadCommunicationError) 등. 전송 실패 시 예외를 발생시키며, 개별 하위 노드의 실패 시에는 예외를 발생시키지 않습니다.
대형 노드의 페이징 (ContinuationPoint)
하위 계층의 단일 Browse 요청은 다음과 같이 requestedMaxReferencesPerNode 고정됩니다. 1000, 따라서 자식 노드가 1000개를 초과할 경우 서버는 첫 페이지만 반환하고 를 표시합니다 ContinuationPoint.browse 읽지도 않고 반환하지도 않는다 ContinuationPoint, 결과로 나온 것은 바로 이 페이지입니다 —— "모든 자식 노드"가 아닙니다.
전체를 보려면, 다음을 사용하세요. browse_with_paging + browse_next:
page = ua.browse_with_paging("ns=2;s=BigFolder")
all_refs = list(page.references)
while page.continuation_point is not None:
page = ua.browse_next(page.continuation_point)
all_refs.extend(page.references)
한 번에 얼마인가요? RPC
browse: 1회 RPC, 첫 페이지만 가져오기 (≤ 1000건)browse_many: 1회 N개의 BrowseDescription을 RPC 포함하며, N-1회의 왕복을 줄임 (저층 주석: "네트워크 왕복 횟수가 N회에서 1회로 감소")browse시리즈의 BrowseDescription은 항상 다음과 같습니다: 방향 Forward, 참조 유형 References (i=31) (하위 유형 포함), resultMask=0x3F —— 이 항목들은 매개변수가 아닙니다. 방향/참조 유형별로 필터링하려면 현재 클라이언트 측에서만 가능합니다(아래의 구현browse_filtered제한 사항 참조).
browse_filtered — 방향 + 참조 유형 필터링
browse_filtered 목표는 browse 을 기반으로 BrowseDirection + reference_type_id + include_subtypes 필터링을 추가하는 것입니다 (Part 4 §5.8.2.2).
def browse_filtered(self,
nid: str,
node_class_filter: NodeClass = NodeClass.Unspecified,
direction: BrowseDirection = None, # None = 처리 FORWARD
reference_type_id: str = None,
include_subtypes: bool = True) -> List[Reference]: ...
관련 구조 (본명 darra_opcua, 대문자로 표기된 멤버):
class BrowseDirection(IntEnum):
FORWARD = 0 # 양방향(인용 출처)만, 부모→자식
INVERSE = 1 # 오직 역방향(인바운드 참조)만, 자식→부모
BOTH = 2 # 양방향 모두 반환
예시
from darra_opcua import BrowseDirection, NodeClass
# 1) 양의 값 + 오직 HierarchicalReferences (i=33)
children = ua.browse_filtered("ns=2;s=Boiler1",
node_class_filter=NodeClass.Variable,
direction=BrowseDirection.FORWARD,
reference_type_id="i=33",
include_subtypes=True)
# 2) 역방향 부모 찾기
parents = ua.browse_filtered("ns=2;s=Tank.Level",
direction=BrowseDirection.INVERSE)
for p in parents:
print(f"父: {p.browse_name}")
구현 제한 사항 (중요)
현재 Python 버전일률적으로 퇴화성 browse(nid, node_class_filter), direction / reference_type_id / include_subtypes 효력이 발생하지 않습니다:
DarraUa_Session_BrowseWithFilter누락 시 기능이 제한되며, 경고 메시지가 한 번 표시됩니다.- 해당 진입점이 존재하더라도, 현재 마찬가지로 제대로 작동하지 않습니다 (세 가지 필터링 매개변수가 적용되지 않음).
그래서 오늘은 실제로 browse_filtered NodeClass 필터링만 수행하며, 방향은 항상 Forward입니다. 방향이나 참조 유형에 따라 필터링해야 한다면, 전체 데이터를 직접 가져온 후 클라이언트 Reference 측에서 필터링해야 합니다. (C# 측에는 BrowseFiltered 매개변수가 resultMask 있어 두 언어의 방식이 완전히 일치하지는 않습니다.)
자동으로 페이지 넘김 계속
Python SDK에는 내장 자동 페이지 넘김 API가 없습니다(C# 쪽에만 BrowseAll 확장 메서드가 있습니다). 직접 루프를 작성하면 됩니다:
def browse_all_refs(ua, node_id, filter=NodeClass.Unspecified):
all_refs = []
page = ua.browse_with_paging(node_id, filter)
all_refs.extend(page.references)
while page.continuation_point is not None:
page = ua.browse_next(page.continuation_point)
all_refs.extend(page.references)
return all_refs