跳到主要内容

History 历史

Session::read_history(...) 是简化入口, 完整 API 在 Session::read_history_* / update_history / delete_history_range.

子页跳转

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_historyInsert / 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
  • 节点的 AccessLevel bit 4 (HistoryRead) / bit 8 (HistoryWrite) 必须置位
  • 节点 Historizing Attribute (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 决定删哪些)
}

下一步