private bool StartArduino() { if (!arduinoConfiguredBox.Checked) { MessageBox.Show("Arduino input mapping not configured", "Error starting Arduino", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } try { var args = new ArduinoSourceFactoryArgs(new SerialPort(arduinoSerialPortCombo.Text, 115200), currentArduinoConfig.Faders, currentArduinoConfig.Buttons); loop = new Runloop(SourceFactory.CreateSource(SourceMode.Arduino, args), new OscConnection(IPAddress.Parse(targetTextBox.Text), Int32.Parse(targetPortTextBox.Text)), new OscProcessor(currentArduinoConfig.FaderMap, currentArduinoConfig.ButtonMap)); loop.Stopped += OnLoopStopped; loop.CommandsSent += OnCommandsSent; runloopTask = new Thread(loop.Run); runloopTask.Start(); } catch { return(false); } return(true); }
private void connectButton_Click(object sender, EventArgs e) { IPAddress target; int port; // Check Form if (((SourceMode)sourceModeCombo.SelectedItem == SourceMode.None || ((SourceMode)sourceModeCombo.SelectedItem == SourceMode.Arduino && arduinoSerialPortCombo.SelectedItem is SerialPort))) { MessageBox.Show("Error starting", "The source has not been configured properly", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (!IPAddress.TryParse(targetTextBox.Text, out target)) { MessageBox.Show("Error starting", "Invalid target IP address", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (!Int32.TryParse(targetPortTextBox.Text, out port)) { MessageBox.Show("Error starting", "Invalid target port", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } connectButton.Enabled = false; sourceModeCombo.Enabled = false; arduinoSerialPortCombo.Enabled = false; targetPortTextBox.Enabled = false; targetTextBox.Enabled = false; statusLabel.Text = "Connecting..."; statusLabel.BackColor = Color.Cyan; var connectionGood = true; try { loop = new Runloop(SourceFactory.CreateSource(SourceMode.Arduino, new SerialPort(arduinoSerialPortCombo.Text, 115200)), new OscConnection(IPAddress.Parse(targetTextBox.Text), Int32.Parse(targetPortTextBox.Text))); runloopTask = new Task(() => loop.Run()); runloopTask.Start(); } catch { connectionGood = false; } if (connectionGood) { statusLabel.Text = "Connected"; statusLabel.BackColor = Color.Green; disconnectButton.Enabled = true; } else { MessageBox.Show("There was an error starting the software :(", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); connectButton.Enabled = true; sourceModeCombo.Enabled = true; arduinoSerialPortCombo.Enabled = true; targetPortTextBox.Enabled = true; targetTextBox.Enabled = true; statusLabel.Text = "Error starting"; statusLabel.BackColor = Color.Red; } }