History 历史
Session::read_history(...) 是简化入口, 完整 API 在 Session::read_history_* /
update_history / delete_history_range.
子页跳转
- 区间内全部原始点请参考 ReadRaw.
- 含修改记录请参考 ReadModified.
- 指定时间点的内插值请参考 ReadAtTime.
- 聚合 (Average / Min / Max / TimeAverage / ...) 请参考 ReadProcessed.
- 历史事件 (报警 / 条件) 请参考 ReadEvents.
- 写历史 (Insert / Replace / Update) 请参考 HistoryUpdate.
- 删除历史请参考 Delete.
5 种 HistoryRead 模式
| 模式 | API | 说明 |
|---|---|---|
| Raw 原始数据 | read_history | 区间内全部点 |
| Modified 含修改记录 | read_history_modified | 区间内含修改记录 |
| AtTime 指定时间点 | read_history_at_time | 给定时间戳的内插值 |
| Processed 聚合 | read_history_processed | 聚合 (Average / Min / Max / ...) |
| Events 事件历史 | read_history_events | 历史事件 (报警 / 条件) |
HistoryUpdate / Delete
| API | 用途 |
|---|---|
update_history | Insert / Replace / Update / Remove 历史数据 |
delete_history_range | 按时间区间删除 (含 / 不含修改记录) |
时间类型
所有 history API 用 std::time::SystemTime. 内部转 FILETIME (1601-based 100ns ticks):
use std::time::{Duration, SystemTime};
let now = SystemTime::now();
let one_hour_ago = now - Duration::from_secs(3600);
let dvs = s.read_history("ns=2;s=Temperature", one_hour_ago, now, 1000)?;
通用前提
- 服务端必须支持 Historian, 否则统一返回
BAD_HISTORY_OPERATION_UNSUPPORTED - 节点的
AccessLevelbit 4 (HistoryRead) / bit 8 (HistoryWrite) 必须置位 - 节点
HistorizingAttribute (20) 决定是否在记录历史
Aggregate NodeId 常量
darra_opcua::history_aggregate 模块预定义标准聚合函数 NodeId:
use darra_opcua::history_aggregate;
history_aggregate::AVERAGE; // i=2342
history_aggregate::MINIMUM; // i=2346
history_aggregate::MAXIMUM; // i=2347
history_aggregate::COUNT; // i=2352
history_aggregate::TOTAL; // i=2348
history_aggregate::TIME_AVERAGE; // i=11285
history_aggregate::RANGE; // i=2353
history_aggregate::DELTA; // i=11286
history_aggregate::STANDARD_DEVIATION_SAMPLE; // i=11427
HistoryUpdateType 枚举
pub enum HistoryUpdateType {
Insert = 1, // 插入新值, 已存在则失败
Replace = 2, // 替换已存在的, 不存在则失败
Update = 3, // Insert 或 Replace, 都行
Remove = 4, // 按时间删除 (DataValue.source_timestamp 决定删哪些)
}