c#串口接收字符串
我在单片机上每10s发送4个字符到上位机 波特率9600
上位机接收事件里面将接收到的字符和时间记录日志,代码如下:
private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
string str = serialPort1.ReadExisting();
write_log(str); //记录日志 将接收到的数据和时间记录下来
}
然后我接收一段时间后查看日志内容如下:
2760 2016/6/11 16:35:26
2 2016/6/11 16:35:37
760 2016/6/11 16:35:37
2 2016/6/11 16:35:48
760 2016/6/11 16:35:48
2 2016/6/11 16:35:59
76 2016/6/11 16:35:59
0 2016/6/11 16:35:59
2 2016/6/11 16:36:09
75 2016/6/11 16:36:09
9 2016/6/11 16:36:09
2 2016/6/11 16:36:20
759 2016/6/11 16:36:20
27 2016/6/11 16:36:31
59 2016/6/11 16:36:31
可以看出我一次发送的数据除了第一次能接收完整 其余时候都要分2次或者3次接收
是windows缓冲机制的原因吗?
各位大神指点指点 这个怎么解决?加快波特率可以吗?