Skip to content

Commit

Permalink
fix(hardware_testing): aded fix to directly search for USB0, and addi…
Browse files Browse the repository at this point in the history
…tional error handling for running the script
  • Loading branch information
AnthonyNASC20 committed Oct 8, 2024
1 parent 2eb36ea commit 32083dd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 21 deletions.
35 changes: 15 additions & 20 deletions hardware-testing/hardware_testing/drivers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,23 @@ def list_ports_and_select(device_name: str = "", port_substr: str = None) -> str
idx_str = ""
for i, p in enumerate(ports):
print(f"\t{i + 1}) {p.device}")
if port_substr:
for i, p in enumerate(ports):
if port_substr in p.device:
idx = i + 1
break
else:
idx_str = input(
f"\nenter number next to {device_name} port (or ENTER to re-scan): "
)
if not idx_str:
return list_ports_and_select(device_name)
if not device_name:
device_name = "desired"

try:
if port_substr:
for i, p in enumerate(ports):
if port_substr in p.device:
return p.device

while True:
idx_str = input(
f"\nEnter number next to {device_name} port (or ENTER to re-scan): "
)
if not idx_str:
return list_ports_and_select(device_name, port_substr)

try:
idx = int(idx_str.strip())
except TypeError:
pass
return ports[idx - 1].device
except (ValueError, IndexError):
return list_ports_and_select()
return ports[idx - 1].device
except (ValueError, IndexError):
print("Invalid selection. Please try again.")


def find_port(vid: int, pid: int) -> str:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def __init__(self, robot: str, duration: int, frequency: int) -> None:
test_name = "ABR-Environment-Monitoring"
run_id = data.create_run_id()
file_name = data.create_file_name(test_name, run_id, robot)
sensor = asair_sensor.BuildAsairSensor(False, False, "USB")
sensor = asair_sensor.BuildAsairSensor(False, False, "USB0")
print(sensor)
env_data = sensor.get_reading()
header = [
Expand Down

0 comments on commit 32083dd

Please sign in to comment.