private void Thread1() { string str; str = Ini.Read("config", "com1"); try { if (str != "null") { textBox3.Text = str; serialPort2.PortName = "COM" + Ini.Read("config", "com1"); serialPort2.Open(); } else { MessageBox.Show("串口未配置!"); } } catch (Exception ex) { MessageBox.Show(string.Format("COM{0}打开失败!", str)); } }
private void open() { string str; str = Ini.Read("config", "com"); try { if (str != "null") { textBoxCom.Text = str; serialPort1.PortName = "COM" + Ini.Read("config", "com"); serialPort1.Open(); } else { MessageBox.Show("串口未配置!"); } } catch { MessageBox.Show(string.Format("COM{0}打开失败!", str)); } }