본문으로 건너뛰기

EventFilter

개요​

OPC UA Part 4 §7.18 EventFilter:

  • select_clauses — 어떤 필드를 추출할 것인가
  • where_clause — 필터 조건 (V1 아직 구현되지 않음)

SimpleAttributeOperand (Part 4 §7.4.4.5): type_definition_id / browse_path / attribute_id / index_range.

현재 "구독 EventFilter 포함"에 SDK 대한 공개 진입점이 없습니다.

EventFilter / SimpleAttributeOperand 에서단순히 데이터 구조일 뿐입니다, 최상위 계층에서 darra_opcua 내보내졌지만 C 계층을 통해 전달됩니다 Session::subscribe_events DarraUa_Subscription_AddEventItem, 해당 진입점filter 매개변수를 허용하지 않습니다.. EventSubscription::subscribe_with_filter 미실현, 그것을 보고 코드를 작성하지 마세요.

실제로 구독할 수 있는 경로는 단 하나뿐입니다 (참조: 이벤트 구독):

pub fn Session::subscribe_events<F>(
&self,
node_id: Option<&str>,
existing: Option<Arc<Subscription>>,
callback: F,
) -> Result<EventSubscription, OpcUaError>
where F: FnMut(&EventArrivedEventArgs) + Send + 'static

EventSubscription 유일한 공통 방법은 입니다 monitored_item_handle() -> u32.

API​

유형 / 필드 / 메서드분류읽기 및 쓰기설명
EventFilter { select_clauses, where_clause }struct—있다 Default
EventFilter::default_5_fields()방법읽기Severity / Message / SourceName / Time / EventType
SimpleAttributeOperand { type_definition_id, browse_path, attribute_id, index_range }struct—derive Debug + Clone만, 없음 Default
SimpleAttributeOperand::field(name)방법읽기단일 필드, type_definition_id = None
SimpleAttributeOperand::nested(path)방법읽기중첩 필드, type_definition_id = None

SimpleAttributeOperand 어떻게 쓰나요?​

type_definition_id 는 Option<String>, 아닌 String —— "i=2041".into() 컴파일 오류 (Option<String> 구현되지 않음 From<&str>), 작성해야 함 Some("i=2041".to_string()). 구조체없음 impl Default, ..Default::default() 이것도 컴파일 오류가 발생합니다. 네 개의 필드를 모두 입력해야 합니다:

use darra_opcua::{SimpleAttributeOperand, AttributeId};

let clause = SimpleAttributeOperand {
type_definition_id: Some("i=2041".to_string()), // Option<String>
browse_path: vec!["EventType".into()],
attribute_id: AttributeId::Value,
index_range: None,
};

지정할 필요가 없을 때는 생성자를 EventType 사용하는 것이 더 짧습니다:

let a = SimpleAttributeOperand::field("EventType");                 // 단일 필드
let b = SimpleAttributeOperand::nested(["EnabledState", "Id"]); // 중첩 필드

생성자가 생성하는 것은 type_definition_id (와일드카드로 간주됨 BaseEventType)입니다 None .

EventFilter 조립​

EventFilter 있다 Default, 그대로 작성해도 where_clause: None 문제없습니다:

use darra_opcua::{EventFilter, SimpleAttributeOperand, AttributeId};

let filter = EventFilter {
select_clauses: vec![
SimpleAttributeOperand {
type_definition_id: Some("i=2041".to_string()),
browse_path: vec!["EventId".into()],
attribute_id: AttributeId::Value,
index_range: None,
},
SimpleAttributeOperand::field("EventType"),
SimpleAttributeOperand::field("SourceName"),
SimpleAttributeOperand::field("Time"),
SimpleAttributeOperand::field("Message"),
SimpleAttributeOperand::field("Severity"),
SimpleAttributeOperand {
type_definition_id: Some("i=2782".to_string()),
browse_path: vec!["ConditionId".into()],
attribute_id: AttributeId::Value,
index_range: None,
},
SimpleAttributeOperand::nested(["ActiveState", "Id"]),
],
where_clause: None,
};

콜백을 통해 실제로 무엇을 얻을 수 있나요?​

구독하기 s.subscribe_events(...), 콜백으로 수신한 내용은 EventArrivedEventArgs —— 5개의 타일링 필드, 배열 fields 없음:

pub struct EventArrivedEventArgs {
pub severity: u16,
pub message: Option<String>,
pub source_name: Option<String>,
pub time: Option<SystemTime>,
pub event_type: Option<String>,
}
use darra_opcua::Session;

let mut s = Session::new("opc.tcp://localhost:4840")?;
s.connect()?;

let ev = s.subscribe_events(Some("i=2253"), None, |args| {
println!("[{:?}] sev={}: {:?} type={:?}",
args.time, args.severity, args.message, args.event_type);
})?;
println!("event mi = {}", ev.monitored_item_handle());
SDK 인덱스를 사용하지 않고 select_clauses 결과를 노출할 때

select_clauses 의 결과아니요의 형태로 콜백이 args.fields[i] 전달되므로, "fields[i]의 순서가 select_clauses의 순서와 같다"는 것은 성립하지 않습니다.EventId / ConditionId 의 원본 ByteString 현재 노출되지 않음에는 위의 5개 필드만 있습니다 EventArrivedEventArgs. Variant 에는 as_byte_string / as_uint16 / 와 같은 as_boolean 게터도 없습니다.

필드 빠른 참조​

EventTypeBrowsePath의미
BaseEventType (i=2041)["EventId"]이벤트의 고유 ID
BaseEventType["Severity"]심각도 1-1000
ConditionType (i=2782)["ConditionId"]조건 NodeId
AcknowledgeableConditionType (i=2881)["AckedState", "Id"]bool Ack 여부
AlarmConditionType (i=2915)["ActiveState", "Id"]bool 활성화 여부

위의 표는필드 의미 참조, 현재 이벤트 콜백은 SDK 5개의 고정 필드만 노출합니다.

구현상의 제약​

  • "구독 EventFilter 포함"을 지원하는 공개 진입점은 없으며, EventFilter 현재는 데이터 구조로만 존재합니다.
  • 이벤트 C 계층을 MI 통과하며 DarraUa_Subscription_AddEventItem, 사용자 정의 설정을 하달하지 않음 SelectClauses
  • where_clause V1 미실현
  • EventId / ConditionId 원본 ByteString 표시되지 않음

모범 사례​

  • 사건을 파악하려면 다음을 사용하세요 subscribe_events, 전송하려고 하지 마세요 EventFilter
  • 필드를 명시적으로 나열하는 관행을 유지하며, filter 기능이 공개되면 바로 재사용할 수 있습니다.
  • 알람 패널이 필요할 ConditionId 때는, 먼저 event_type + 를 사용하여 위치를 source_name 파악한 다음, 알람 call 노드의 확인 방법을 선택하십시오.

다국어 대조​

C#PythonJavaC++RustC
EventFilterEventFilterEventFilterEventFilterEventFilterDarraUa_EventFilter
SimpleAttributeOperandSimpleAttributeOperandSimpleAttributeOperandSimpleAttributeOperandSimpleAttributeOperandDarraUa_SimpleAttributeOperand

다음 단계​