private void ConnectArduino() { try { string Port = comPortList.GetItemText(comPortList.SelectedItem); ArduinoPort.PortName = Port; ArduinoPort.Open(); connected = true; ConnectBtn.BackColor = Color.Crimson; ConnectBtn.Text = "DISCONNECT"; StateLabel.Text = "CONNECTED"; StateLabel.ForeColor = Color.LimeGreen; } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
static bool check_connection() { if (!ArduinoPort.IsOpen) { try { ArduinoPort.Open(); ArduinoPort.WriteLine("T"); ArduinoPort.Close(); } catch { MessageBox.Show("There was an error. Please make sure that the correct port was selected, and that the device is plugged in."); return(false); } return(true); } else { return(true); } }
public ArduinoForm() { InitializeComponent(); ArduinoPort.Open(); }