这样使用SerialPort串口通讯有问题吗?
测试代码如下:
byte[] dataSend = new byte[4];
dataSend[0] = 0x04;
dataSend[1] = 0x04;
dataSend[2] = 0x00;
dataSend[3] = 0x08;
SerialPort sp = new SerialPort( "COM1 ", 9600, Parity.Mark, 8, StopBits.One);
sp.Open();
this.rtBox.Text = "串口打开成功! " + "\r\n ";
sp.ReadTimeout = 1000;
sp.WriteTimeout = 1000;
try
{
this.rtBox.Text += "开始发送命令数据... " + "\r\n ";
sp.Write(dataSend, 0, 4);
byte[] buffer = new byte[14];
this.rtBox.Text += "开始接收返回数据... " + "\r\n ";
System.Threading.Thread.Sleep(2000);
int n = sp.BytesToRead;
sp.Read(buffer, 0, buffer.Length);
//int n = sp.BytesToRead;
this.rtBox.Text += "返回数据: " + StrToByte.byteToStr(buffer) + "\r\n ";
}
finally
{