Im looking into reading multiple lines of data from a device using an rs232 to UART adapter.
The string takes two forms and will look like this
OR LIKE THIS
The main difference being the line with the '-' in it.
So the data could have 3 or 4 lines, i only want the 3rd and 4th line or the 4th if it exists.
Also the data doesn't come in that often maybe a couple of times a minute.
I want to be able to capture both lines if they exist or just the one if the one with the - doesn't exist.
I know it mightnt be ideal but could i use the serial.readuntil function to read into a newline is received.
I haven't access to the piece of equipment that provides the data only the format above that it takes.
So i was thinking could i read until a newline is received, if the indexOf the received line is true for '-' i have the 3rd line so for example 2021-22. I could also check the indexof FR"EIDVID" is equal to -1 to ignore the first line.
I could also do the same for the ? in the 2nd line by doing the same as the line above.
I want to keep the third and 4th lines.
Also to get the last line i was thinking what if i check that the indexOf the read string is not equal to ? and doesnt contain FR"EIDVID" and also doesn't contain a -.
I would read until a \n was received and then use if statements to check the above using if statements.
If i did get a - id save that string In a separate variable to the 4th line.
My question was whether that approach would work or would i lose the remaining data if any of those conditions were met.
I only want the last two lines if the 4 lines exist or the last one if the data only has 3 lines e.g. the one with the - is missing.
Sorry if the question is long and awkward.