跳到主要内容

History 历史

ua.read_history(...) 是简化入口, 完整 API 直接挂在 OpcUaSession 上, 命名 read_history_* / update_history / delete_history_*.

子页跳转

5 种 HistoryRead 模式​

模式API说明
Raw 原始数据read_history区间内全部点
Modified 含修改记录read_history_modified区间内含修改记录
AtTime 指定时间点read_history_at_time给定时间戳的内插值
Processed 聚合read_history_processed聚合 (Avg / Min / Max / ...)
Events 事件历史read_history_events历史事件 (报警 / 条件)

HistoryUpdate​

API用途
update_historyInsert / Replace / Update / Remove 历史数据
delete_history_range按时间段删除历史

时间戳约定​

所有 API 入参 / 返回的 datetime 都是 UTC:

import datetime as dt

start = dt.datetime.now(dt.timezone.utc) - dt.timedelta(hours=1)
end = dt.datetime.now(dt.timezone.utc)

不要传本地时间 (dt.datetime.now() 默认本地, 没 tzinfo). SDK 内部 datetime → FILETIME 转换会强制按 UTC 处理 naive datetime.

通用前提​

  • 服务端必须支持 Historian, 否则抛 OpcUaException, 状态码 StatusCode.BadHistoryOperationUnsupported (安全版 read_history_safe 不抛, 返回 (StatusCode, []))
  • 节点的 AccessLevel 的 HistoryRead 位 (bit 2 / 0x04) / HistoryWrite 位 (bit 3 / 0x08) 必须置位
  • 节点 Historizing Attribute (20) 决定是否在记录历史
  • 所有历史方法都是同步的, RPC 返回前占住调用线程; 方法级没有取消 / 超时参数 (每次 RPC 由会话构造参数 request_timeout_ms 约束, 默认 5000 ms), 大区间只能业务侧切片

配套入口​

  • ua.read_history_safe(...) — read_history 的安全版, 异常转 (StatusCode, []), 不抛
  • read_history_stream — 流式读 — 异步生成器逐条 yield, 防一次装进 list 撑爆内存

下一步​