Page 1 of 1

UART and end of line

Posted: Fri Feb 12, 2021 7:50 pm
by 161616harvard
Hello,

I'm trying to read 40 bytes from uart.readline() in micropython. However the reading stops when it encounters \x00.
Example.
"\xff\xff\xff\xff\x01\x00\x05\x07\x02\x44\x45\x41\"

uart.readline() returns b'\xff\xff\xff\xff\x01'

Can someone shed a light into this? Why does it convert to ascii and How can I read the 0 byte and the rest?

Re: UART and end of line

Posted: Fri Feb 12, 2021 7:59 pm
by kevinkk525
If you are trying to read exactly 40 bytes, why are you using uart.readline()? You should be using uart.read(40)
But even then it might return less bytes if it reads faster than the other end sends bytes.

Re: UART and end of line

Posted: Fri Feb 12, 2021 8:12 pm
by 161616harvard
I added at the end he byte 0x0A for end of line, but I could use the uart.read(40)

I still have the same problem with \x00 byte since the reading stops there. Is there a solution to that?

Re: UART and end of line

Posted: Fri Feb 12, 2021 8:34 pm
by kevinkk525
What hardware are you using?
if you use uart.readline() maybe it stops because it considers \x00 the end of a line? i don't know. I only use read()