EventFilter — 사용자 정의 이벤트 필드 및 필터링
개요
OPC UA Part 4 §7.18 EventFilter 두 부분으로 구성된다:
- SelectClauses — 어떤 필드를 추출할 것인가 (순서대로 대응하여
EventArrivedEventArgs) - WhereClause — 필터 조건 (
ContentFilter식 트리) — 현재 제공되지 않음
각 SelectClause 는 입니다 ( SimpleAttributeOperand Part 4 §7.4.4.5):
| 필드 | 설명 |
|---|---|
| TypeDefinitionId | 이벤트 유형 NodeId (예: i=2041 BaseEventType) |
| BrowsePath | 필드 경로 (예: ["Severity"] / ["EnabledState", "Id"]) |
| AttributeId | 속성 Id, 기본값 Value |
| IndexRange | 배열 인덱스 범위 (일반적으로 null) |
전달 여부와 관계없이 EventFilter, 현재는 SDK 5개의 필드만 구독하고 있습니다: ( Severity / Message / SourceName / Time / EventType 아래 "현재 동작" 참조).
API
| 클래스 / 필드 | 분류 | 읽기 및 쓰기 | 설명 |
|---|---|---|---|
| EventFilter | 클래스 | — | 필터 용기 |
| .SelectClauses | 속성 | 읽기 및 쓰기 | SimpleAttributeOperand[] |
| .WhereClause | 속성 | 읽기 및 쓰기 | string, 현재 제공되지 않으므로 null로 두시면 됩니다. |
| SimpleAttributeOperand | 클래스 | — | 개별 필드 정의 |
| ev.Subscribe(objectNodeId, filter) | 방법 | 쓰기 | 기존 이벤트를 삭제한 후 대상 노드에 다시 MI 연결합니다 (현재 필터는 적용되지 않음). |
코드 예시
using DarraOpcUa_Client;
using var ua = new DarraOpcUa("opc.tcp://localhost:4840");
ua.Connect();
using var sub = ua.CreateSubscription(500);
// 1) 어떤 필드를 수집할지 명시 (기본값 5개 + 경보 전용 2개)
var filter = new EventFilter
{
SelectClauses = new[]
{
// 기본 5개 필드
new SimpleAttributeOperand { TypeDefinitionId = "i=2041", BrowsePath = new[] { "Severity" } },
new SimpleAttributeOperand { TypeDefinitionId = "i=2041", BrowsePath = new[] { "Message" } },
new SimpleAttributeOperand { TypeDefinitionId = "i=2041", BrowsePath = new[] { "SourceName" } },
new SimpleAttributeOperand { TypeDefinitionId = "i=2041", BrowsePath = new[] { "Time" } },
new SimpleAttributeOperand { TypeDefinitionId = "i=2041", BrowsePath = new[] { "EventType" } },
// 경보 전용
new SimpleAttributeOperand { TypeDefinitionId = "i=2782", BrowsePath = new[] { "ConditionId" } },
new SimpleAttributeOperand { TypeDefinitionId = "i=2915", BrowsePath = new[] { "ActiveState", "Id" } },
}
};
// 2) 먼저 이벤트 구독을 생성한 다음, filter에 따라 해당 노드의 이벤트 구독을 다시 생성합니다.
using var ev = ua.SubscribeEvents("i=2253", sub);
ev.Subscribe("i=2253", filter);
ev.EventArrived += (s, e) =>
{
// 이벤트 콜백은 현재 5개의 고정 필드만 노출하며, 사용자 정의 필드는 현재 제공되지 않습니다.
Console.WriteLine($"[{e.Time:HH:mm:ss}] sev={e.Severity} {e.SourceName}: {e.Message}");
};
현재 행동 (중요)
사용자 정의 SelectClauses 현재는 확실히 적용되지 않습니다
ev.Subscribe(objectNodeId, filter) 서버로 SelectClauses 전송하지 않습니다, 반드시 기본 필드를 사용해야 합니다:
- 사건 MI 평소와 같이 등록, SelectClauses 배포하지 않음
- 'Info'
Diagnostic카테고리의 이벤트 항목이 하나 표시되며, 기본값인 5개 필드로 돌아왔음을 나타냅니다. - 그래서필터 조건과 필드 선택이 모두 적용되지 않았습니다.: 서버에서 보내는 대로, 그대로
EventArrived수신한다
- 이벤트 콜백은 항상
Severity / Message / SourceName / Time / EventType5개의 필드(EventArrivedEventArgs)를 반환하며, 사용자 정의 필드는 수신되지 않습니다. - WhereClause 문자열 자리 표시자이며, 없음 ContentFilter 분석, 어떠한 조건에 의한 필터링도 수행하지 않음
Subscribe(objectNodeId, filter)먼저 기존 이벤트를 제거한 후 MI, 대상 노드에 새로운 이벤트를 연결합니다. 대상이 컨테이너 구독에 연결되어 있어야 하며, 그렇지 않으면 예외가 발생합니다InvalidOperationException. null인objectNodeId경우 예외가 발생합니다.ArgumentNullException
SelectClauses 필드 경로 빠른 참조 (자주 사용하는 EventType + BrowsePath)
| EventType | BrowsePath | 의미 |
|---|---|---|
| BaseEventType (i=2041) | ["EventId"] | 이벤트 고유 ID (ByteString) |
| BaseEventType | ["EventType"] | 사건 유형 NodeId |
| BaseEventType | ["SourceName"] | 트리거 소스 이름 |
| BaseEventType | ["Time"] | 사건 발생 시간 (UTC) |
| BaseEventType | ["Message"] | 문자 메시지 |
| BaseEventType | ["Severity"] | 심각도 1-1000 |
| ConditionType (i=2782) | ["ConditionId"] | 조건 NodeId |
| ConditionType | ["ConditionName"] | 조건명 |
| ConditionType | ["EnabledState", "Id"] | Bool 활성화 여부 |
| AcknowledgeableConditionType (i=2881) | ["AckedState", "Id"] | Bool: 확인 완료 여부 |
| AlarmConditionType (i=2915) | ["ActiveState", "Id"] | Bool 활성화 여부 |
| AlarmConditionType | ["ShelvingState", "CurrentState"] | LocalizedText 차폐 상태 |
모범 사례
- 5개의 고정 필드에 따라 콜백을 작성합니다. — 지금은 의존하지 마세요 SelectClauses. 전송해도 적용되지 않습니다.
- 필수 입력 필드(EventId / ConditionId / ActiveState)에 대해서는 다른 방법을 찾아야 합니다. — 이벤트 콜백에 이 항목들이 없는데,
ua.Acknowledge/Confirm또conditionId+ 가 필요함eventId. 참조: 이벤트 구독 설명 - 필드 경로 규격 참조용 — Bool,
["ActiveState", "Id"]LocalizedText, 필터링이 적용된 후 이 표에 따라 구성["ActiveState"]
다국어 대조
| C# | Python | Java | C++ | Rust | C |
|---|---|---|---|---|---|
| EventFilter | EventFilter | EventFilterDef.Filter | EventFilter | EventFilter | 현재 제공되지 않습니다 |
| SimpleAttributeOperand | SimpleAttributeOperand | EventFilterDef.Operand | SimpleAttributeOperand | SimpleAttributeOperand | 현재 제공되지 않습니다. |