1from pyb import UART 2 3# test we can correctly create by id 4for bus in (-1, 0, 1, 2, 5, 6): 5 try: 6 UART(bus, 9600) 7 print("UART", bus) 8 except ValueError: 9 print("ValueError", bus) 10 11uart = UART(1) 12uart = UART(1, 9600) 13uart = UART(1, 9600, bits=8, parity=None, stop=1) 14print(uart) 15 16uart.init(2400) 17print(uart) 18 19print(uart.any()) 20print(uart.write("123")) 21print(uart.write(b"abcd")) 22print(uart.writechar(1)) 23 24# make sure this method exists 25uart.sendbreak() 26 27# non-blocking mode 28uart = UART(1, 9600, timeout=0) 29print(uart.write(b"1")) 30print(uart.write(b"abcd")) 31print(uart.writechar(1)) 32print(uart.read(100)) 33 34# set rxbuf 35uart.init(9600, rxbuf=8) 36print(uart) 37uart.init(9600, rxbuf=0) 38print(uart) 39 40# set read_buf_len (legacy, use rxbuf instead) 41uart.init(9600, read_buf_len=4) 42print(uart) 43uart.init(9600, read_buf_len=0) 44print(uart) 45