Event Subscription
OPC UA events (Alarms & Conditions) are subscribed to through SubscribeEvents. These are OPC UA protocol events and are not the same thing as the SDK's lifecycle events ua.Events.*.
ua.SubscribeEvents(...)— OPC UA Protocol Events (Alarms / Conditions, Server-Side Push Notifications, This Section)ua.Events.*— SDK Life Cycle Events (Session / Subscription Lifecycle, Protocol-Independent)
Signature
public OpcUaEventSubscription SubscribeEvents(
string nodeId = null,
OpcUaSubscription existingSubscription = null);
| Parameters | Default | Note |
|---|---|---|
| nodeId | null (Server, i=2253) | Event Source Node |
| existingSubscription | null | Reuse an existing subscription; if null, SDK create a new subscription 1000 ms with the specified publication interval; the lifecycle of the subscription is determined by the returned EventSubscription. |
OpcUaEventSubscription
| Members | Note |
|---|---|
| EventArrived | EventReachCallback (EventHandler<EventArrivedEventArgs>) |
| Subscribe(objectNodeId, filter) | After deleting the old Event, reattach one MI to the target node; the filter is currently not active—see EventFilter |
| Dispose() | Remove this event MI; if a subscription was created above, it will also be deleted. |
EventArrivedEventArgs
| Field | Type | Note |
|---|---|---|
| Severity | ushort | Severity (the higher the number, the more severe) |
| Message | string | Event Text |
| SourceName | string | Event Source Name |
| Time | DateTime? | Time of the incident |
| EventType | string | Event Type NodeId |
Usage
Default Subscription Server Node
using var evSub = ua.SubscribeEvents();
evSub.EventArrived += (s, e) =>
{
Console.WriteLine($"[{e.Severity}] {e.SourceName}: {e.Message}");
Console.WriteLine($" EventType={e.EventType} Time={e.Time}");
};
Thread.Sleep(TimeSpan.FromMinutes(5));
Subscribe to events from a specific node
using var evSub = ua.SubscribeEvents("ns=2;s=Line1"); // Line1 It must be EventNotifier
Reusing an Existing Subscription Container
using var sub = ua.CreateSubscription(500);
sub.Add("ns=2;s=Counter"); // Data Subscriptions
// Attach the Event to MI the same container
using var evSub = ua.SubscribeEvents("ns=2;s=Line1", existingSubscription: sub);
// evSub.Dispose Remove only the Event MI; do not destroy the sub.
EventNotifier
Only nodes with a non-0 EventNotifier attribute (12) can generate events. By default, Server(i=2253) acts as an EventNotifier. Whether a custom node can act as an event source depends on the server implementation.
EventFilter (Advanced)
The OPC UA EventFilter is meant to filter and select fields by EventType / Severity / SourceNode. The EventFilter / SimpleAttributeOperand types already exist, but SubscribeEvents does not accept filter conditions; once you hold an OpcUaEventSubscription you can call ev.Subscribe(objectNodeId, filter) to attach one.
The filter is not currently active — The filter is not sent to the server; events are still pushed in full, with a default of 5 fields. For details, see EventFilter。
Alarm Operations (Acknowledge / Confirm)
After receiving an AlarmConditionType event, use a dedicated alarm API handler; do not write the method manually NodeId:
public StatusCode Acknowledge(string conditionId, byte[] eventId, string comment = "");
public StatusCode Confirm(string conditionId, byte[] eventId, string comment = "");
public StatusCode AddComment(string conditionId, byte[] eventId, string comment);
public StatusCode EnableCondition(string conditionId);
public StatusCode DisableCondition(string conditionId);
public StatusCode ConditionRefresh(uint subscriptionId);
public StatusCode ConditionRefresh2(uint subscriptionId, uint monitoredItemId);
public StatusCode OneShotShelve(string shelvingStateId);
public StatusCode TimedShelve(string shelvingStateId, double durationMs);
public StatusCode Unshelve(string shelvingStateId);
If the input parameter is eventId empty or null, return an error status code directly (without throwing an exception); in both DarraOpcUa cases, return StatusCode.
/ conditionId
Acknowledge
/ Confirm
/ AddComment
Needs conditionId
(condition example NodeId
) and eventId
(ByteString
), but EventArrivedEventArgs
only has Severity / Message / SourceName / Time / EventType
Five fields, These two items cannot be accessed within the event callback; custom settings do not SelectClauses take effect either (see EventFilter). In other words, the alarm method familyCurrently, it is not possible to be triggered directly by received events., The business side needs to obtain this through a separate method ConditionId / EventId (e.g., using a browse conditional node based on fixed rules).