// This example shows how change the update rate of multiple existing subscriptions.
using System;
using System.Threading;
using OpcLabs.EasyOpc.DataAccess;
using OpcLabs.EasyOpc.DataAccess.OperationModel;
namespace DocExamples.DataAccess._EasyDAClient
{
class ChangeMultipleItemSubscriptions
{
public static void Main1()
{
// Instantiate the client object.
using (var client = new EasyDAClient())
{
client.ItemChanged += client_ItemChanged;
Console.WriteLine("Subscribing...");
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("Waiting for 10 seconds...");
Thread.Sleep(10 * 1000);
Console.WriteLine("Changing subscriptions...");
client.ChangeMultipleItemSubscriptions(new[]
{
new DAHandleGroupArguments(handleArray[0], 100),
new DAHandleGroupArguments(handleArray[1], 100)
});
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(object sender, EasyDAItemChangedEventArgs e)
{
if (e.Succeeded)
Console.WriteLine(e.Vtq);
else
Console.WriteLine($"*** Failure: {e.ErrorMessageBrief}");
}
}
}