본문으로 건너뛰기

ReadHistoryEvents

서버 측에서 이벤트 이력을 기록하면, 클라이언트 측에서 시간 범위를 지정하여 과거 이벤트를 불러올 수 있습니다.

세트

서명​

다음 프로토타입은 Session 의 멤버 메서드입니다.

std::vector<EventArrivedEventArgs> ReadHistoryEvents(
std::string const& node_id,
int64_t start_ft, int64_t end_ft,
uint32_t max_events = 0);
매개변수기본값설명
node_id—이벤트 소스 노드 NodeId, 일반적으로 서버 i=2253
start_ft—구간 시작 (FileTime)
end_ft—구간 정지 (FileTime)
max_events0최대 몇 건까지 반환할 수 있습니까? 0 = 제한 없음 (서버 측에서 자체적으로 상한을 설정할 수 있음)

EventArrivedEventArgs​

struct EventArrivedEventArgs {
uint16_t severity = 0; // 1-1000
std::string message;
std::string source_name;
int64_t time = 0; // FileTime (UTC 100ns since 1601)
std::string event_type;
};

서버에서 반환된 각 이벤트는 이미 SDK 계층에서 평면 구조로 추출되었습니다. 내장 SelectClause 4개의 필드 고정: 심각도 / 메시지 / SourceName / 시간; 필터 조건을 비워두면 = 해당 범위 내의 모든 이벤트가 반환됩니다.

event_type 이력 수업에서항상 빈 문자열 —— 이 4가지 SelectClause 중 어느 것에도 해당하지 않으며, 이력 경로를 파악할 수 없습니다 ( EventType 기본 이벤트 구독도 마찬가지로 파악할 수 없습니다. 참조: 이벤트 구독).

사용법​

#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 - 24LL * 3600 * 10000000;

auto events = s.ReadHistoryEvents("i=2253", start_ft, end_ft);

for (auto const& e : events) {
std::cout << "[" << e.severity << "] " << e.source_name
<< ": " << e.message
<< " ft=" << e.time << "\n";
// e.event_type 이력 조회 시 항상 빈 문자열이 표시됩니다. 위 내용을 참조하십시오.
}

사용자 지정 필터​

ReadHistoryEvents에는 EventFilter 매개변수가 없습니다 — 어떤 필드를 가져올지, 무엇으로 필터링할지는 모두 고정되어 있습니다: SelectClause 필드 4개, 필터링 조건은 비워둡니다(모든 이벤트). 범위 내의 알람/조건이 모두 반환되므로, Severity / SourceName 등으로 거르는 것은 업무 측에서 직접 합니다.

SelectClause 또는 필터 조건을 사용자 지정하려면 이벤트 구독 경로를 씁니다: C API DarraUa_EventSubscription_SubscribeWithFilter에 사용자 지정 EventFilter를 전달합니다. C++ 쪽 darra/opcua/event_filter.hpp는 EventFilter / SimpleAttributeOperand 유형 정의를 제공하지만, Session은 현재 이런 유형을 받지 않으며, 해당 파일의 WhereClause도 구현되지 않았습니다(비워 두면 됩니다).

서버 측 요구 사항​

  • 서버는 Events HistoryRead (ReadEventsDetails)를 지원해야 합니다.
  • 이벤트 소스 노드의 EventNotifier Attribute (12)의 1번째 비트 (0x02, HistoryRead)는 설정되어 있어야 합니다.

실시간 이벤트 구독과의 관계​

API무엇으로
s.SubscribeEvents(...)실시간 이벤트 (구독 기간 중 발생한)
s.ReadHistoryEvents(...)이력 이벤트 (서버에 보관된)

일반적인 조합: 시작 시 24시간 동안 데이터를 ReadHistoryEvents 가져온 다음, SubscribeEvents가 실시간 처리를 이어받습니다.

다음 단계​