ReadHistory (Raw)
以下のプロトタイプは Session のメンバメソッドです。
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 1601年以降)、変換式については 履歴の概要.
パラメータ
| パラメータ | デフォルト | 説明 |
|---|---|---|
| node_id | — | 目標 NodeId |
| start_utc_100ns | — | 区間の開始 (FileTime) |
| end_utc_100ns | — | 範囲ストップ (FileTime) |
| max_values | 0 | 一回のリクエストあたりの最大返却数。0 = 制限なし(サーバー側で独自に上限を設定することは可能です) |
| return_bounds | false | true = エンドポイントは必ず結果に含まれる |
使用方法
#include <darra/opcua/client.hpp>
#include <chrono>
#include <iostream>
using namespace darra::opcua;
Session s("opc.tcp://localhost:4840");
s.Connect();
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、メッセージは次のような形式となる HistoryRead 'ns=2;s=Temperature' failed: 0x80720000。ステータスコードはサーバーからそのまま返されるもので、( e.status_code() uint32_t) または e.status() (Status 列挙型) で取得し、人間が読みやすい名称には を使用する Stack::StatusName(e.status_code())。
| ステータスコード | 意味 |
|---|---|
BadHistoryOperationUnsupported | サーバー側にHistorianがない |
BadNotReadable | ノードに HistoryRead 権限がありません |
BadCommunicationError | ネットワーク障害 |
パフォーマンスとベストプラクティス
- 高頻度データ (1000 Hz+) 一日分の引き上げ = 86 M+ ポイント → 制限
max_valuesをかけるか、別の方法に切り替える必要がある ReadHistoryProcessed 集約 std::vector<DataValue>オブジェクト全体の破棄時に要素は自動的に解放されるため、手動でDeleteを実行する必要はない- タイムスタンプは一律に設定し UTC FileTime、ローカル時刻を送信しないでください