From 17f5ea53f5937d69eddc80ca4a2f7d9a77ef5e28 Mon Sep 17 00:00:00 2001 From: Arcmyx Official Date: Wed, 11 Mar 2026 01:05:50 +0000 Subject: [PATCH] Add dev-tests/test-allow-missing-uart.py --- dev-tests/test-allow-missing-uart.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 dev-tests/test-allow-missing-uart.py diff --git a/dev-tests/test-allow-missing-uart.py b/dev-tests/test-allow-missing-uart.py new file mode 100644 index 0000000..6d5aebc --- /dev/null +++ b/dev-tests/test-allow-missing-uart.py @@ -0,0 +1,25 @@ +from pybricks.iodevices import UARTDevice as _UARTDevice +from pybricks.tools import wait +from uerrno import ETIMEDOUT + +class FakeUART: + def __init__(self, port, baudrate, timeout): + self.timeout = timeout + print("Warning: No physical UART detected. Using simulator.") + + def read(self, length=1): + if self.timeout is not None: + wait(self.timeout) + raise OSError(ETIMEDOUT) + else: + while True: + wait(1000) + + def write(self, data): + pass + +def UARTDevice(port, baudrate=9600, timeout=None): + try: + return _UARTDevice(port, baudrate, timeout) + except OSError: + return FakeUART(port, baudrate, timeout) \ No newline at end of file