My question is, is there a way which i can terminate the handler once i have receiving a certain piece of data or character?
I am currently using the below code to read data from the serial port.
private void serial_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
try
{
//Initialize a buffer to hold the received data
byte[] buffer = new byte[sp.ReadBufferSize];
//There is no accurate method for checking how many bytes are read
//unless you check the return from the Read method
try
{
int bytesRead = sp.Read(buffer, 0, buffer.Length);
}
catch { }
//data we are received is ASCII data.
tString += Encoding.ASCII.GetString(buffer, 0, buffer.Length);
//Check if string contains the terminator
if (tString.IndexOf((char)_terminator) > -1)
{
//If tString does contain terminator we cannot assume that it is the last character received
string workingString = tString.Substring(0, tString.IndexOf((char)_terminator));
//Remove the data up to the terminator from tString
tString = tString.Substring(tString.IndexOf((char)_terminator));
// MessageBox.Show(workingString);
sp.DiscardOutBuffer();
sp.DiscardInBuffer();
tString = "";
ProcessSerialBuffer(workingString);
localStatus = "Aknowledgement Recieved";
}
// we then pass the buffer value to the process serial buffer method.
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
I welcome any ideas or suggestions, many thanks.