History 历史
ua.read_history(...) 是简化入口, 完整 API 直接挂在 OpcUaSession 上, 命名 read_history_* / update_history / delete_history_*.
子页跳转
- 区间内全部原始点请参考 read_history (Raw).
- 含修改记录请参考 read_history_modified.
- 指定时间点的内插值请参考 read_history_at_time.
- 聚合 (Avg / Min / Max / TimeAverage / ...) 请参考 read_history_processed.
- 历史事件 (报警 / 条件) 请参考 read_history_events.
- 写历史 (Insert / Replace / Update) 请参考 update_history.
- 删除历史请参考 delete_history_range.
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_history | Insert / 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 撑爆内存