默认情况下,SerialPort中ReadTo只能指定string,能否用来读取二进制?

解决方案 »

  1.   

    你把string转为byte[]不就行了,真是的
      

  2.   

    SerialPort.ReadTo使用指定的编码格式把Byte[]转换成字符串然后输出,
    应该使用SerialPort.Read (Byte[], Int32, Int32)
    从 SerialPort 输入缓冲区读取一些字节并将那些字节写入字节数组中指定的偏移量处。
      

  3.   

    用ReadTo的话,你就转换就行了,如果要直接读取byte,如下 int n = SerialPort.BytesToRead;
     byte[] buf = new byte[n];
     SerialPort.Read(buf, 0, n);