// This example shows how change the percent deadband of an existing subscription.
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
// OPC client and subscriber examples in C# on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-CSharp .
// Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
// a commercial license in order to use Online Forums, and we reply to every post.
using System;
using System.Threading;
using OpcLabs.BaseLib.ComInterop;
using OpcLabs.EasyOpc.DataAccess.OperationModel;
using OpcLabs.EasyOpc.DataAccess;
namespace DocExamples.DataAccess._EasyDAClient
{
partial class ChangeItemSubscription
{
public static void PercentDeadband()
{
// Instantiate the client object.
using (var client = new EasyDAClient())
{
client.ItemChanged += client_ItemChanged_PercentDeadband;
Console.WriteLine("Subscribing with 10% deadband...");
int handle = client.SubscribeItem("", "OPCLabs.KitServer.2", "Simulation.Ramp 0:100 (10 s)",
VarTypes.Empty, requestedUpdateRate:100, percentDeadband:10.0f, state:null);
Console.WriteLine("Waiting for 10 seconds...");
Thread.Sleep(10 * 1000);
Console.WriteLine("Changing subscription to 0% deadband...");
client.ChangeItemSubscription(handle, new DAGroupParameters(100, 0.0f));
Console.WriteLine("Waiting for 10 seconds...");
Thread.Sleep(10 * 1000);
Console.WriteLine("Unsubscribing...");
client.UnsubscribeAllItems();
Console.WriteLine("Waiting for 10 seconds...");
Thread.Sleep(10 * 1000);
}
}
// Item changed event handler
static void client_ItemChanged_PercentDeadband(object sender, EasyDAItemChangedEventArgs e)
{
if (e.Succeeded)
Console.WriteLine(e.Vtq);
else
Console.WriteLine("*** Failure: {0}", e.ErrorMessageBrief);
}
}
}
' This example shows how change the percent deadband of an existing subscription.
'
' Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
' OPC client and subscriber examples in VB.NET on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-VBNET .
' Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
' a commercial license in order to use Online Forums, and we reply to every post.
Imports System.Threading
Imports OpcLabs.BaseLib.ComInterop
Imports OpcLabs.EasyOpc.DataAccess
Namespace DataAccess._EasyDAClient
Partial Friend Class ChangeItemSubscription
Public Shared Sub PercentDeadband()
Using client = New EasyDAClient()
AddHandler client.ItemChanged, AddressOf client_ItemChanged_PercentDeadband
Console.WriteLine("Subscribing with 10% deadband...")
Dim handle As Integer = client.SubscribeItem("", "OPCLabs.KitServer.2", "Simulation.Ramp 0:100 (10 s)", VarTypes.Empty, 100, 10.0F, Nothing)
Console.WriteLine("Waiting for 10 seconds...")
Thread.Sleep(10 * 1000)
Console.WriteLine("Changing subscription to 0% deadband...")
client.ChangeItemSubscription(handle, New DAGroupParameters(100, 0.0F))
Console.WriteLine("Waiting for 10 seconds...")
Thread.Sleep(10 * 1000)
Console.WriteLine("Unsubscribing...")
client.UnsubscribeAllItems()
Console.WriteLine("Waiting for 10 seconds...")
Thread.Sleep(10 * 1000)
End Using
End Sub
' Item changed event handler
Private Shared Sub client_ItemChanged_PercentDeadband(ByVal sender As Object, ByVal e As EasyDAItemChangedEventArgs)
If e.Succeeded Then
Console.WriteLine(e.Vtq)
Else
Console.WriteLine("*** Failure: {0}", e.ErrorMessageBrief)
End If
End Sub
End Class
End Namespace
# This example shows how change the percent deadband of an existing subscription.
#
# 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 .
# Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
# a commercial license in order to use Online Forums, and we reply to every post.
# 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 *
# Item changed event handler
def itemChanged(sender, e):
if e.Succeeded:
print(e.Vtq)
else:
print('*** Failure: ', e.ErrorMessageBrief, sep='')
# Instantiate the client object.
client = EasyDAClient()
client.ItemChanged += itemChanged
print('Subscribing item with 10% deadband...')
handle = IEasyDAClientExtension.SubscribeItem(client, '', 'OPCLabs.KitServer.2', 'Simulation.Ramp 0:100 (10 s)',
VarType(VarTypes.Empty), requestedUpdateRate=50, percentDeadband=10.0,
state=None)
print('Processing item change notifications for 10 seconds...')
time.sleep(10)
print('Changing item subscription to 0% deadband...')
IEasyDAClientExtension.ChangeItemSubscription(client, handle, DAGroupParameters(50, 0.0))
print('Processing item change notifications for 10 seconds...')
time.sleep(10)
print('Unsubscribing item...')
IEasyDAClientExtension.UnsubscribeItem(client, handle)
print('Waiting for 10 seconds...')
time.sleep(10)
client.ItemChanged -= itemChanged
print('Finished.')