// shutdown the worker thread when the form closes protected override void OnClosed(EventArgs e) { ComPort com = ComPort.Instance; com.Close(); base.OnClosed(e); }
private void Form1_FormClosed(object sender, FormClosedEventArgs e) { ComPort com = ComPort.Instance; if (com.IsOpen) { com.Close(); } }
private void btnClose_Click(object sender, EventArgs e) { ComPort com = ComPort.Instance; if (com.IsOpen) { com.Close(); //com.Dispose(); //com = null; } }
private void btnOpen_Click(object sender, EventArgs e) { //read port status ComSetting.Port.PortName = ComboPortList.Text; ComSetting.Port.BaudRate = Int32.Parse(ComboBr.Text); ComSetting.Port.DataBits = ComboDb.SelectedIndex + 5; ComSetting.Port.Parity = (Parity)ComboParity.SelectedIndex; ComSetting.Port.StopBits = (StopBits)ComboSb.SelectedIndex; ComSetting.Port.Handshake = (Handshake)ComboFlow.SelectedIndex; //read port option if (radioButton2.Checked) ComSetting.Option.AppendToSend = ComSetting.Option.AppendType.AppendCR; else if (radioButton3.Checked) ComSetting.Option.AppendToSend = ComSetting.Option.AppendType.AppendLF; else if (radioButton4.Checked) ComSetting.Option.AppendToSend = ComSetting.Option.AppendType.AppendCRLF; else ComSetting.Option.AppendToSend = ComSetting.Option.AppendType.AppendNothing; ComSetting.Option.HexOutput = checkBox1.Checked; ComSetting.Option.MonoFont = checkBox2.Checked; ComSetting.Option.LocalEcho = checkBox3.Checked; ComSetting.Option.StayOnTop = checkBox4.Checked; ComSetting.Option.FilterUseCase = checkBox5.Checked; ComPort com = ComPort.Instance; if (com.IsOpen) { com.Close(); btnOpen.Text = "disconnect"; } else { com.Open(); richTextBox1.Focus(); btnOpen.Text = "connect"; } }