首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

C# 串口读取和写入 能写入但是读不到值解决方法

2012-04-25 
C#串口读取和写入能写入但是读不到值byte[] SendDataEncoding.ASCII.GetBytes(textBox1.Text)byte[] Rec

C# 串口读取和写入 能写入但是读不到值
byte[] SendData=Encoding.ASCII.GetBytes(textBox1.Text);
byte[] ReceiveData=Encoding.ASCII.GetBytes(textBox2.Text);
int Overtime=300;
serialPort1.DiscardInBuffer(); //清空接收缓冲区
 serialPort1.Write(SendData, 0, SendData.Length);  
System.Threading.Thread.Sleep(50);  
int num = 0, ret = 0;  
while (num++ < Overtime)  
{  
  if (serialPort1.BytesToRead>= ReceiveData.Length)  
  {  
  break;  
  }  
System.Threading.Thread.Sleep(50);  
}

为什么serialPort1.BytesToRead没有值?该serialPort1.BytesToWrite也没有?
求帮助

[解决办法]
看你发了这么多的贴子,网上不是有串口的相关小程序吗?下一个看看,没有的话,联系我。
107424627

热点排行