EventFilter
Overview
OPC UA Part 4 §7.18 EventFilter:
- select_clauses — Which fields to capture
- where_clause — Filter Criteria (V1 Not yet implemented)
SimpleAttributeOperand (Part 4 §7.4.4.5): type_definition_id / browse_path / attribute_id / index_range。
EventFilter / SimpleAttributeOperand in SDK thereJust Data Structures, It has been exported from
darra_opcua the top level, but Session::subscribe_events it goes through the C layer
DarraUa_Subscription_AddEventItem, that entry pointDoes not accept the "filter" parameter。
EventSubscription::subscribe_with_filter Not implemented, Don't write code based on it.
There is only one actual subscription entry point (see Event Subscription):
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 The only public method is monitored_item_handle() -> u32.
API
| Type / Field / Method | Category | Reading and Writing | Note |
|---|---|---|---|
| EventFilter { select_clauses, where_clause } | struct | — | Yes Default |
| EventFilter::default_5_fields() | Methods | Read | Severity / Message / SourceName / Time / EventType |
| SimpleAttributeOperand { type_definition_id, browse_path, attribute_id, index_range } | struct | — | Only derive Debug + Clone, None Default |
| SimpleAttributeOperand::field(name) | Methods | Read | Single field, type_definition_id = None |
| SimpleAttributeOperand::nested(path) | Methods | Read | Nested fields, type_definition_id = None |
SimpleAttributeOperand How to Write It
type_definition_id is Option<String>, not String — Fails to compile "i=2041".into()
(Option<String> Not implemented From<&str>), needs to be written Some("i=2041".to_string()).
StructureNone impl Default, It also ..Default::default() fails to compile; all four fields must be filled in:
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,
};
When no value needs to be specified, using EventType the constructor is shorter:
let a = SimpleAttributeOperand::field("EventType"); // Single Field
let b = SimpleAttributeOperand::nested(["EnabledState", "Id"]); // Nested Fields
The constructor type_definition_id returns None (treated as a wildcard BaseEventType).
EventFilter Assembly
EventFilter has Default, It's fine to write it directly 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,
};
What Can You Actually Get from a Callback?
Subscribe now s.subscribe_events(...). The callback received is EventArrivedEventArgs —— 5 tiled fields,
no arrays 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());
select_clauses that are not exposed via an indexselect_clauses ResultsNo The callback is returned in the form args.fields[i] of, so there is no such thing as
"the order of fields[i] being the same as the order of select_clauses.EventId " / The ConditionId original
ByteString Not currently exposed There EventArrivedEventArgs are only the 5 fields listed above.
Variant There are also no as_byte_string / as_uint16 / getters there as_boolean.
Field Quick Reference
| EventType | BrowsePath | Meaning |
|---|---|---|
| BaseEventType (i=2041) | ["EventId"] | Unique Event ID |
| BaseEventType | ["Severity"] | Severity 1–1000 |
| ConditionType (i=2782) | ["ConditionId"] | Conditions NodeId |
| AcknowledgeableConditionType (i=2881) | ["AckedState", "Id"] | bool Is Ack |
| AlarmConditionType (i=2915) | ["ActiveState", "Id"] | bool IsActive |
The table above is a field semantics reference; the SDK's event callback currently exposes only 5 fixed fields.
Implementation Constraints
- There is no public interface for "subscribe EventFilter "; it currently
EventFilterexists only as a data structure. - Event: Processes MI run at the C-layer
DarraUa_Subscription_AddEventItem; no custom commands are issued. SelectClauses where_clauseV1 Not implemented- EventId / ConditionId Original ByteString Not exposed
Best Practices
- To capture an event, use
subscribe_events, Do not attempt to sendEventFilter - The convention of explicitly listing fields is retained; once the filter entry point is available, it can be reused directly.
- When the alarm panel requires ConditionId, first use
event_type+source_nameto locate it, then use the Acknowledge Method for the alarmcallnode.
Cross-Language Comparison
| C# | Python | Java | C++ | Rust | C |
|---|---|---|---|---|---|
| EventFilter | EventFilter | EventFilter | EventFilter | EventFilter | DarraUa_EventFilter |
| SimpleAttributeOperand | SimpleAttributeOperand | SimpleAttributeOperand | SimpleAttributeOperand | SimpleAttributeOperand | DarraUa_SimpleAttributeOperand |