Beispiel #1
0
 static void Main()
 {
     Application.EnableVisualStyles();
     Application.SetCompatibleTextRenderingDefault(false);
     try
     {
         //Close app if user doesn't connect to serial port
         if (!connectToDevice())
         {
             return;
         }
         Application.Run(new Form1());
     }
     finally
     {
         Uart.disconnect();
     }
 }
Beispiel #2
0
        static bool connectToDevice()
        {
            var portDlg = new PortDialog();

            //Loop until a successful connection is made or the user gives up
            while (DialogResult.OK == portDlg.ShowDialog())
            {
                try
                {
                    Uart.connect(portDlg.PortName);
                    return(true);
                }
                catch (UnauthorizedAccessException ex)
                {
                    MessageBox.Show(ex.Message + "\nClose the serial monitor darn it!");
                }
                catch (Exception ex) when(ex is IOException || ex is ArgumentException)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            return(false);
        }