Subscription
OpcUaSubscription It is a subscription container that manages a set of MonitoredItem (MI), and provides DataChanged events.
DataChangeFilter: (Dead Zone/Trigger Filtering),EventFilter (Custom Event Fields and Filtering),SetTriggering and (Trigger Linkage)The type exists but will not be sent to the server at this time — Behavior after invocation is equivalent to not applying any filtering: Data/events are reported in full by default, and each item is returned via Triggering BadNotSupported. Read this before using. DataChangeFilter / EventFilter / Triggering Links "Current Behavior."
- To create a subscription, please refer to Create a Subscription.
- Add / Add in Bulk MonitoredItem Please refer to Add MonitoredItem.
- Modify publishingInterval / lifetime / sampling—please refer to Modify.
- For "Disabled / Sampling / Reporting," please refer to SetMonitoringMode.
- To request a resend for a specific SeqNo, please refer to Republish.
- For information on the DataChanged field and the threading model, please refer to DataChanged Event.
- For OPC UA alarms and event subscriptions, see Event Subscription.
One-Minute Overview
// Create
using var sub = ua.CreateSubscription(publishingIntervalMs: 500);
// Data Change Callback
sub.DataChanged += (s, e) =>
Console.WriteLine($"{e.NodeId} = {e.ValueString} ({e.Status})");
// Add MI
uint h1 = sub.Add("ns=2;s=Counter");
uint h2 = sub.Add("ns=2;s=Temperature");
// Add in Bulk
var nodes = Enumerable.Range(1, 100).Select(i => $"ns=2;s=T{i}").ToList();
var results = sub.AddMany(nodes); // IReadOnlyList<(uint handle, StatusCode status)>
// Change the sampling interval MI for a single item
sub.ModifyItem(h2, samplingIntervalMs: 100);
// Pause / Resume Collection
sub.SetMode(h2, MonitoringMode.Disabled);
sub.SetMode(h2, MonitoringMode.Reporting);
// Remove
sub.Remove(h1);
Subscribe to Lifecycle Events
Subscription Lifecycle FlowUnified Event Channelua.Events.Any (OpcUaEventEntry, filter Category by ):
ua.Events.Any += (s, e) =>
{
if (e.Category == OpcUaEventCategory.SubscriptionCreated) { /* ... */ }
if (e.Category == OpcUaEventCategory.MonitoredItemAdded) { /* ... */ }
if (e.Category == OpcUaEventCategory.SubscriptionLost) { /* ... */ }
};
ua.Events There is also a strongly typed channel SubscriptionLost / SubscriptionRestored, along with the channel filtered Category by as shown aboveMutually Independent, For more details, see Subscription Resumes Automatically.
For more information, see Session Events.