// Shows how to observe OPC UA data changes with a specified absolute deadband.
using OpcLabs.EasyOpc.UA.Reactive;
using System;
using System.Threading;
using OpcLabs.EasyOpc.UA;
using OpcLabs.EasyOpc.UA.OperationModel;
namespace ReactiveDocExamples
{
namespace _UADataChangeNotificationObservable
{
partial class Subscribe
{
public static void AbsoluteDeadband()
{
// Define which server we will work with.
UAEndpointDescriptor endpointDescriptor =
"opc.tcp://opcua.demo-this.com:51210/UA/SampleServer";
// or "http://opcua.demo-this.com:51211/UA/SampleServer" (currently not supported)
// or "https://opcua.demo-this.com:51212/UA/SampleServer/"
const double absoluteDeadband = 50;
Console.WriteLine($"Creating observable with absolute deadband {absoluteDeadband}...");
var attributeArguments = new UAAttributeArguments(
endpointDescriptor,
"nsu=http://test.org/UA/Data/ ;i=11194"); // /Data.Dynamic.AnalogScalar.Int32Value
var monitoredItemArguments = new UAMonitoredItemArguments(
attributeArguments,
new UAMonitoringParameters(samplingInterval: 1000, dataChangeFilter: absoluteDeadband));
UADataChangeNotificationObservable<int> observable =
UADataChangeNotificationObservable.Create<int>(monitoredItemArguments);
Console.WriteLine("Subscribing...");
using (observable.Subscribe(e => Console.WriteLine(
(e.Exception is null) ? e.AttributeData.ToString() : e.Exception.GetBaseException().ToString())))
{
Console.WriteLine("Waiting for 10 seconds...");
Thread.Sleep(10*1000);
Console.WriteLine("Unsubscribing...");
}
Console.WriteLine("Waiting for 2 seconds...");
Thread.Sleep(2 * 1000);
}
}
}
}