byte[] list1 = new byte[serialPort1.BytesToRead];
            serialPort1.Read(list1, 0, serialPort1.BytesToRead); 

解决方案 »

  1.   

    我觉得上面的代码,针对serialPort有问题,因为你不知道每次读了多少个字节。
    这样定义的字节数组长度是固定的,假设我要知道该数组第10个元素是否被赋值,怎么实现呢?
    动态数组的COUNT属性可以确定数组里添加了多少个元素。
      

  2.   

    我知道了:
                    List<byte>list1 = new List<byte>();
                     do
                    {
                        list1.Add(Convert.ToByte(serialPort2.ReadByte()));
                    }
                    while (list1.Count < 30);
    读出帧头后,读后面的字节,一直读到该帧的结尾。