跳到主要内容

History 历史

Session 提供历史读 5 模式 + 历史写 / 删. 时间一律用 FileTime (UTC 100ns since 1601-01-01), 与 Windows DateTime.ToFileTimeUtc() 一致.

子页跳转

FileTime 常量

constexpr int64_t WIN_EPOCH_OFFSET = 116444736000000000LL;  // 1601 → 1970 间隔

// 当前时刻的 FileTime
auto now_ns = std::chrono::duration_cast<std::chrono::nanoseconds>(
std::chrono::system_clock::now().time_since_epoch()).count();
int64_t now_ft = WIN_EPOCH_OFFSET + now_ns / 100;

// 1 小时前
int64_t one_hour_ago = now_ft - 3600LL * 10000000LL;

5 种 HistoryRead 模式

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

HistoryUpdate

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

通用前提

  • 服务端必须支持 Historian, 否则统一返回 Status::BadHistoryOperationUnsupported
  • 节点的 AccessLevel bit 4 (HistoryRead) / bit 8 (HistoryWrite) 必须置位
  • 节点 Historizing Attribute (20) 决定是否在记录历史

下一步