Skip to content

Commit

Permalink
added device info command to cli
Browse files Browse the repository at this point in the history
  • Loading branch information
nplan committed May 26, 2024
1 parent 52a9568 commit 92ae8da
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
30 changes: 29 additions & 1 deletion python/picoquake/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,35 @@ def _list_devices(args):
all_ports = args.all
ports = comports()
for p in ports:
if p.vid == _VID and p.pid == _PID and p.serial_number:
if p.vid == VID and p.pid == PID and p.serial_number:
short_id = DeviceInfo.unique_id_to_short_id(p.serial_number)
print(f"PicoQuake {short_id}: {p.device}")
elif all_ports:
print(f"Unknown device: {p.device}, description: {p.description}")


def _info(args):
short_id: str = args.short_id
try:
device = PicoQuake(short_id)
except DeviceNotFound:
print(f"Device with short_id {short_id} not found.")
sys.exit(1)
except Exception as e:
logger.exception(e)
print(f"Error: {e}")
sys.exit(1)
try:
info = device.device_info
print(info)
except Exception as e:
logger.exception(e)
print(f"Error: {e}")
sys.exit(1)
finally:
device.stop()


def _test(args):
tol = 0.1
short_id: str = args.short_id
Expand Down Expand Up @@ -317,6 +340,11 @@ def main():
list_devices_parser.add_argument("-a", "--all", action="store_true", help="List all serial ports.")
list_devices_parser.set_defaults(func=_list_devices)

# device info
info_parser = subparsers.add_parser("info", help="Display device information.")
info_parser.add_argument("short_id", help="The 4 character ID of the device. Found on the label.")
info_parser.set_defaults(func=_info)

# test
test_parser = subparsers.add_parser("test", help="Test device.")
test_parser.add_argument("short_id", help="The 4 character ID of the device. Found on the label.")
Expand Down
6 changes: 3 additions & 3 deletions python/picoquake/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
from .data import *
from .exceptions import *

_VID = 0x2E8A
_PID = 0xA
VID = 0x2E8A
PID = 0xA

_HANDSHAKE_TIMEOUT = 5.0
_STATUS_TIMEOUT = 2.0
Expand Down Expand Up @@ -289,7 +289,7 @@ def _find_port(self, short_id: str) -> Optional[str]:
ports = comports()
for p in ports:
self._logger.debug(f"Found port: {p.device}, pid: {p.pid}, vid: {p.vid}, sn: {p.serial_number}")
if p.vid == _VID and p.pid == _PID and p.serial_number:
if p.vid == VID and p.pid == PID and p.serial_number:
if DeviceInfo.unique_id_to_short_id(p.serial_number) == short_id.upper():
return p.device
return None
Expand Down

0 comments on commit 92ae8da

Please sign in to comment.