我是用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#中属性的get,set是怎么走的..
- object o = new { },这里的o算什么类型?
- 字符串赋值的问题
- 我们要上一套外贸邮件管理。最好附带源码。有没有好的资源推荐一下。付费也可以。
- c#下串行口通讯的问题
- 工具栏 图标问题
- 请问关于实体类这样设计合理吗?
- 急!!!!!!!!!!!---在c#中如何把string转化为int
- 请问C#&ASP.net的关于脚本语言的问题
- 在while循环里给lable动态赋值,显示出lable值得变化。
- 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