Multi-Source Subscription Collection
Simultaneously monitor multiple data points—including temperature, pressure, flow rate, and counters—and push data only when there are changes on the server, so as not to waste bandwidth. Use C# Example.
Sample Configuration
- Automatic Node Discovery + Fall CSV → End-to-end data collection to CSV
- 1000+ nodes → Mass Surveillance
Complete Code
using DarraOpcUa_Client;
using System;
using System.Threading;
class Program
{
static void Main()
{
// Replace with an on-site PLC industrial PC IP
const string endpoint = "opc.tcp://192.168.1.100:4840";
// Nodes are formatted as ID ns=2;s=<DBor GVLpath>.<variable name>; the actual names are subject to the identifiers used in the project PLC .
var nodes = new[]
{
"ns=2;s=Boiler1.Temperature",
"ns=2;s=Boiler1.Pressure",
"ns=2;s=Boiler1.FlowRate",
"ns=2;s=Line1.Counter",
};
// 1. Connection
using var ua = new DarraOpcUa(endpoint);
ua.Connect();
Console.WriteLine($"[OK] 已连接 {endpoint}");
// 2. Create a subscription + set up a callback
using var sub = ua.CreateSubscription(publishingIntervalMs: 500);
sub.DataChanged += (s, e) =>
Console.WriteLine($"{DateTime.Now:HH:mm:ss.fff} {e.NodeId,-32} = {e.ValueString,-12} [{e.Status}]");
// 3. Add Monitoring Items in Bulk
var results = sub.AddMany(nodes);
for (int i = 0; i < nodes.Length; i++)
Console.WriteLine($" add {nodes[i]} -> {results[i].status}");
// 4. Continue receiving push notifications until you press Ctrl+C
Console.WriteLine("\n等待数据推送, 按 Ctrl+C 停止...\n");
Thread.Sleep(Timeout.Infinite);
}
}
Code Highlights
publishingIntervalMsThis refers to the interval between server-side push batches, not the sampling interval; if there are no changes, nothing is sent. NotificationMessageDataChangedTriggered on the Publish thread; WinForms usesControl.BeginInvoke/ WPF usesDispatcher.BeginInvoketo switch back to UI the threadAddManyis 1 RPC; the loop's per-nodeAddcalls are 1 RPC each.subThis is requiredusing; otherwise, the server will retain the subscription until it timessessionTimeoutMsout.
Important Notes
- The "Subscribe Publish" model uses server-side push; as long as the client's session remains active, it continues to receive updates without needing to send its own heartbeats.
subThis is requiredusing; otherwise, the server will retain the subscription until itsessionTimeoutMstimes out.- For large-volume (1000+) monitoring, please see Examples of Mass Surveillance.