Пример #1
0
        private void Update()
        {
            bool   success = false;
            string port    = null;
            int    attempt = 0;

            while (true)
            {
                attempt++;
                Thread.Sleep(updateTimeout);
                System.Console.WriteLine($"[{DateTime.Now.ToString("HH':'mm':'ss'.'fffffff")}] [UPDATER] !! attempt {attempt}...");
                try
                {
                    if (transport == null || messenger == null || !transport.IsConnected())
                    {
                        //messenger?.Disconnect();
                        messenger?.Dispose();
                        messenger = null;
                        //transport?.Disconnect();
                        transport?.Dispose();
                        transport = null;

                        port      = AutodetectArduinoPort();
                        transport = GetTransport(port);
                        messenger = GetMessenger(transport);
                    }
                    if (transport.IsConnected())
                    {
                        success = true;
                    }
                }
                catch (Exception e)
                {
                    System.Console.WriteLine($"[{DateTime.Now.ToString("HH':'mm':'ss'.'fffffff")}] [UPDATER] !! {e}");
                    success = false;
                }
                if (success)
                {
                    System.Console.WriteLine($"[{DateTime.Now.ToString("HH':'mm':'ss'.'fffffff")}] [UPDATER] !! connected at port {port} at {attempt} attempt");
                    break;
                }
            }
        }
Пример #2
0
 public bool IsConnected()
 {
     return(_serialTransport.IsConnected());
 }