Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement _detect_available_configs for Seeedbus #1690

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions can/interfaces/seeedstudio/seeedstudio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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):
"""
Expand Down Expand Up @@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return configs
return configs # type: ignore[return-value]

Loading