rp2: uasyncio: sys.stdout not working
the Pico port does not have a separate USB_VCP object so we resort to use sys stdio. while receiving works, transmitting blocks or crashes on writing. other ports like the pyboard support this. It would be good if this works so that uasyncio communication can be done via USB too.
Here is a minimal example for testing:
echo.py.txt
- It works on a pyboard (pybv11-20210302-unstable-v1.14-82-gcdaec0dca)
- It works on the unix port (though with
sys.stdoutinstead ofsys.stdout.buffer) - It fails on the pico (rp2-pico-20210301-unstable-v1.14-82-gcdaec0dca)
- [edit] it fails on the esp32 (esp32-20210302-unstable-v1.14-82-gcdaec0dca)
Output when it fails (drain never outputs anything on pico and esp32):
# ready
.# input b'hello\r\n'
# drain
.........Traceback (most recent call last):
[...]
KeyboardInterrupt:
And there is an exception on the pico (not on esp32) when the feedback_task is not started, pressing RETURN twice results in:
# ready
# input b'hello\r\n'
# drain
Traceback (most recent call last):
File "<stdin>", line 32, in <module>
File "<stdin>", line 29, in echo
File "uasyncio/core.py", line 1, in run_forever
File "uasyncio/core.py", line 1, in run_until_complete
IndexError: empty heap
Compared to an output on the pyboard, where it echoes and goes back to reading as expected:
# ready
...# input b'hallo\r\n'
# drain
.hallo
# ready
[...]
esp8266: can't read from sys.stdin
I was trying to work around the fact that the ESP8266 port doesn't have UART support on the Python side yet, and simply read/write from and to the sys.stdin and sys.stdout.
While sys.stdout works as expected, trying to read even a single character from sys.stdin hangs the REPL. I compared with other ports, and that's not the case in them -- they wait until the specified number of characters is input and then properly return those characters.