C#串口通信索引超出了数组界限问题
以下是部分代码:
delegate void ShowInformation(string str1);//显示信息
private void ShowInfo(string StrInfo)
{
Invoke(new ShowInformation(OnshowInformation), StrInfo);
}
private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
int recByetLen = this.serialPort1.BytesToRead;
byte[] recByte = new byte[recByetLen];
this.serialPort1.Read(recByte, 0, recByetLen);
str = Encoding.UTF8.GetString(recByte);
ShowInfo(str);
}
错误提示出现在绿色那行,为索引超出数组界限问题。
程序可以正常通信,但通信一段时间后出现问题。
是否要清空委托的列表之类的?如果是要如何做?
望高手指教~