browse_with_paging
browse 只返回 references 列表, 丢弃 continuation_point, 适合"子数不超过单页 (底层一次请求最多 1000 条)"的节点. 子数可能超过一页的节点用 browse_with_paging 显式拿到 BrowsePage.
前置阅读
- 续翻分页用 browse_next.
签名
def browse_with_paging(self,
node_id: str,
filter: NodeClass = NodeClass.Unspecified) -> BrowsePage: ...
用法
page = ua.browse_with_paging("ns=2;s=BigFolder")
print(f"Got {len(page.references)} children, more = {page.continuation_point is not None}")
if page.continuation_point is not None:
nxt = ua.browse_next(page.continuation_point)
print(f"Next page: {len(nxt.references)} more children")
何时用 browse vs browse_with_paging
| 场景 | API |
|---|---|
| 已知子数不超过一页 (≤ 1000), 不关心分页 | browse(...) |
| 不确定子数, 安全起见 | browse_with_paging(...) + 循环 browse_next |
| 子数可能上千的大节点 | browse_with_paging(...) 必选 |
| 一次 browse 多个节点 | browse_many(...) (注意当前 browse_many 不返回 ContinuationPoint) |
完整模板
Python SDK 没有内置的自动续翻 API (C# 侧才有 BrowseAll 扩展方法), 自己写成辅助函数即可:
from darra_opcua import OpcUaSession, NodeClass, Reference
from typing import List
def browse_all_refs(ua: OpcUaSession,
node_id: str,
filter: NodeClass = NodeClass.Unspecified) -> List[Reference]:
all_refs: List[Reference] = []
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