Пример #1
0
        private void button_Test_Click(object sender, EventArgs e)
        {
            //关闭
            if (buttonBool)
            {
                buttonBool = false;
                commBar.Close();
                this.button_Test.Text = "点击测试";
            }
            //开始
            else if (!buttonBool)
            {
                buttonBool            = true;
                this.button_Test.Text = "正在测试……";

                //注册一该串口
                commBar.SerialPortValue(this.comboBox_Com.Text,
                                        Convert.ToInt32(this.comboBox_comPl.Text),
                                        Convert.ToInt32(cbxDataBits.Text.Trim()),
                                        (StopBits)Enum.Parse(typeof(StopBits), cbxStopBits.Text.Trim()),
                                        (Parity)Enum.Parse(typeof(Parity), cbxParity.Text.Trim()),
                                        (Handshake)Enum.Parse(typeof(Parity), cbxHandShaking.Text.Trim())
                                        );
                //打开串口
                if (commBar.Open())
                {
                    //关联事件处理程序
                    commBar.serialPort.DataReceived += new System.IO.Ports.SerialDataReceivedEventHandler(serialPort_DataReceived);
                }
            }
        }