Merge pull request #6908 from dhalbert/nrf-busio-none-empty-uart-read

nrf: return None when UART.read() reads nothing
This commit is contained in:
Dan Halbert 2022-09-15 22:12:06 -04:00 committed by GitHub
commit 7914870f9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 2 deletions

View File

@ -337,6 +337,11 @@ size_t common_hal_busio_uart_read(busio_uart_obj_t *self, uint8_t *data, size_t
NVIC_EnableIRQ(nrfx_get_irq_number(self->uarte->p_reg)); NVIC_EnableIRQ(nrfx_get_irq_number(self->uarte->p_reg));
if (rx_bytes == 0) {
*errcode = EAGAIN;
return MP_STREAM_ERROR;
}
return rx_bytes; return rx_bytes;
} }

View File

@ -200,10 +200,14 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(busio_uart___exit___obj, 4, 4, busio_
// These are standard stream methods. Code is in py/stream.c. // These are standard stream methods. Code is in py/stream.c.
// //
//| def read(self, nbytes: Optional[int] = None) -> Optional[bytes]: //| def read(self, nbytes: Optional[int] = None) -> Optional[bytes]:
//| """Read characters. If ``nbytes`` is specified then read at most that many //| """Read bytes. If ``nbytes`` is specified then read at most that many
//| bytes. Otherwise, read everything that arrives until the connection //| bytes. Otherwise, read everything that arrives until the connection
//| times out. Providing the number of bytes expected is highly recommended //| times out. Providing the number of bytes expected is highly recommended
//| because it will be faster. //| because it will be faster. If no bytes are read, return ``None``.
//|
//| .. note:: When no bytes are read due to a timeout, this function returns ``None``.
//| This matches the behavior of `io.RawIOBase.read` in Python 3, but
//| differs from pyserial which returns ``b''`` in that situation.
//| //|
//| :return: Data read //| :return: Data read
//| :rtype: bytes or None""" //| :rtype: bytes or None"""