micropython/tests/pyb/uart.py
Damien George 0d9b450701 stmhal: Make uart.write() function correctly for timeout=0.
In non-blocking mode (timeout=0), uart.write() can now transmit all of its
data without raising an exception.  uart.read() also works correctly in
this mode.

As part of this patch, timout_char now has a minimum value which is long
enough to transfer 1 character.

Addresses issue #1533.
2015-11-30 17:29:52 +00:00

33 lines
677 B
Python

from pyb import UART
# test we can correctly create by id or name
for bus in (-1, 0, 1, 2, 3, 4, 5, 6, 7, "XA", "XB", "YA", "YB", "Z"):
try:
UART(bus, 9600)
print("UART", bus)
except ValueError:
print("ValueError", bus)
uart = UART(1)
uart = UART(1, 9600)
uart = UART(1, 9600, bits=8, parity=None, stop=1)
print(uart)
uart.init(2400)
print(uart)
print(uart.any())
print(uart.write('123'))
print(uart.write(b'abcd'))
print(uart.writechar(1))
# make sure this method exists
uart.sendbreak()
# non-blocking mode
uart = UART(1, 9600, timeout=0)
print(uart.write(b'1'))
print(uart.write(b'abcd'))
print(uart.writechar(1))
print(uart.read(100))