HistoryReadEvents (C)
서버 측에서 이벤트 이력을 기록하면, 클라이언트 측에서 시간 범위를 지정하여 과거 이벤트(알람/조건)를 불러올 수 있습니다.
세트
- 실시간 이벤트 구독을 원하시면 다음을 이용하십시오. 이벤트 구독.
- 과거 변수 데이터는 다음을 사용해 주십시오. ReadRaw / ReadProcessed.
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);
서버 측 요구 사항
- 서버 측에서는 ReadEventsDetails (Part 11 §6.4.4)를 HistoryRead 구현해야 합니다. 지원되지 않을 경우 서버 측 상태 코드가 그대로 전달됩니다.
- 이벤트 소스 노드에는 EventNotifier 속성(12)의 비트 HistoryRead (
0x02)가 설정되어 있어야 합니다.
실시간 이벤트 구독과의 관계
| API | 무엇으로 |
|---|---|
| DarraUa_Subscription_AddEventItem(...) | 실시간 이벤트 (구독 기간 중 발생한) |
| DarraUa_Session_HistoryReadEvents(...) | 이력 이벤트 (서버에 보관된) |
일반적인 조합: 시작 시 24시간 동안 데이터를 ReadEvents 가져온 다음, 구독을 통해 실시간으로 데이터를 수신합니다.