// This example shows how to subscribe to changes of a monitored item with absolute deadband.
using System;
using OpcLabs.EasyOpc.UA;
using OpcLabs.EasyOpc.UA.OperationModel;
namespace UADocExamples._EasyUAClient
{
partial class SubscribeDataChange
{
public static void AbsoluteDeadband()
{
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/"
// Instantiate the client object and hook events
var client = new EasyUAClient();
client.DataChangeNotification += client_DataChangeNotification_AbsoluteDeadband;
const double absoluteDeadband = 50;
Console.WriteLine($"Subscribing with absolute deadband {absoluteDeadband}...");
// The UADataChangeFilter has an implicit conversion from Double, which creates a filter with the specified
// absolute deadband.
client.SubscribeDataChange(endpointDescriptor,
"nsu=http://test.org/UA/Data/ ;i=11194", // /Data.Dynamic.AnalogScalar.Int32Value
samplingInterval:1000,
dataChangeFilter: absoluteDeadband);
Console.WriteLine("Processing data change events for 20 seconds...");
System.Threading.Thread.Sleep(20 * 1000);
Console.WriteLine("Unsubscribing...");
client.UnsubscribeAllMonitoredItems();
Console.WriteLine("Waiting for 5 seconds...");
System.Threading.Thread.Sleep(5 * 1000);
}
static void client_DataChangeNotification_AbsoluteDeadband(object sender, EasyUADataChangeNotificationEventArgs e)
{
// Display value
if (e.Succeeded)
Console.WriteLine("Value: {0}", e.AttributeData.Value);
else
Console.WriteLine("*** Failure: {0}", e.ErrorMessageBrief);
}
}
}
# This example shows how to subscribe to changes of a monitored item with absolute deadband.
# The QuickOPC package is needed. Install it using "pip install opclabs_quickopc".
import opclabs_quickopc
import time
# Import .NET namespaces.
from OpcLabs.EasyOpc.UA import *
from OpcLabs.EasyOpc.UA.OperationModel import *
def dataChangeNotification(sender, e):
# Display value.
if e.Succeeded:
print('Value: ', e.AttributeData.Value, sep='')
else:
print('*** Failure: ', e.ErrorMessageBrief, sep='')
endpointDescriptor = UAEndpointDescriptor('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/'
# Instantiate the client object and hook events.
client = EasyUAClient()
client.DataChangeNotification += dataChangeNotification
ABSOLUTE_DEADBAND = 50
print('Subscribing with absolute deadband ', ABSOLUTE_DEADBAND, '...', sep='')
IEasyUAClientExtension.SubscribeDataChange(client,
endpointDescriptor,
UANodeDescriptor('nsu=http://test.org/UA/Data/ ;i=11194'),
1000, # samplingInterval
UADataChangeFilter(ABSOLUTE_DEADBAND))
print('Processing data change events for 20 seconds...')
time.sleep(20)
print('Unsubscribing...')
client.UnsubscribeAllMonitoredItems()
print('Waiting for 5 seconds...')
time.sleep(5)
print('Finished.')