private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
//System.Threading.Thread.Sleep(100); //延時100ms等待數據接收完成
byte[] ReciveData = new byte[serialPort1.BytesToRead];
serialPort1.Read(ReciveData, 0, ReciveData.Length);
if (ReciveData[0] == 0xfe)
{
MessageBox.Show("數據錯誤!");
}
上面的程序運行到這個數組等于0xfe就會出現說程序數組越界,System.IndexOutOfRangeException,個位大神有沒有碰到過類似的問題
|