我是用SerialPort的DataReceived事件:
public void spReceive_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e) 这样读取的:
int readLength = this.serialPort1.BytesToRead;
int offset = 0;
byte[] readBuffer = new byte[readLength];
this.serialPort1.Read(readBuffer, offset, readLength); 但是经常发现readBuffe里边不只一帧数据,有时候下位机发的多了有好多帧数据到串口缓冲区里。我还设置了serialPort1.ReceivedBytesThreshold = 5;但是这个好像只有第一次触发函数的时候有效,后边就不起作用了。请问:怎么才能弄成串口缓冲区每收到10个数据就自动触发函数呢?
public void spReceive_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e) 这样读取的:
int readLength = this.serialPort1.BytesToRead;
int offset = 0;
byte[] readBuffer = new byte[readLength];
this.serialPort1.Read(readBuffer, offset, readLength); 但是经常发现readBuffe里边不只一帧数据,有时候下位机发的多了有好多帧数据到串口缓冲区里。我还设置了serialPort1.ReceivedBytesThreshold = 5;但是这个好像只有第一次触发函数的时候有效,后边就不起作用了。请问:怎么才能弄成串口缓冲区每收到10个数据就自动触发函数呢?
解决方案 »
- 哪位朋友有 博客离线发布工具 的C#源代码
- C#屏蔽系统热键
- sqlserver 存储过程中字段是变量报错,如表名.@selectthismonth 报错
- 谁用过 NHibenate 连接 Oracle 数据库!!帮我个忙??
- 【散分讨论】No.02-反射的应用场合
- 救命的急~~~~~~~~~~~~~~~在线等--------------郁闷中呀,高手请进
- 如何在VS中代码窗中新开一个窗口,可以让网页在新窗口中显示
- 求web下票据套打的例子,源代码或者可行性方案?
- winform一个技术问题,困扰一阵子了,界面刷新的问题
- 使用C#的WEB编程,请问:如何获取多个checkbox的值并删除掉?谢谢!
- treeview节点拖拽
- 把excel在datagridview中显示后 原来的样式不对了怎么解决?
{
this.serialPort1.Read(readBuffer, offset, readLength);
//...........
} DataReceived本来是提供方便的,却因为不当使用带来更多麻烦了。
{
this.serialPort1.Read(readBuffer, offset, readLength);
//...........
}
不停的读数?这个是多少字节读一次数呢
我给下位机一个起始指令,然后下位机开始不断的发数据给上位机,但是我每次读到的串口buffer都有很多帧数据。怎么处理呢?
我想能不能每收到一帧数据就读出来处理?
不想针对一大块数据进行处理。
http://blog.csdn.net/wuyazhe/category/695097.aspx