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?
UART and end of line
-
- Posts: 969
- Joined: Sat Feb 03, 2018 7:02 pm
Re: UART and end of line
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.
But even then it might return less bytes if it reads faster than the other end sends bytes.
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode
-
- Posts: 5
- Joined: Fri Feb 12, 2021 7:33 pm
Re: UART and end of line
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?
I still have the same problem with \x00 byte since the reading stops there. Is there a solution to that?
-
- Posts: 969
- Joined: Sat Feb 03, 2018 7:02 pm
Re: UART and end of line
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()
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()
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode