private void DisconnectButton_Click(object sender, EventArgs e) { try { //if something goes wrong, close the ports that may be open SDMC1SerialPort.Close(); ArduinoSerialPort.Close(); //Change connection interaction SDMC1Port.Enabled = true; SDMC1BaudRate.Enabled = true; ArduinoPort.Enabled = true; ArduinoBaudRate.Enabled = true; ConnectButton.Enabled = true; DisconnectButton.Enabled = false; //Change controller interaction ArduinoSendText.Enabled = false; ArduinoSendButton.Enabled = false; SDMC1SendText.Enabled = false; SDMC1SendButton.Enabled = false; HomeButton.Enabled = false; ScanButton.Enabled = false; } catch (Exception error) { MessageText.Text = error.Message; } }
private void ConnectButton_Click(object sender, EventArgs e) { if (SDMC1BaudRate.SelectedItem == "" || SDMC1Port.SelectedItem == "" || ArduinoPort.SelectedItem == "" || ArduinoBaudRate.SelectedItem == "") { MessageText.Text = "Specify ports and baudrates"; } else { try { //Connect to SDMC1 SDMC1SerialPort.PortName = SDMC1Port.SelectedItem.ToString(); SDMC1SerialPort.BaudRate = Convert.ToInt32(SDMC1BaudRate.SelectedItem.ToString()); SDMC1SerialPort.ReadTimeout = timeoutMS; SDMC1SerialPort.DataBits = 8; SDMC1SerialPort.StopBits = StopBits.One; SDMC1SerialPort.Parity = Parity.None; SDMC1SerialPort.Open(); //Connect to Arduino ArduinoSerialPort.PortName = ArduinoPort.SelectedItem.ToString(); ArduinoSerialPort.BaudRate = Convert.ToInt32(ArduinoBaudRate.SelectedItem.ToString()); ArduinoSerialPort.ReadTimeout = timeoutMS; ArduinoSerialPort.Open(); //Change connection interaction DisconnectButton.Enabled = true; SDMC1Port.Enabled = false; SDMC1BaudRate.Enabled = false; ArduinoPort.Enabled = false; ArduinoBaudRate.Enabled = false; ConnectButton.Enabled = false; //Change controller interaction ArduinoSendText.Enabled = true; ArduinoSendButton.Enabled = true; SDMC1SendText.Enabled = true; SDMC1SendButton.Enabled = true; HomeButton.Enabled = true; } catch (Exception error) { MessageText.Text = error.Message; //if something goes wrong, close the ports that may be open SDMC1SerialPort.Close(); ArduinoSerialPort.Close(); //Change connection interaction SDMC1Port.Enabled = true; SDMC1BaudRate.Enabled = true; ArduinoPort.Enabled = true; ArduinoBaudRate.Enabled = true; ConnectButton.Enabled = true; DisconnectButton.Enabled = false; //Change controller interaction ArduinoSendText.Enabled = false; ArduinoSendButton.Enabled = false; SDMC1SendText.Enabled = false; SDMC1SendButton.Enabled = false; HomeButton.Enabled = false; ScanButton.Enabled = false; } } }