private void button1_Click(object sender, EventArgs e) { if (button1.Text == "关闭") { try { HandleRst rst = comm.OnStop(); comm.Dispose(); comm = null; } catch (Exception) { throw; } button1.Text = "打开"; } else { string portName = cbxPortName.SelectedItem.ToString(); if (string.IsNullOrEmpty(portName)) { MessageBox.Show("请选择一个串口!!!"); return; } int BaudRate; if (!int.TryParse(cbxBaudList.Text, out BaudRate)) { MessageBox.Show("请选择一个波特率!!!"); return; } comm = new SerialImpl(portName, BaudRate); this.DialogResult = DialogResult.OK; } }
public FormConn_Serialport(SerialImpl conn) { InitializeComponent(); InitComList(); comm = conn; this.cbxPortName.Text = comm.comm.PortName; this.cbxBaudList.Text = comm.comm.BaudRate.ToString(); this.button1.Text = "关闭"; }