private void InitPortCB() //Availabe Ports combo box { string currentport = CBPort.SelectedItem as string; CBPort.BeginUpdate(); CBPort.Items.Clear(); foreach (string portname in System.IO.Ports.SerialPort.GetPortNames()) { string purgename = portname; //FIX https://github.com/arkypita/LaserGRBL/issues/31 if (!char.IsDigit(purgename[purgename.Length - 1])) { purgename = purgename.Substring(0, purgename.Length - 1); } CBPort.Items.Add(purgename); } if (currentport != null && CBPort.Items.Contains(currentport)) { CBPort.SelectedItem = currentport; } else if (CBPort.Items.Count > 0) { CBPort.SelectedIndex = CBPort.Items.Count - 1; } CBPort.EndUpdate(); }
private void InitPortCB() //Availabe Ports combo box { string currentport = CBPort.SelectedItem as string; CBPort.BeginUpdate(); CBPort.Items.Clear(); CBPort.Items.AddRange(System.IO.Ports.SerialPort.GetPortNames()); if (currentport != null && CBPort.Items.Contains(currentport)) { CBPort.SelectedItem = currentport; } else if (CBPort.Items.Count > 0) { CBPort.SelectedIndex = CBPort.Items.Count - 1; } CBPort.EndUpdate(); }
//wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww public FCOMserver(Form own) { InitializeComponent(); Owner = own; ColorCBPort = CBPort.BackColor; CBBaud.SelectedIndex = CBBaud.FindString(Properties.Settings.Default.asBaud); CBPort.Items.AddRange(SerialPort.GetPortNames()); CBPort.SelectedIndex = CBPort.FindString(Properties.Settings.Default.asCOMport); CBDevice.Items.AddRange(Enum.GetNames(typeof(EDevs))); CBDevice.SelectedIndex = CBDevice.FindString(Properties.Settings.Default.asDevComPort); NUDFont.Value = Properties.Settings.Default.dmSizeFontByComPort; ChBChangePar.CheckedChanged -= ChBChangePar_CheckedChanged; ChBChangePar.Checked = Properties.Settings.Default.bChangeVal_ComP; ChBChangePar.CheckedChanged += ChBChangePar_CheckedChanged; //Log = new TTrace (); }
private void BtnConnect_Click(object sender, EventArgs e) { if (BtnConnect.Text == "Connect") { try { serialPort1.PortName = CBPort.Text; serialPort1.Open(); BtnConnect.Text = "Disconnect"; BtnConnect.ForeColor = Color.Red; CBPort.Enabled = false; PortsRefresh.Enabled = false; TxtLog.Text = ""; TxtSendToPort.Text = ""; this.Height = FormHeightWithGBControl; RePosition(); BGW_CheckConnection.RunWorkerAsync(); LedSet(ledState.Ready); } catch (Exception ex) { MessageBox.Show(ex.Message); } } else { try { serialPort1.Close(); BtnConnect.Text = "Connect"; BtnConnect.ForeColor = Color.Green; CBPort.Enabled = true; PortsRefresh.Enabled = true; this.Height = FormHeightWithoutGBControl; RePosition(); CBPort.Focus(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } }