如何从串口清除数据字节c#中的通信

时间:2015-08-30 14:03:34

标签: c#

我有问题,我从串口接收消息以及如何从c#中的串口清除数据字节,我试试这个SerialPort1.Clear();但不行。

while (serialPort1.BytesToRead > 112)
               {
                    SerialPort1.Clear();
                }

1 个答案:

答案 0 :(得分:0)

读取所有字节可能会解决问题。

int readCount = serialPort.BytesToRead;
byte[] buffer = new byte[readCount];
serialPort.Read(buffer, 0, readCount);

我希望这会有所帮助。