跳到主要内容

Historical Access(Part 11)

Historical Access(Part 11)定义了如何访问服务端 "Historian" 中存储的历史数据. 这是历史数据访问能力, 与服务器高可用不是一回事. 详细概念见 基础知识 → 历史模型.

配套阅读

5 种 HistoryRead 模式​

模式适用SDK API
ReadRawModified (raw)区间内全部点ua.ReadHistory(nodeId, startTime, endTime, maxValues)
ReadAtTime指定时刻插值ua.ReadHistoryAtTime(nodeId, times, useSimpleBounds)
ReadProcessed (聚合)聚合结果ua.ReadHistoryProcessed(nodeId, start, end, processingInterval, aggregateNodeId)
ReadEvents事件历史ua.ReadHistoryEvents(nodeId, start, end, maxEvents)
ReadRawModified (modified)含修改记录ua.ReadHistoryModified(nodeId, start, end, maxValues, returnBounds)

HistoryUpdate​

操作SDK API
Insert / Replace / Update / Remove Dataua.UpdateHistory(nodeId, updateType, values)
Delete by Rangeua.DeleteHistoryRange(nodeId, start, end, deleteModifiedToo)
Insert Annotation当前不提供
Delete Events当前不提供

updateType 取 HistoryUpdateType 的四个成员: Insert (1) / Replace (2) / Update (3) / Remove (4). Remove 时 values 里只用 SourceTimestamp 定位要删的点, value 字段被忽略.

节点 Historizing​

Variable 节点的 Attribute 20 (Historizing) 表示是否在记录. 节点访问权限不足时服务端会拒绝 HistoryRead.

聚合 (Aggregates)​

当前 SDK 提供的聚合函数 NodeId:

常量NodeId说明
Averagei=2342区间内值的算术平均
Minimumi=2346区间内最小值
Maximumi=2347区间内最大值
Counti=2352区间内 Good 状态的数据点数量
Totali=2348区间内值的累加 (代数和)
StandardDeviationSamplei=11427样本标准差
TimeAveragei=11285时间加权平均
Rangei=2353区间内 (Max − Min)
Deltai=11286区间末 − 区间始

例: "查 24 小时温度的每小时平均":

var values = ua.ReadHistoryProcessed(
nodeId: "ns=2;s=Temperature",
start: yesterday,
end: today,
processingInterval: TimeSpan.FromHours(1),
aggregateNodeId: HistoryAggregate.Average);

性能建议​

  • 高频原始数据用 ReadHistoryProcessed 聚合, 少拉原始点
  • 历史读取当前不提供续读入口, 用 maxValues 控制单次返回量 (0 = 不限, 由服务端决定上限)

相关链接​