MyException - 我的异常网
当前位置:我的异常网» C# » SerialPort串口通讯中DataReceived事件不能触发

SerialPort串口通讯中DataReceived事件不能触发(8)

www.MyException.Cn  网友分享于:2013-02-20  浏览:827次

                n = buf.Count;
            }
            else//ascii编码直接发送   
            {
                //包含换行符   
                if (checkBoxNewlineSend.Checked)
                {
                    comm.WriteLine(txSend.Text);
                    n = txSend.Text.Length + 2;
                }
                else//不包含换行符   
                {
                    comm.Write(txSend.Text);
                    n = txSend.Text.Length;
                }
            }
            send_count += n;//累加发送字节数   
            labelSendCount.Text = "Send:" + send_count.ToString();//更新界面   
        }

        private void buttonReset_Click(object sender, EventArgs e)
        {
            //复位接受和发送的字节数计数器并更新界面。   
            send_count = received_count = 0;
            labelGetCount.Text = "Get:0";
            labelSendCount.Text = "Send:0";
        }
        //窗体初始化   
        private void SerialportSampleForm_Load_1(object sender, EventArgs e)
        {
            //初始化下拉串口名称列表框   
            string[] ports = SerialPort.GetPortNames();
            Array.Sort(ports);
            comboPortName.Items.AddRange(ports);
            comboPortName.SelectedIndex = comboPortName.Items.Count > 0 ? 0 : -1;
            comboBaudrate.SelectedIndex = comboBaudrate.Items.IndexOf("19200");

文章评论

软件开发程序错误异常ExceptionCopyright © 2009-2015 MyException 版权所有