api/customdevices: add UARTDevice

This commit is contained in:
Laurens Valk
2019-12-06 14:57:43 +01:00
parent 3143b28be1
commit 1187f059fa
2 changed files with 63 additions and 0 deletions
+4
View File
@@ -72,3 +72,7 @@ More details about using I2C without MicroPython can be found on
the `ev3dev I2C`_ page.
.. _ev3dev I2C: http://docs.ev3dev.org/projects/lego-linux-drivers/en/ev3dev-stretch/i2c.html
UART Device
^^^^^^^^^^^^^
.. autoclass:: pybricks.customdevices.UARTDevice
+59
View File
@@ -96,3 +96,62 @@ class I2CDevice():
data (``bytes``): Bytes to be written.
"""
pass
class UARTDevice():
"""Generic UART device."""
def __init__(self, port, baudrate, timeout=None):
"""
Arguments:
port (Port): Port to which the device is connected.
baudrate (int): Baudrate of the UART device.
timeout (:ref:`time`): How long to wait
during :meth:`.read` before giving up. If you choose ``None``,
it will wait forever. (*Default*: ``None``)
"""
pass
def read(self, length):
"""Read a given number of bytes from the buffer.
Your program will wait until the requested number of bytes are
received. If this takes longer than ``timeout``, the ``ETIMEDOUT``
exception is raised.
Arguments:
length (``int``): How many bytes to read.
Returns:
``bytes``: Bytes returned from the device.
"""
pass
def read_all(self):
"""Read all bytes from the buffer.
Returns:
``bytes``: Bytes returned from the device.
"""
pass
def write(self, data):
"""Write bytes.
Arguments:
data (``bytes``): Bytes to be written.
"""
pass
def waiting(self):
"""How many bytes are still waiting to be read.
Returns:
``int``: Number of bytes in the buffer.
"""
pass
def clear(self):
"""Empty the buffer."""
pass