// This example shows how change the percent deadband of an existing subscription.
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.
Imports System.Threading
Imports OpcLabs.BaseLib.ComInterop
Imports OpcLabs.EasyOpc.DataAccess
Namespace DocExamples.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