using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; using System.Threading; using OpcLabs.EasyOpc; using OpcLabs.EasyOpc.DataAccess; namespace ConsoleApplication1 { class Program { static string filePath; static ulong counter = 0; // Counter how many times EasyDAclient has been instantiated static void Main(string[] args) { filePath = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData); // Get file path to C:\ProgramData\ filePath = filePath + @"\Counter.txt"; ServerDescriptor server = new ServerDescriptor("", "OPCLabs.KitServer.2"); DAItemDescriptor item = new DAItemDescriptor("Demo.Ramp"); EasyDAClient.SharedParameters.Topic.SlowdownWeight = 0.0f; EasyDAClient.SharedParameters.Topic.SpeedupWeight = 0.0f; while (true) { EasyDAClient client = new EasyDAClient(); client.InstanceParameters.UpdateRates.ReadAutomatic = Timeout.Infinite; client.InstanceParameters.UpdateRates.WriteAutomatic = Timeout.Infinite; counter++; // Count how many times EasyDAClient has been instantiated Write(); // Write counter to file DAVtq vtq = client.ReadItem(server, item); Console.WriteLine("{0} {1} {2}", vtq.Timestamp.ToString("yyyy:mm:dd HH:MM:ss.fff"), vtq.Value, vtq.Quality.QualityChoiceBitField); client.Dispose(); Thread.Sleep(500); } } static void Write() { try { StreamWriter sw = new StreamWriter(filePath); sw.WriteLine("{0}\t\t{1}", DateTime.Now.ToString("yyyy:mm:dd HH:MM:ss.fff"), counter); sw.Close(); } catch { // Ignore exception. Couldn't write to file. } } } }