private void connect() { if (comboJoysticks1.SelectedItem != null) { try { VJoy1 = vJoyEnumerator1.GetVJoy(comboJoysticks1.SelectedItem.ToString()); joy1 = comboJoysticks1.SelectedIndex; } catch (VJoyBase.VJoyException ex) { ErrorMessageBox(ex.Message, "VJoy Error"); return; } } if (comboJoysticks2.SelectedItem != null) { try { VJoy2 = vJoyEnumerator2.GetVJoy(comboJoysticks2.SelectedItem.ToString()); joy2 = comboJoysticks2.SelectedIndex; } catch (VJoyBase.VJoyException ex) { ErrorMessageBox(ex.Message, "VJoy Error"); return; } } serialReader = createSerialReader(); var sp = useCustomSerialParameters ? serialParameters : serialReader.GetDefaultSerialParameters(); if (!serialReader.OpenPort((string)comboPorts.SelectedItem, sp)) { ErrorMessageBox("Can not open the port", "Serial Error"); VJoy1.Release(); VJoy2.Release(); return; } comboProtocol.Enabled = false; comboPorts.Enabled = false; buttonPortSetup.Enabled = false; buttonPortsRefresh.Enabled = false; buttonProtocolSetup.Enabled = false; buttonConnect.Text = "Disconnect"; comboJoysticks1.Enabled = false; comboJoysticks2.Enabled = false; toolStripStatusLabel.Text = "Connecting ..."; connected = true; lua = new Lua(luaScript); backgroundWorker.RunWorkerAsync(); }
private void connect() { int baudRate; string errmsg; if ((errmsg = VJoy.Acquire(uint.Parse(comboJoysticks.SelectedItem.ToString()))) != null) { MessageBox.Show(errmsg); return; } try { baudRate = (int)UInt32.Parse(textBaud.Text); } catch (Exception) { MessageBox.Show("Invalid baud rate", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } try { serialPort = new SerialPort((string)comboPorts.SelectedItem, baudRate); serialPort.Open(); } catch (Exception) { MessageBox.Show("Can not open the port", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); VJoy.Release(); return; } serialReader = (SerialReader)Activator.CreateInstance(Protocols[comboProtocol.SelectedIndex]); comboProtocol.Enabled = false; comboPorts.Enabled = false; textBaud.Enabled = false; buttonPortsRefresh.Enabled = false; buttonConnect.Text = "Disconnect"; comboJoysticks.Enabled = false; connected = true; backgroundWorker.RunWorkerAsync(); }