Force PySerial to wait for next character after newline before begin read?

Is there any way to force PySerial to wait for the next character after a /n newline character before beginning to read data from an Arduino sensor?

My Arduino sketch is set to write a string of 200 comma separated values to serial, which is then read by PySerial.

My current PySerial code works perfectly about 1/3 of the time, but sometimes begins reading in the middle of a string, which results in only half of the string being read, or causes an 'invalid first byte' error.

You can achieve what you want, but you must read all the characters that arrive and just ignore those that are irrelevant.

Have a look at this Python - Arduino demo

See also Serial Input Basics which was written more recently.

...R

Robin2:
You can achieve what you want, but you must read all the characters that arrive and just ignore those that are irrelevant.

Thanks, I finished looking over the tutorials, which were helpful learning tools, but do not help with this issue.

When the string starts being read halfway through, how would I make the code check to make sure all 200 of the values are returned and not only 199?

Also when the 'invalid first byte' error arrives (due to I assume PySerial beginning to read in the middle of a value) that is a completely different case than the 'returns 199 characters' issue...

Is there any way to do what I asked in the OP and have PySerial wait to begin collecting data until the /n character is read at the end of a previous line?

That would be optimal as it would allow me to avoid all of the possible errors caused by reading in the middle of a string, or the middle of a value, etc as a catch-all.

MrJenkins:
When the string starts being read halfway through, how would I make the code check to make sure all 200 of the values are returned and not only 199?

That is the purpose of encapsulating the data between start-and end-markers - as in my examples.

If you only have an end-marker all you can do is save the data received up to the end-marker and then count how many characters have been received. If you know that the message has exactly 200 characters you could count backwards from the end for 200 chars and assume that you are then at the start.

...R