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 されるため、ビット単位で組み合わせることができます(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 のフィルタリングを行うことである(第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欠落している場合は退化し、Warningを一回出力する- そのエントリポイントが存在したとしても、現状では同様に機能不全に陥っている(三つのフィルタリングパラメータが有効になっていない)。
したがって、今日は実際にはフィルタ 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