0

I'm quite new to programming in C# but i can't get this one figured out.

I'm reading out data from a serial connection, this is the output:

N 0.0198 0.0000 0.0000 0.00 0.0000 30300 1025.4 0

The data I need is the first column of numbers. It's probably not possible to use a substring with fixed values because it is possible the data output is negative.

The while loop in this code is to check if the data sent is complete

What is the best way to get this data filtered out?

Thanks in advance!

private void btnRead_Click(object sender, EventArgs e)
{
        string inComingData = serialPort.ReadLine();
        int charLoc = 0;
        int serialCharLoc = inComingData.IndexOf("N");

        while(!(inComingData.Contains("N")) && !(charLoc == serialCharLoc)) 
        {
            inComingData = serialPort.ReadLine();              
        }

        rtbIncoming.Text = inComingData;
        serialPort.DiscardInBuffer();

        // this part is for filtering the data
        string usableData = inComingData.Substring(inComingData.IndexOf("N "), inComingData.IndexOf(" "));
        tbData.Text = usableData;
}
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

0 Answers0