Esempio n. 1
0
        private static void Main(string[] args)
        {
            //var commPort = new SerialPort("COM11", 38400);
            var commPort = new IrDAPort();

            using (var client = new HoneywellClient(commPort, InstrumentType.MiniMax))
            {
                try
                {
                    client.Connect(10).Wait();

                    while (true) // Loop indefinitely
                    {
                        try
                        {
                            System.Console.WriteLine("Enter item number to read or exit:");
                            var line = System.Console.ReadLine();
                            if (line == "exit") // Check string
                            {
                                break;
                            }

                            int item;
                            if (int.TryParse(line, out item))
                            {
                                var itemValue = client.GetItemValue(item).Result;
                                System.Console.WriteLine($"{itemValue}");
                            }
                            else if (line.Contains(","))
                            {
                                var items      = line.Split(',').Select(int.Parse);
                                var itemValues = client.GetItemValues(items).Result;

                                itemValues.ForEach(System.Console.WriteLine);
                            }
                            else
                            {
                                System.Console.WriteLine("Didn't understand that.");
                            }
                        }
                        catch (AggregateException ex)
                        {
                            System.Console.WriteLine(ex.Flatten().InnerException.Message);
                        }
                    }
                }
                catch (AggregateException ex)
                {
                    System.Console.WriteLine(ex.Flatten().Message);
                }
            }

            System.Console.ReadLine();
        }
 private async Task SetupCommPort()
 {
     await Task.Run(() =>
     {
         if (InstrumentCommunicator == null)
         {
             var commPort = new SerialPort(SettingsManager.SettingsInstance.InstrumentCommPort,
                                           SettingsManager.SettingsInstance.InstrumentBaudRate);
             InstrumentCommunicator = new HoneywellClient(commPort, InstrumentType.MiniMax);
             //var commPort = Communications.CreateCommPortObject(SettingsManager.SettingsInstance.InstrumentCommPort, SettingsManager.SettingsInstance.InstrumentBaudRate);
             //InstrumentCommunicator = new InstrumentCommunicator(_container.Resolve<IEventAggregator>(), commPort, InstrumentType.MiniMax);
         }
     });
 }