diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2015-10-20 00:27:07 +0300 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2015-10-20 00:27:07 +0300 |
commit | bedab235f9028562b6677fa257cd08fbf1efecca (patch) | |
tree | 34f9e46b33c15dc9509b6c4b7d8598c4664efd94 | |
parent | 83158e0e7f12d0454bb5efb27cd9071123e3be75 (diff) | |
download | micropython-bedab235f9028562b6677fa257cd08fbf1efecca.tar.gz micropython-bedab235f9028562b6677fa257cd08fbf1efecca.zip |
stmhal/uart: If char is not received within timeout, return EAGAIN error.
Instead of return 0, which means EOF. There's no good way to detect EOF on
continuously active bus like UART, and treat timeout as just temporary
unvailability of data. .read() method of UART object will return None in
this case (instead of 0, which again measn EOF). This is fully compliant
with unix port.
-rw-r--r-- | stmhal/uart.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/stmhal/uart.c b/stmhal/uart.c index 85feb32e05..177318aecd 100644 --- a/stmhal/uart.c +++ b/stmhal/uart.c @@ -772,9 +772,9 @@ STATIC mp_uint_t pyb_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t size, i // wait for first char to become available if (!uart_rx_wait(self, self->timeout)) { - // we can either return 0 to indicate EOF (then read() method returns b'') - // or return EAGAIN error to indicate non-blocking (then read() method returns None) - return 0; + // return EAGAIN error to indicate non-blocking (then read() method returns None) + *errcode = EAGAIN; + return MP_STREAM_ERROR; } // read the data |