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

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

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


                builder.Remove(0,builder.Length);//清除字符串构造器的内容   
                //因为要访问ui资源,所以需要使用invoke方式同步ui。   
                this.Invoke((EventHandler)(delegate
                {
                    //判断是否是显示为16禁止   
                    if (checkBoxHexView.Checked)
                    {
                        //依次的拼接出16进制字符串   
                        foreach (byte b in buf)
                        {
                            builder.Append(b.ToString("X2") + " ");
                            string bStr=b.ToString("X2");
                            if (bStr == "FF"
------解决方案--------------------
 bStr =="EF")
                            {
                                builder.Append("\r\n");
                            }
                        }
                    }
                    else
                    {
                        //直接按ASCII规则转换成字符串   
                        builder.Append(Encoding.ASCII.GetString(buf));

                    }
                    //追加的形式添加到文本框末端,并滚动到最后。   

文章评论

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