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

为什么写入到串口里面了 却没有数据
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.BytesToRade 这里面没有值? 改成serialPort1.BytesToWrite也没有值 我明明写入了啊。求高手帮忙

------解决方案--------------------
探讨
那么怎么才能读取到呢?

引用:

假设你的serialPort1打开的是串口A,串口A的另一端通过串口线连接的是串口B
那么你从串口A写入的数据,你只能从串口B中把你从写入的数据读出来,你现在用serialPort1.BytesToRead
这样的代码,难道你想再从串口A里面把你写进去的东西读出来吗?就是能读出来点东西 ,那个也不是你从串口A里写进去的,而是另一个程序……