ReadHistory (Raw)
std::vector<DataValue> ReadHistory(
std::string const& node_id,
int64_t start_utc_100ns,
int64_t end_utc_100ns,
uint32_t max_values = 0,
bool return_bounds = false);
最常用的历史读, 返回 [start, end] 区间内全部原始数据点.
前置 / 配套
- 高频数据点过多时改用 ReadHistoryProcessed 聚合.
- 想要含修改记录请用 ReadHistoryModified.
- 时间用 FileTime (UTC 100ns since 1601), 转换公式见 History 总览.
参数
| 参数 | 默认 | 说明 |
|---|---|---|
node_id | — | 目标 NodeId |
start_utc_100ns | — | 区间起 (FileTime) |
end_utc_100ns | — | 区间止 (FileTime) |
max_values | 0 (不限) | 单次返回上限 |
return_bounds | false | true = 返回包含边界点 |
用法
constexpr int64_t WIN_EPOCH_OFFSET = 116444736000000000LL;
auto now_ns = std::chrono::duration_cast<std::chrono::nanoseconds>(
std::chrono::system_clock::now().time_since_epoch()).count();
int64_t end_ft = WIN_EPOCH_OFFSET + now_ns / 100;
int64_t start_ft = end_ft - 3600LL * 10000000LL; // 1 小时前
auto dvs = s.ReadHistory("ns=2;s=Temperature",
start_ft, end_ft, /*max_values=*/1000);
for (auto const& dv : dvs) {
std::cout << "ft=" << dv.SourceTimestamp()
<< " val=" << dv.Value().AsString()
<< " status=0x" << std::hex << dv.StatusCode() << "\n";
}
异常
| 异常 | 含义 |
|---|---|
Exception(..., BadHistoryOperationUnsupported) | 服务端无 Historian |
Exception(..., BadNotReadable) | 节点无 HistoryRead 权限 |
Exception(..., BadCommunicationError) | 网络故障 |
ContinuationPoint 处理 (内部)
如果数据量大, 服务端可能分多次返回 (ContinuationPoint). SDK 内部已自动循环 HistoryReadNext, 客户端拿到的是合并后的完整 std::vector<DataValue>.
性能与最佳实践
- 高频数据 (1000 Hz+) 拉一天 = 86 M+ 点 → 必须用
max_values限制或改用 ReadHistoryProcessed 聚合 std::vector<DataValue>整体析构时元素自动释放, 不需要手动 Delete- 时间戳一律 UTC FileTime, 不要传本地时间