Пример #1
0
        // shutdown the worker thread when the form closes
        protected override void OnClosed(EventArgs e)
        {
            ComPort com = ComPort.Instance;
            com.Close();

            base.OnClosed(e);
        }
Пример #2
0
        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            ComPort com = ComPort.Instance;

            if (com.IsOpen)
            {
                com.Close();
            }
        }
Пример #3
0
        private void btnClose_Click(object sender, EventArgs e)
        {
            ComPort com = ComPort.Instance;

            if (com.IsOpen)
            {
                com.Close();
                //com.Dispose();
                //com = null;
            }
        }
Пример #4
0
        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";
            }
        }