// 测试四:使用int Read()方式读取数据 // 备注:这种方式比较合适(配合以适当的ReadBufferSize和ReadTimeOut参数) try { byte[] bytesRecvData = new byte[serialPort2.ReadBufferSize + 1]; int iCount = serialPort2.Read(bytesRecvData, 0, serialPort2.ReadBufferSize); string strRecvData = ""; for (int i = 0; i < iCount; i++) { strRecvData += Convert.ToString((bytesRecvData[i] >> 4) & 0x0F, 16) + Convert.ToString(bytesRecvData[i] & 0x0F, 16); } m_strRecvData += strRecvData; if (bytesRecvData[iCount - 1] == 0x7D) // 检测结束帧 { this.Invoke(new EventHandler(DisplayText)); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); }