// This example shows how subscribe to changes of multiple items, and unsubscribe from one of them.
using System;
using System.Threading;
using OpcLabs.EasyOpc.DataAccess;
using OpcLabs.EasyOpc.DataAccess.OperationModel;
namespace DocExamples.DataAccess._EasyDAClient
{
class UnsubscribeItem
{
public static void Main1()
{
// Instantiate the client object.
using (var client = new EasyDAClient())
{
client.ItemChanged += client_ItemChanged;
int[] handleArray = client.SubscribeMultipleItems(
new[] {
new DAItemGroupArguments("", "OPCLabs.KitServer.2", "Simulation.Random", 1000, null),
new DAItemGroupArguments("", "OPCLabs.KitServer.2", "Trends.Ramp (1 min)", 1000, null),
new DAItemGroupArguments("", "OPCLabs.KitServer.2", "Trends.Sine (1 min)", 1000, null),
new DAItemGroupArguments("", "OPCLabs.KitServer.2", "Simulation.Register_I4", 1000, null)
});
Console.WriteLine("Processing item changed events for 30 seconds...");
Thread.Sleep(30 * 1000);
Console.WriteLine("Unsubscribing from the first item...");
client.UnsubscribeItem(handleArray[0]);
Console.WriteLine();
Console.WriteLine("Processing item changed events for 30 seconds...");
Thread.Sleep(30 * 1000);
}
}
// Item changed event handler
static void client_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, and unsubscribe from one of them.
Imports System.Threading
Imports OpcLabs.EasyOpc.DataAccess
Imports OpcLabs.EasyOpc.DataAccess.OperationModel
Namespace DocExamples.DataAccess._EasyDAClient
Partial Friend Class UnsubscribeItem
Shared Sub Main1()
Using client = New EasyDAClient()
AddHandler client.ItemChanged, AddressOf client_ItemChanged
Dim handleArray = client.SubscribeMultipleItems(
New DAItemGroupArguments() _
{ _
New DAItemGroupArguments("", "OPCLabs.KitServer.2", "Simulation.Random", 1000, Nothing),
New DAItemGroupArguments("", "OPCLabs.KitServer.2", "Trends.Ramp (1 min)", 1000, Nothing),
New DAItemGroupArguments("", "OPCLabs.KitServer.2", "Trends.Sine (1 min)", 1000, Nothing),
New DAItemGroupArguments("", "OPCLabs.KitServer.2", "Simulation.Register_I4", 1000, Nothing)
})
Console.WriteLine("Processing item changed events for 30 seconds...")
Thread.Sleep(30 * 1000)
Console.WriteLine("Unsubscribing from the first item...")
client.UnsubscribeItem(handleArray(0))
Console.WriteLine()
Console.WriteLine("Processing item changed events for 30 seconds...")
Thread.Sleep(30 * 1000)
End Using
End Sub
' Item changed event handler
Private Shared Sub client_ItemChanged(sender As Object, 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