All, a new bee here, and I am seeking some help. I am at a lost. Below you will find a portion of my code where I take the < and > out of my string received from a serial port. This all works great until I send a serial message back to the other device(Just a button programed to send a message). Then program stops and tells me "System.ArgumentOutOfRangeException: 'StartIndex cannot be less than zero.".
It stops at "string CleanString1 = withoutStartOfString1.Remove(endOfString1);"
All your help will be appreciated.
private void DataReceivedHandler1(object sender1, SerialDataReceivedEventArgs e )
{
SerialPort sp1 = (SerialPort)sender1;
string indata1 = sp1.ReadLine();
Console.WriteLine("Data Received1:"+ indata1);
int startOfString1 = indata1.IndexOf('<');
string withoutStartOfString1 = indata1.Remove(0, startOfString1 + 1);
int endOfString1 = withoutStartOfString1.LastIndexOf('>');
string CleanString1 = withoutStartOfString1.Remove(endOfString1);
txtReceive1.BeginInvoke((new myDelegate1(Serial_Text_Out1)), CleanString1);
txtReceive1.BeginInvoke ((new myDelegate1(Serial_Text_Out1)), CleanString1);
/*
* ROBOT 1 Section to convert "CleanSting so it can be used else where
*/
void Serial_Text_Out1(string Clean1String1)
{
txtReceive1.Text= Clean1String1;
string[] words1 = CleanString1.Split(',');
txtIdentifier1.Text = words1[0];
txtValue1_1.Text = words1[1];
txtValue1_2.Text = words1[2];
txtValue1_3.Text = words1[3];
txtValue1_4.Text = words1[4];
}
}