// This example shows how to subscribe to changes of multiple monitored items with percent deadband.
using System;
using OpcLabs.EasyOpc.UA;
using OpcLabs.EasyOpc.UA.OperationModel;
namespace UADocExamples._EasyUAClient
{
partial class SubscribeMultipleMonitoredItems
{
public static void PercentDeadband()
{
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_PercentDeadband;
Console.WriteLine("Subscribing with different percent deadbands...");
client.SubscribeMultipleMonitoredItems(new[]
{
new EasyUAMonitoredItemArguments(null, endpointDescriptor,
"nsu=http://test.org/UA/Data/ ;i=11194", // /Data.Dynamic.AnalogScalar.Int32Value
new UAMonitoringParameters(
samplingInterval:100,
new UADataChangeFilter(UADeadbandType.Percent, 5.0))),
new EasyUAMonitoredItemArguments(null, endpointDescriptor,
"nsu=http://test.org/UA/Data/ ;i=11218", // /Data.Dynamic.AnalogScalar.FloatValue
new UAMonitoringParameters(
samplingInterval:100,
new UADataChangeFilter(UADeadbandType.Percent, 10.0)))
});
Console.WriteLine("Processing monitored item changed events for 10 seconds...");
System.Threading.Thread.Sleep(10 * 1000);
Console.WriteLine("Unsubscribing...");
client.UnsubscribeAllMonitoredItems();
Console.WriteLine("Waiting for 5 seconds...");
System.Threading.Thread.Sleep(5 * 1000);
}
static void client_DataChangeNotification_PercentDeadband(object sender, EasyUADataChangeNotificationEventArgs e)
{
// Display value
if (e.Succeeded)
Console.WriteLine("{0}: {1}", e.Arguments.NodeDescriptor, e.AttributeData.Value);
else
Console.WriteLine("{0} *** Failure: {1}", e.Arguments.NodeDescriptor, e.ErrorMessageBrief);
}
}
}
# This example shows how to subscribe to changes of multiple monitored items with percent 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(e.Arguments.NodeDescriptor, ': ', e.AttributeData.Value, sep='')
else:
print(e.Arguments.NodeDescriptor, ' *** 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
print('Subscribing with different percent deadbands...')
client.SubscribeMultipleMonitoredItems([
EasyUAMonitoredItemArguments(
None,
endpointDescriptor,
UANodeDescriptor('nsu=http://test.org/UA/Data/ ;i=11194'),
UAMonitoringParameters(
100, # samplingInterval
UADataChangeFilter(UADeadbandType.Percent, 5.0))),
EasyUAMonitoredItemArguments(
None,
endpointDescriptor,
UANodeDescriptor('nsu=http://test.org/UA/Data/ ;i=11218'),
UAMonitoringParameters(
100, # samplingInterval
UADataChangeFilter(UADeadbandType.Percent, 10.0))),
])
print('Processing data change events for 10 seconds...')
time.sleep(10)
print('Unsubscribing...')
client.UnsubscribeAllMonitoredItems()
print('Waiting for 5 seconds...')
time.sleep(5)
print('Finished.')