串口接收数据 Overrun发生字符缓冲区溢出,下一个字符将丢失

混QWER 2018-04-09 03:37:46
如题,串口接收数据定义如下:
 	   
WinPort = new SerialPort(l_com);
WinPort.BaudRate = l_rate;
WinPort.DataBits = 8;
WinPort.Parity = Parity.None;
WinPort.Encoding = System.Text.Encoding.GetEncoding("GB2312");
WinPort.StopBits = StopBits.One;
WinPort.ReceivedBytesThreshold = 1;
WinPort.DataReceived += new SerialDataReceivedEventHandler(DevicePort_DataReceived);
WinPort.ErrorReceived += new SerialErrorReceivedEventHandler(DevicePortError_DataReceived);


有没有大神知道可能的原因都有哪些。
...全文
724 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
xian_wwq 2018-04-09
  • 打赏
  • 举报
回复
WinPort.ReceivedBytesThreshold = 1; 只要接收长度大于1即触发事件 这样的话事件触发比较频繁, 如果接收buffer太小,也可能会导致数据丢失
xian_wwq 2018-04-09
  • 打赏
  • 举报
回复
串口接收数据长度是不确定的 所以要根据串口协议来确定完整包的长度, 避免接收长度不足时进行解析

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧