是字符串处理还是串口通讯有问题?
用serialport 控件做串口通讯,接受数据后
public void serialPort_ReceiveData(object sender, SerialDataReceivedEventArgs e) { string s = ""; byte[] APIcmd = new byte[34]; this.serialPort1.Read(APIcmd, 0, APIcmd.Length); s = System.Text.ASCIIEncoding.ASCII.GetString(APIcmd);//这样处理得到的结果是s="123\0\0\0\0\0\0\0\0\0\0" //for (int i = 0; i < APIcmd.Length; i++) //{ // s += APIcmd[i].ToString(); //}//这样处理的结果是s="495051000000000000" this.textBox1.Invoke(new testTextBox(stringTest), new object[] { s.Trim() }); }