From ff158bd39f206291ffade3d69a8bde5fca7b0577 Mon Sep 17 00:00:00 2001 From: oystub Date: Wed, 18 Dec 2024 22:03:43 +0100 Subject: [PATCH 1/2] driver/python_can: use correct timeout for pyhon-can recv() python-can's recv function is supposed to take a timeout in seconds, or None, not in milliseconds or -1. --- dronecan/driver/python_can.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/dronecan/driver/python_can.py b/dronecan/driver/python_can.py index a457d73..d7be798 100644 --- a/dronecan/driver/python_can.py +++ b/dronecan/driver/python_can.py @@ -136,8 +136,6 @@ def close(self): def receive(self, timeout=None): self._check_write_feedback() - timeout = -1 if timeout is None else (timeout * 1000) - try: msg = self._bus.recv(timeout=timeout) if msg is not None: From 7d128572aba5be886213d76758c62635dbdb7386 Mon Sep 17 00:00:00 2001 From: oystub Date: Sat, 22 Feb 2025 22:10:35 +0100 Subject: [PATCH 2/2] driver/python_can: support interfaces without `flush_tx_buffer` E.g. the socketcan interface does not have `flush_tx_buffer` implemented. Calling the function without a `try` would cause send operations to fail. --- dronecan/driver/python_can.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/dronecan/driver/python_can.py b/dronecan/driver/python_can.py index d7be798..2b9ec24 100644 --- a/dronecan/driver/python_can.py +++ b/dronecan/driver/python_can.py @@ -99,8 +99,10 @@ def _writer_thread_loop(self): data=list(frame.data), ) self._bus.send(msg) - self._bus.flush_tx_buffer() - + try: + self._bus.flush_tx_buffer() + except NotImplementedError: + pass frame.ts_monotonic = time.monotonic() frame.ts_real = time.time() self._write_feedback_queue.put(frame)