日期:2014-05-18  浏览次数:21045 次

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