Event Subscription
Events on the OPC UA Server (alarms, status changes, custom messages) can be subscribed to through EventMonitoredItem.
- Related Standards — AC Alarms & Conditions — Severity / EventType Concept
- Basics — Subscription Models — Subscription Container
- C# SDK Event Subscription
The Simplest Event Subscription
using var evSub = ua.SubscribeEvents(); // Default Server node (i=2253)
evSub.EventArrived += (s, e) =>
{
Console.WriteLine($"[{e.Severity}] {e.SourceName}: {e.Message}");
Console.WriteLine($" Type={e.EventType} Time={e.Time}");
};
Thread.Sleep(TimeSpan.FromMinutes(5));
EventArrived Fields in the callback:
| Field | Type | Note |
|---|---|---|
| Severity | ushort | Severity 1-1000, with 1000 being the highest |
| Message | string | Event Text |
| SourceName | string | Event Source Name |
| Time | DateTime? | Time of the incident |
| EventType | string | Event Type NodeId |
Subscribe to events from a specific node
Certain nodes (such as a production line) are themselves EventNotifiers and can be subscribed to individually:
using var evSub = ua.SubscribeEvents("ns=2;s=Line1");
Reusing an Existing Subscription Container
If you already have a subscription running a data subscription and want to MI attach the event to the same container:
using var sub = ua.CreateSubscription(500);
// Data Subscriptions
sub.Add("ns=2;s=Counter");
// Reusing the Same Container for Event Subscriptions
using var evSub = ua.SubscribeEvents("ns=2;s=Line1", existingSubscription: sub);
When reusing a container, evSub.Dispose only remove your own events MI; do not destroy the container. Otherwise (default: null), evSub creates a new 1000ms container internally, which is owned by evSub.
Event Filtering
Currently, all event types are subscribed to by the SDK by default (BaseEventType). To filter by EventType / Severity, you need to construct EventFilter — see SDK "Event" Section of the Document.
Differences from the Unified Event Channel
Be sure to distinguish between these two concepts:
ua.Events.*— SDK Internal Unified event channel (Connected/Disconnected/KeepAlive, etc.), OPC UA protocol-independentSubscribeEvents(...)— OPC UA Agreement Events (Alarms & Conditions), Server-Side Push Notifications