From 35075fb33a3939e77d5757096ac8023afde8c960 Mon Sep 17 00:00:00 2001 From: Ryan Hope Date: Mon, 13 Nov 2023 20:02:25 -0500 Subject: [PATCH 1/2] implement _detect_available_configs for SeeedBus --- can/interfaces/seeedstudio/seeedstudio.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/can/interfaces/seeedstudio/seeedstudio.py b/can/interfaces/seeedstudio/seeedstudio.py index 8e0dca8c7..daa7707f4 100644 --- a/can/interfaces/seeedstudio/seeedstudio.py +++ b/can/interfaces/seeedstudio/seeedstudio.py @@ -10,9 +10,11 @@ import logging import struct from time import time +from typing import Any, List import can from can import BusABC, CanProtocol, Message +from can.typechecking import AutoDetectedConfig logger = logging.getLogger("seeedbus") @@ -25,6 +27,13 @@ ) serial = None +try: + from serial.tools.list_ports import comports as list_comports +except ImportError: + # If unavailable on some platform, just return nothing + def list_comports() -> List[Any]: + return [] + class SeeedBus(BusABC): """ @@ -310,3 +319,13 @@ def fileno(self): "fileno is not implemented using current CAN bus: %s", str(excption) ) return -1 + + @staticmethod + def _detect_available_configs() -> List[AutoDetectedConfig]: + configs = [] + for port in list_comports(): + if port.vid == 0x1A86 and port.pid == 0x7523: + configs.append( + {"interface": "seeedstudio", "channel": port.device} + ) + return configs \ No newline at end of file From 97db60a730f12d9c7a83a9ff16c8a5737e2ddae4 Mon Sep 17 00:00:00 2001 From: RyanHope Date: Tue, 14 Nov 2023 01:03:16 +0000 Subject: [PATCH 2/2] Format code with black --- can/interfaces/seeedstudio/seeedstudio.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/can/interfaces/seeedstudio/seeedstudio.py b/can/interfaces/seeedstudio/seeedstudio.py index daa7707f4..4d749412d 100644 --- a/can/interfaces/seeedstudio/seeedstudio.py +++ b/can/interfaces/seeedstudio/seeedstudio.py @@ -325,7 +325,5 @@ def _detect_available_configs() -> List[AutoDetectedConfig]: configs = [] for port in list_comports(): if port.vid == 0x1A86 and port.pid == 0x7523: - configs.append( - {"interface": "seeedstudio", "channel": port.device} - ) - return configs \ No newline at end of file + configs.append({"interface": "seeedstudio", "channel": port.device}) + return configs