browse_with_paging
browse 只返回 references 列表, 丢弃 continuation_point, 适合"已知小节点"场景. 大节点 (子节点 100+) 用 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 |
|---|---|
| 已知节点子数 ≤ 50, 不关心分页 | browse(...) |
| 不确定子数, 安全起见 | browse_with_paging(...) + 循环 browse_next |
| 100+ 子节点的大节点 | browse_with_paging(...) 必选 |
| 一次 browse 多个节点 | browse_many(...) (注意当前 browse_many 不返回 ContinuationPoint) |
完整模板
from darra_opcua import OpcUaSession, NodeClass, Reference
from typing import List
def browse_all(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