Skip to main content

EventFilter — Custom Event Fields and Filters

Overview​

OPC UA Part 4 §7.18 EventFilter consists of two parts:

  • SelectClauses — Which fields to capture (corresponding to in order EventArrivedEventArgs)
  • WhereClause — Filter Criteria (ContentFilter Expression Tree) — Not currently available

Each SelectClause is a SimpleAttributeOperand (Part 4 §7.4.4.5):

FieldNote
TypeDefinitionIdEvent Type NodeId (e.g., i=2041 BaseEventType)
BrowsePathField path (e.g., ["Severity"] / ["EnabledState", "Id"])
AttributeIdProperty Id, Default Value
IndexRangeArray index range (usually null)

Regardless of whether data is transmitted or not EventFilter, only 5 fields are currently SDK subscribed to: ( Severity / Message / SourceName / Time / EventType see "Current Behavior" below).

API​

Class / FieldCategoryReading and WritingNote
EventFilterClass—Filter Housing
.SelectClausesPropertiesReading and WritingSimpleAttributeOperand[]
.WhereClausePropertiesReading and Writingstring, Not currently available; just leave it as null
SimpleAttributeOperandClass—Single-Field Definition
ev.Subscribe(objectNodeId, filter)MethodsWriteMI After deleting the old Event, reattach one to the target node (the filter is currently not active).

Code Example​

using DarraOpcUa_Client;

using var ua = new DarraOpcUa("opc.tcp://localhost:4840");
ua.Connect();

using var sub = ua.CreateSubscription(500);

// 1) Specify which fields to capture (default: 5 + 2 specific to alerts)
var filter = new EventFilter
{
SelectClauses = new[]
{
// Default: 5 fields
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" } },
// Alert-Specific
new SimpleAttributeOperand { TypeDefinitionId = "i=2782", BrowsePath = new[] { "ConditionId" } },
new SimpleAttributeOperand { TypeDefinitionId = "i=2915", BrowsePath = new[] { "ActiveState", "Id" } },
}
};

// 2) First create an event subscription, then recreate the event subscription for that node based on the filter
using var ev = ua.SubscribeEvents("i=2253", sub);
ev.Subscribe("i=2253", filter);

ev.EventArrived += (s, e) =>
{
// Event callbacks currently expose only 5 fixed fields; custom fields are not currently supported.
Console.WriteLine($"[{e.Time:HH:mm:ss}] sev={e.Severity} {e.SourceName}: {e.Message}");
};

Current Behavior (Important)​

Custom This definitely isn't working right SelectClauses now

ev.Subscribe(objectNodeId, filter)Will not send SelectClauses to the server, Be sure to use the default field:

  • Event Register MI as usual, SelectClauses Not issued
  • A post will be pushed under the "Info" category Diagnostic, indicating that it has reverted to the default 5 fields.
  • SoNeither the filter criteria nor the field selections are taking effect.: Whatever the server sends, that's EventArrived what you receive
  • Event callbacks always return 5 Severity / Message / SourceName / Time / EventType fields (EventArrivedEventArgs), and custom fields are not received.
  • WhereClause This is a string placeholder, None ContentFilter parsing; no conditional filtering is performed
  • Subscribe(objectNodeId, filter) First MI, the existing event will be removed, and then a new one will be attached to the target node; the object must already be subscribed to the container, otherwise an exception will be thrown InvalidOperationException; if the object is null objectNodeId, an exception will be thrown. ArgumentNullException

SelectClauses Quick Reference for Field Paths (Common EventType + BrowsePath)​

EventTypeBrowsePathMeaning
BaseEventType (i=2041)["EventId"]Unique Event ID (ByteString)
BaseEventType["EventType"]Event Type NodeId
BaseEventType["SourceName"]Trigger Source Name
BaseEventType["Time"]Event Time (UTC)
BaseEventType["Message"]Text Message
BaseEventType["Severity"]Severity 1-1000
ConditionType (i=2782)["ConditionId"]Conditions NodeId
ConditionType["ConditionName"]Condition Name
ConditionType["EnabledState", "Id"]Boolean: Enabled
AcknowledgeableConditionType (i=2881)["AckedState", "Id"]Bool: Has it been acknowledged?
AlarmConditionType (i=2915)["ActiveState", "Id"]Boolean: Is it activated?
AlarmConditionType["ShelvingState", "CurrentState"]LocalizedText Screened state

Best Practices​

  • Write a callback based on 5 fixed fields — Don't rely on it right now SelectClauses; even if you send it, it won't work.
  • We'll have to find another way to handle the "alarm" field (EventId / ConditionId / ActiveState). — These items are missing from the event callback, and ua.Acknowledge / Confirm needs to be conditionId + eventId; see Event Subscription Explanation of
  • Field Path Specifications for Reference — ["ActiveState", "Id"] is Bool, ["ActiveState"] is LocalizedText, once the filter takes effect, configure according to this table

Cross-Language Comparison​

C#PythonJavaC++RustC
EventFilterEventFilterEventFilterDef.FilterEventFilterEventFilterNot currently available
SimpleAttributeOperandSimpleAttributeOperandEventFilterDef.OperandSimpleAttributeOperandSimpleAttributeOperandNot currently available

Next Step​