读书人

C# 串口读取和写入 能写入但是读不到

发布时间: 2012-04-25 19:32:32 作者: rapoo

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

读书人网 >C#

热点推荐