def __init__(self, tx, rx, baudrate=9600, bits=8, parity=None, stop=1, timeout=1000, receiver_buffer_size=64, flow=None): if detector.board.any_embedded_linux: raise RuntimeError('busio.UART not supported on this platform. Please use pyserial instead.') else: from machine import UART as _UART from microcontroller.pin import uartPorts self.baudrate = baudrate if flow is not None: # default 0 raise NotImplementedError( "Parameter '{}' unsupported on {}".format( "flow", agnostic.board_id)) # translate parity flag for Micropython if parity is UART.Parity.ODD: parity = 1 elif parity is UART.Parity.EVEN: parity = 0 elif parity is None: pass else: raise ValueError("Invalid parity") # check tx and rx have hardware support for portId, portTx, portRx in uartPorts: # if portTx == tx and portRx == rx: self._uart = _UART( portId, baudrate, bits=bits, parity=parity, stop=stop, timeout=timeout, read_buf_len=receiver_buffer_size ) break else: raise NotImplementedError( "No Hardware UART on (tx,rx)={}\nValid UART ports: {}".format((tx, rx), uartPorts) )
def __init__(self, tx, rx, baudrate=9600, bits=8, parity=None, stop=1): # check tx and rx have hardware support for portId, txPin, rxPin in uartPorts: if txPin == tx and rxPin == rx: self._uart = _UART( portId, baudrate, bits=bits, parity=parity, stop=stop, tx=Pin(txPin.id), rx=Pin(rxPin.id), ) break else: raise ValueError( "No Hardware UART on (tx,rx)={}\nValid UART ports: {}".format( (tx.id, rx.id), uartPorts))