delegate void SetTextCallback(string text);
private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e){
try{
SetText(serialPort1.ReadExisting()); //delegate one
}
catch{
btnClose_Click(this, null);
}
}
private void SetText(String text){
inCom = text.ToCharArray(0, 1);
if (inCom[0] == 'A'){ //ready to configure
if (txtDataReceived.InvokeRequired){
SetTextCallback d = new SetTextCallback(SetText);
Invoke(d, new object[] { text });
}else{
txtDataReceived.Clear();
txtDataReceived.Text = "Configure...";
}
}else if (inCom[0] == 'B'){ //load recorded data
if (txtDataReceived.InvokeRequired){
SetTextCallback d = new SetTextCallback(SetText);
Invoke(d, new object[] { text });
}else{
txtDataReceived.Clear();
txtDataReceived.Text = "Load...";
}
}else{
}
}