[SOLVED] UART.readline() not using timeout
[SOLVED] UART.readline() not using timeout
[EDIT] timeout in MicroPython machine.UART is in milliseconds instead of seconds in PC Python pyserial module.
I did some tests and realized that UART.readline() doesn't timeout. Instead, it immediately returns an empty byte string. I am puzzled at why we can specify timeout if this call doesn't utilize it. It would mean a lot of unnecessary modifications for my script and break away from its consistency with the PC version script.
The PC version of serial module, pyserial, does honor the timeout and waits until timeout to return the empty byte string.
Is there anything I can do to make UART.readline() honor the timeout parameter? Thanks.
System: ESP32 Lobo firmware (I really don't think this is due to the unofficial firmware).
I did some tests and realized that UART.readline() doesn't timeout. Instead, it immediately returns an empty byte string. I am puzzled at why we can specify timeout if this call doesn't utilize it. It would mean a lot of unnecessary modifications for my script and break away from its consistency with the PC version script.
The PC version of serial module, pyserial, does honor the timeout and waits until timeout to return the empty byte string.
Is there anything I can do to make UART.readline() honor the timeout parameter? Thanks.
System: ESP32 Lobo firmware (I really don't think this is due to the unofficial firmware).
Last edited by liudr on Thu Aug 16, 2018 4:43 pm, edited 1 time in total.
Re: UART.readline() not using timeout
Please, read the UART Wiki.
Re: UART.readline() not using timeout
Loboris,
Thanks for your quick response! The wiki indicates that the function will wait until timeout but my experience has been "it doesn't".
The real reason was that timeout was in milliseconds in MicroPython but in seconds in PC pyserial. Neither explicitly mentions on the constructor what time units timeout is in. Units are so important, as important as values! As a physicist, I protest! Use timeout_ms or timeout_s in the future! Billion dollar project ended up in a pile of junk when units were wrong:
https://www.wired.com/2010/11/1110mars- ... er-report/
Thanks for your quick response! The wiki indicates that the function will wait until timeout but my experience has been "it doesn't".
The real reason was that timeout was in milliseconds in MicroPython but in seconds in PC pyserial. Neither explicitly mentions on the constructor what time units timeout is in. Units are so important, as important as values! As a physicist, I protest! Use timeout_ms or timeout_s in the future! Billion dollar project ended up in a pile of junk when units were wrong:
https://www.wired.com/2010/11/1110mars- ... er-report/
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Which docs are you reading?
From the official docs: "timeout is the timeout in milliseconds to wait for writing/reading the first character."
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
-
- Posts: 969
- Joined: Sat Feb 03, 2018 7:02 pm
Re: UART.readline() not using timeout
As he's using loboris port, I'm not sure the official docs apply to this.
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
Re: UART.readline() not using timeout
From Wiki.
I have also updated the uart.init() timeout argument description.If the line end character is not found in the input buffer and uart timeout is set to a value greater than 0, waits until line end character is received or timeout ms expires.
Re: UART.readline() not using timeout
There is only esp8266 official doc:kevinkk525 wrote: ↑Wed Aug 15, 2018 9:38 amAs he's using loboris port, I'm not sure the official docs apply to this.
http://docs.micropython.org/en/latest/e ... .UART.html
Units are not mentioned.
Here is wipy port doc. Same thing:
http://docs.micropython.org/en/latest/w ... .UART.html
Loboris firmware has a wiki with doc that he pointed out.
My point is to name a variable with units. In my 30+ years of experience in programming, including units has not been mentioned as important in any textbooks that I have read. Am I the only one who saw this as a grave issue? This simple fix could prevent many bad things from happening. It is as bad as using magic numbers to not include units when necessary.
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: UART.readline() not using timeout
If you spot an error in the documentation why not submit a GitHub pull request to fix it?
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: UART.readline() not using timeout
Peter,pythoncoder wrote: ↑Thu Aug 16, 2018 8:26 amIf you spot an error in the documentation why not submit a GitHub pull request to fix it?
Thanks for the suggestion. I opened an issue on github. Another potential place to improve is to define some alias for time.sleep() as time.sleep_s() since there are already _ms and _us counterparts.