メインコンテンツまでスキップ

HistoryReadEvents (C)

サーバー側がイベントの履歴を記録している場合、クライアント側は時間範囲を指定して過去のイベント(アラーム/条件)を取得することができます。

付属品

API​

#include <opcua/opcua_history.h>
#include <opcua/opcua_event.h>

OPCUA_API DarraUa_Status OPCUA_CALL DarraUa_Session_HistoryReadEvents(
DarraUa_SessionHandle h,
const char* node_id_str, /* 通常「i=2253」のサーバー */
DarraUa_DateTime start_time,
DarraUa_DateTime end_time,
uint32_t num_values_per_node,
DarraUa_Event*** out_events,
uint32_t* out_count);

DarraUa_Event* 構造は同じ イベントの購読.

内蔵 SelectClauses​

4つの標準フィールドを固定(Subscription Event と同様):

  • Severity (UInt16)
  • Message (LocalizedText)
  • SourceName (String)
  • Time (DateTime)

whereClause 空白 = すべてのイベント。

解放​

DarraUa_EventArray_Delete(events, count);

_EventArray_Delete 配列自体、各Event要素、およびEvent内部のstrdupで生成された文字列フィールドを解放します。

使用方法​

#include <opcua/opcua_history.h>
#include <opcua/opcua_event.h>

DarraUa_DateTime end = utc_now_ft();
DarraUa_DateTime start = end - 864000000000LL; /* 24時間 */

DarraUa_Event** events = NULL;
uint32_t count = 0;

DarraUa_Status st = DarraUa_Session_HistoryReadEvents(
h, "i=2253",
start, end,
/*num*/ 0, /* 制限なし */
&events, &count);

if (UA_STATUS_IS_GOOD(st)) {
for (uint32_t i = 0; i < count; ++i) {
const DarraUa_Event* ev = events[i];
printf("[sev=%u] src=\"%s\" time=%lld msg=\"%s\"\n",
(unsigned)ev->severity,
ev->source_name ? ev->source_name : "",
(long long)ev->time,
ev->message ? ev->message : "");
}
}

DarraUa_EventArray_Delete(events, count);

サーバー側の要件​

  • サーバー側は HistoryRead の ReadEventsDetails (Part 11 §6.4.4) を実装する必要があります。未実装の場合は、サーバー側のステータスコードをそのまま透過的に転送します。
  • イベント送信ノードには、EventNotifier属性 (12) の HistoryRead ビット (0x02) がセットされている必要があります。

リアルタイムイベントの購読との関係​

API何を持っていくか
DarraUa_Subscription_AddEventItem(...)リアルタイムイベント(購読期間中に発生したもの)
DarraUa_Session_HistoryReadEvents(...)履歴上のイベント(サーバーにアーカイブされたもの)

一般的な設定:起動時に ReadEvents で過去 24 時間分を取得し、その後、サブスクリプションによるリアルタイム配信に切り替えます。

次のステップ​