diff --git a/can/interfaces/seeedstudio/seeedstudio.py b/can/interfaces/seeedstudio/seeedstudio.py index 8e0dca8c7..4d749412d 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,11 @@ 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