Skip to main content

Event Subscription

Events on the OPC UA Server (alarms, status changes, custom messages) can be subscribed to through EventMonitoredItem.

Further Reading

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:

FieldTypeNote
SeverityushortSeverity 1-1000, with 1000 being the highest
MessagestringEvent Text
SourceNamestringEvent Source Name
TimeDateTime?Time of the incident
EventTypestringEvent 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);
Container Ownership

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-independent
  • SubscribeEvents(...) — OPC UA Agreement Events (Alarms & Conditions), Server-Side Push Notifications