我有以下代码:
void serialport_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
string serialData = serialport.ReadExisting().Replace("/n", "");
string[] splitSerialData = serialData.Split(new Char[] {','}); //Split up the data
this.Invoke(new Action(delegate()
{
this.temperatureLabel.Text = splitSerialData[0];
}));
}
它工作正常,但是当我这样做时:
void serialport_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
string serialData = serialport.ReadExisting().Replace("/n", "");
string[] splitSerialData = serialData.Split(new Char[] {','}); //Split up the data
this.Invoke(new Action(delegate()
{
this.temperatureLabel.Text = splitSerialData[0];
this.lightLevelLabel.Text = splitSerialData[1];
}));
}
它不起作用并说“索引超出了数组的范围”。