Skip to content

Commit

Permalink
Merge pull request #61 from roaldarbol/list-devices
Browse files Browse the repository at this point in the history
Create list devices helper method
  • Loading branch information
BrianPugh authored Dec 1, 2022
2 parents af3f06c + a91b023 commit 128f524
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
12 changes: 8 additions & 4 deletions belay/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@

__all__ = [
"AuthenticationError",
"minify",
"ConnectionLost",
"Device",
"SpecialFunctionNameError",
"PyboardException",
"Implementation",
"FeatureUnavailableError",
"Implementation",
"MaxHistoryLengthError",
"PyboardException",
"SpecialFunctionNameError",
"list_devices",
"minify",
]
from ._minify import minify
from .device import Device, Implementation
Expand All @@ -19,4 +22,5 @@
MaxHistoryLengthError,
SpecialFunctionNameError,
)
from .helpers import list_devices
from .pyboard import PyboardException
18 changes: 18 additions & 0 deletions belay/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
import secrets
import string
from functools import lru_cache, partial, wraps
from typing import List

from serial.tools import list_ports

from . import snippets

Expand All @@ -22,3 +25,18 @@ def random_python_identifier(n=16):
@lru_cache
def read_snippet(name):
return pkg_resources.read_text(snippets, f"{name}.py")


def list_devices() -> List[str]:
"""Lists available device ports.
For example::
['/dev/cu.usbmodem1143401', '/dev/cu.usbmodem113101']
Returns
-------
list[str]
Available devices identifiers.
"""
return [port.device for port in list_ports.comports()]

0 comments on commit 128f524

Please sign in to comment.