// This example shows how to create and use two isolated client objects, resulting in two separate connections to the target
// OPC DA server.
using System;
using System.Diagnostics;
using System.Threading;
using OpcLabs.EasyOpc.DataAccess;
using OpcLabs.EasyOpc.DataAccess.OperationModel;
namespace DocExamples.DataAccess._EasyDAClient
{
class Isolated
{
public static void Main1()
{
// Instantiate the client objects and make them isolated
var client1 = new EasyDAClient { Isolated = true };
var client2 = new EasyDAClient { Isolated = true };
// The callback is a local method the displays the value
void ItemChangedCallback(object sender, EasyDAItemChangedEventArgs eventArgs)
{
Debug.Assert(!(eventArgs is null));
Console.Write($"[{eventArgs.Arguments.State}] ");
if (eventArgs.Succeeded)
{
Debug.Assert(!(eventArgs.Vtq is null));
Console.WriteLine(eventArgs.Vtq.ToString());
}
else
Console.WriteLine("*** Failure: {0}", eventArgs.ErrorMessageBrief);
}
Console.WriteLine("Subscribing...");
client1.SubscribeItem("", "OPCLabs.KitServer.2", "Simulation.Random", 1000, ItemChangedCallback, state: 1);
client2.SubscribeItem("", "OPCLabs.KitServer.2", "Simulation.Random", 1000, ItemChangedCallback, state: 2);
Console.WriteLine("Processing item changed events for 10 seconds...");
Thread.Sleep(10 * 1000);
Console.WriteLine("Unsubscribing...");
client1.UnsubscribeAllItems();
client2.UnsubscribeAllItems();
Console.WriteLine("Waiting for 2 seconds...");
Thread.Sleep(2 * 1000);
}
}
}