BytesToRead没有显示完整字节 [英] BytesToRead not showing full bytes

查看:120
本文介绍了BytesToRead没有显示完整字节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用C#Framework 4.0进行串口通信。

我将ReceivedBytesThreshold定义为51204;出于某种目的,最初为低波特率打开端口为921600。完成此操作后,串口被关闭并重新打开并使用更高的波特率1228800重新打开其他任务。



当收到的字节数为51204时,将触发DataReceivedHandler。

  private   static   void  DataReceivedHandler(
object sender,
SerialDataReceivedEventArgs e)
{
SerialPort sp =(SerialPort)sender;
Console.WriteLine(sp.BytesToRead());
}





问题是BytesToRead功能不再显示完整字节。它显示的值如51174,51123等小于51204.



我也改变了ReadBufferSize,但对此没有影响。

当我以波特率1228800打开串口只有一次时,应用程序工作正常......但开启波特率921600的串口是开始执行某项任务所必需的。

接收完整字节可以做些什么?

解决方案

阅读: http://stackoverflow.com/questions/9804503/how-to-get-the-correct-value-from-serialport-bytestoread [ ^ ]

I am using C# Framework 4.0 for Serial Port communication.
I have defined ReceivedBytesThreshold as 51204; Initially the port is opened for low baud rate as 921600 for some purpose. After doing that Serial port is closed and disposed and reopened for some other task using higher Baud rate 1228800.

When number of bytes received is 51204, the DataReceivedHandler is fired.

private static void DataReceivedHandler(
                    object sender,
                    SerialDataReceivedEventArgs e)
{
    SerialPort sp = (SerialPort)sender;
    Console.WriteLine (sp.BytesToRead());
}



The problem is "BytesToRead" function is no more showing full bytes. It shows values like 51174, 51123 etc. less than 51204.

I have changed ReadBufferSize as well, but there is no effect on account of that.
When I used to open Serial port only once at Baud rate 1228800, the application works fine...but opening serial port for baud rate 921600 is necessary to carry out some task initially.
What can be done to receive full bytes?

解决方案

Read this : http://stackoverflow.com/questions/9804503/how-to-get-the-correct-value-from-serialport-bytestoread[^]


这篇关于BytesToRead没有显示完整字节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆