본문으로 건너뛰기

EventFilter

개요​

OPC UA Part 4 §7.18 EventFilter 두 부분으로 구성된다:

  • SelectClauses — 어떤 필드를 추출할지 명시하기
  • WhereClause — 필터 조건 (V1 아직 구현되지 않음)

각각은 다음과 같습니다 SelectClause SimpleAttributeOperand:

필드유형기본값설명
type_definition_idOptional[str]None이벤트 유형 NodeId 문자열 (예: "i=2041"); None = 와일드카드 BaseEventType
browse_pathTuple[str, ...]()필드 탐색 경로 (각 세그먼트 BrowseName); 빈 튜플은 해당 EventType 전체를 선택함을 나타냅니다.
attribute_idAttributeIdAttributeId.Value속성 Id
index_rangeOptional[str]None배열 인덱스 범위 (NumericRange 문자열)

EventFilter 그 자체도 frozen 데이터 클래스입니다:

필드유형기본값설명
select_clausesTuple[SimpleAttributeOperand, ...]()어떤 필드를 추출할 것인가
where_clauseOptional[str]None필터 표현식 (ContentFilter). V1 미실현, None 또는 ""을 입력하면 됩니다
현재 버전은 실제로 적용되지 EventFilter 않습니다.

EventSubscription.subscribe(node_id, event_filter) 수락 EventFilter, 하지만 사용자 정의 SelectClauses / WhereClause 전혀 배포하지 않는다, 이벤트는 모두 아래의 5가지 고정 필드에 따라 event_arrived 콜백으로 반환됩니다.

실제로 가져올 수 있는 필드​

전하지 않는 EventFilter 시 (그리고전해도 마찬가지야) 콜백을 통해 반환된 고정된 5개의 필드:

#필드해당 EventArrivedEventArgs
1Severity (UInt16)severity
2Message (String)message
3SourceName (String)source_name
4Time (DateTime)time
5EventType (String)event_type

없음EventId / ConditionId / ActiveState / 모든 사용자 정의 필드 —— 현재 이 필드들은 가져올 수 없으며, 를 통해서도 SelectClauses 추출할 수 없습니다. 와 같은 ConditionId 정보가 필요한 경우, 이벤트를 수신한 후 를 사용하여 알람 노드의 속성을 직접 ua.read(...) 읽어오십시오.

코드 예시​

EventFilter 오직 EventSubscription.subscribe(node_id, event_filter) 사용법; 간편한 진입점 필터는 ua.subscribe_events(...) 지원하지 않습니다. 따라서 필터를 전달하려면 직접 컨테이너를 연결해야 합니다:

from darra_opcua import (
DarraOpcUa, EventFilter, SimpleAttributeOperand, EventSubscription,
)

with DarraOpcUa("opc.tcp://localhost:4840") as ua:
ua.connect()

# 1) 컨테이너 구독 (Publish 처리)
with ua.create_subscription(500) as sub:

# 2) 원하는 필드를 선언합니다 (browse_path 튜플을 사용하여).
f = EventFilter(select_clauses=(
SimpleAttributeOperand(type_definition_id="i=2041", browse_path=("Severity",)),
SimpleAttributeOperand(type_definition_id="i=2041", browse_path=("Message",)),
SimpleAttributeOperand(type_definition_id="i=2041", browse_path=("Time",)),
SimpleAttributeOperand(type_definition_id="i=2041", browse_path=("SourceName",)),
SimpleAttributeOperand(type_definition_id="i=2041", browse_path=("EventType",)),
))

# 3) 직접 구축 EventSubscription, 컨테이너를 등록한 후 subscribe
es = EventSubscription(ua)
es.attach_container_subscription(sub, owns=False) # owns=False: es.dispose()는 sub를 삭제하지 않습니다.
es.subscribe("i=2253", event_filter=f)

# 4) 콜백 매개변수는 고정된 값이며 EventArrivedEventArgs, select_clauses 순서가 정해져 있지 않은 필드 목록이 아닙니다.
def on_event(args):
if args.time is not None:
print(f"[{args.time:%H:%M:%S}] sev={args.severity}: {args.message}")
print(f" source={args.source_name} type={args.event_type}")

es.event_arrived.append(on_event)
콜백에는 args.fields가

EventArrivedEventArgs 없고, 오직 다섯 severity / message / source_name / time / event_type 개의 필드만 있습니다.존재하지 않음 args.fields[...], 또한 as_byte_string / as_uint16 이와 같은 필드 액세서리도 없습니다. —— 더 많은 필드가 필요하면 콜백 내에서 ua.read(...) 직접 읽어오십시오.

필드 빠른 참조 (browse_path 참조)​

아래 표는 표준 OPC UA 주소 공간 (Part 3 / Part 9)에 나오는 이벤트 필드로, 이를 구성할 때 SimpleAttributeOperand.browse_path 참조용으로 사용하십시오.현재 SDK 배포되지 않음 EventFilter, 이 필드들을 선택한다고 해서 데이터가 더 많이 제공되는 것은 아닙니다. — 이 필드들은 EventFilter true로 설정된 경우에만 의미가 있습니다.

사건 유형type_definition_idbrowse_path의미
BaseEventTypei=2041("EventId",)이벤트의 고유 ID
BaseEventTypei=2041("Severity",)중증도
BaseEventTypei=2041("Message",)사건 내용
BaseEventTypei=2041("Time",)사건 발생 시간
ConditionTypei=2782("ConditionId",)조건 NodeId
ConditionTypei=2782("EnabledState", "Id")bool 활성화 여부
AcknowledgeableConditionTypei=2881("AckedState", "Id")bool Ack 여부
AlarmConditionTypei=2915("ActiveState", "Id")bool 활성화 여부
ShelvedConditionTypei=2929("ShelvingState", "CurrentState")LocalizedText 차폐 상태

행동 및 제한 사항​

  • 사용자 정의 SelectClauses / WhereClause 적용되지 않음, 이벤트 필드는 항상 그 5개만 고정됩니다.
  • 적용되지 않을 때 / OpcUaEventCategory.Diagnostic OpcUaEventSeverity.Info 이벤트에 「현재 버전에서는 사용자 정의 EventFilter 앱 (...)을 제공하지 않으므로 기본 5개 필드로 되돌려졌습니다」라는 메시지를 한 건 전송합니다. 주의 수준은 Info Warn이 아닙니다.
  • 필터는 현재 구독 내에서만 유지되며, 구독이 재구성될 때 다시 적용되지 않습니다.
  • where_clause 현재는 단순히 문자열 자리 표시자일 뿐이며, 실제 ContentFilter(ElementOperand 트리)는 구현되지 않아 어떤 값을 전달해도 작동하지 않습니다.

모범 사례​

  • 더 많은 필드가 필요하면, 이벤트 콜백에서 알람 노드의 속성을 직접 ua.read(...) 읽어오세요.
  • 중첩된 필드는 튜플을 사용하여 여러 단계로 작성합니다: ("ActiveState", "Id")
  • type_definition_id 이벤트 유형의 NodeId 문자열을 사용하여 browse_path 쌍을 이루는 선언

다국어 대조​

C#PythonJavaC++RustC
EventFilterEventFilterEventFilterEventFilterEventFilterDarraUa_EventFilter
SimpleAttributeOperandSimpleAttributeOperandSimpleAttributeOperandSimpleAttributeOperandSimpleAttributeOperandDarraUa_SimpleAttributeOperand

다음 단계​