// This example shows how subscribe to changes of multiple items with percent deadband.
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
using System;
using System.Threading;
using OpcLabs.BaseLib.ComInterop;
using OpcLabs.EasyOpc.DataAccess;
using OpcLabs.EasyOpc.DataAccess.OperationModel;
namespace DocExamples.DataAccess._EasyDAClient
{
partial class SubscribeMultipleItems
{
public static void PercentDeadband()
{
// Instantiate the client object.
using (var client = new EasyDAClient())
{
client.ItemChanged += client_PercentDeadband_ItemChanged;
Console.WriteLine("Subscribing with different percent deadbands...");
client.SubscribeMultipleItems(
new[] {
new DAItemGroupArguments("", "OPCLabs.KitServer.2", "Simulation.Ramp 0:100 (10 s)",
VarTypes.Empty, requestedUpdateRate:100, percentDeadband:10.0f, null),
new DAItemGroupArguments("", "OPCLabs.KitServer.2", "Simulation.Ramp 0:100 (1 min)",
VarTypes.Empty, requestedUpdateRate:100, percentDeadband:5.0f, null),
});
Console.WriteLine("Processing item changed events for 1 minute...");
Thread.Sleep(60 * 1000);
}
}
// Item changed event handler
static void client_PercentDeadband_ItemChanged(object sender, EasyDAItemChangedEventArgs e)
{
if (e.Succeeded)
Console.WriteLine("{0}: {1}", e.Arguments.ItemDescriptor.ItemId, e.Vtq);
else
Console.WriteLine("{0} *** Failure: {1}", e.Arguments.ItemDescriptor.ItemId, e.ErrorMessageBrief);
}
}
}
# This example shows how subscribe to changes of multiple items with percent deadband.
#
# Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
# OPC client and subscriber examples in Python on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-Python .
# The QuickOPC package is needed. Install it using "pip install opclabs_quickopc".
import opclabs_quickopc
import time
# Import .NET namespaces.
from OpcLabs.BaseLib.ComInterop import *
from OpcLabs.EasyOpc.DataAccess import *
from OpcLabs.EasyOpc.DataAccess.OperationModel import *
# Item changed event handler.
def itemChanged(sender, e):
if e.Succeeded:
print(e.Arguments.ItemDescriptor.ItemId, ': ', e.Vtq, sep='')
else:
print(e.Arguments.ItemDescriptor.ItemId, ' *** Failure: ', e.ErrorMessageBrief, sep='')
# Instantiate the client object.
client = EasyDAClient()
client.ItemChanged += itemChanged
print('Subscribing item changes with different percent deadbands...')
IEasyDAClientExtension.SubscribeMultipleItems(client, [
DAItemGroupArguments('', 'OPCLabs.KitServer.2', 'Simulation.Ramp 0:100 (10 s)',
VarType(VarTypes.Empty), 100, 10.0, None),
DAItemGroupArguments('', 'OPCLabs.KitServer.2', 'Simulation.Ramp 0:100 (1 min)',
VarType(VarTypes.Empty), 100, 5.0, None),
])
print('Processing item change notifications for 1 minute...')
time.sleep(60)
print('Unsubscribing all items...')
client.UnsubscribeAllItems()
client.ItemChanged -= itemChanged
print('Finished.')
' This example shows how subscribe to changes of multiple items with percent deadband.
'
' Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
Imports System.Threading
Imports OpcLabs.BaseLib.ComInterop
Imports OpcLabs.EasyOpc.DataAccess
Imports OpcLabs.EasyOpc.DataAccess.OperationModel
Namespace DataAccess._EasyDAClient
Partial Friend Class SubscribeMultipleItems
Public Shared Sub PercentDeadband()
' Instantiate the client object.
Using client = New EasyDAClient()
AddHandler client.ItemChanged, AddressOf client_PercentDeadband_ItemChanged
Console.WriteLine("Subscribing with different percent deadbands...")
client.SubscribeMultipleItems(New DAItemGroupArguments() {
New DAItemGroupArguments("", "OPCLabs.KitServer.2", "Simulation.Ramp 0:100 (10 s)",
VarTypes.Empty, requestedUpdateRate:=100, percentDeadband:=10.0F, Nothing),
New DAItemGroupArguments("", "OPCLabs.KitServer.2", "Simulation.Ramp 0:100 (1 min)",
VarTypes.Empty, requestedUpdateRate:=100, percentDeadband:=5.0F, Nothing)
})
Console.WriteLine("Processing item changed events for 1 minute...")
Thread.Sleep(60 * 1000)
End Using
End Sub
' Item changed event handler
Private Shared Sub client_PercentDeadband_ItemChanged(ByVal sender As Object, ByVal e As EasyDAItemChangedEventArgs)
If e.Succeeded Then
Console.WriteLine("{0}: {1}", e.Arguments.ItemDescriptor.ItemId, e.Vtq)
Else
Console.WriteLine("{0} *** Failure: {1}", e.Arguments.ItemDescriptor.ItemId, e.ErrorMessageBrief)
End If
End Sub
End Class
End Namespace