Skip to content

Commit

Permalink
fix(hardware_testing): added fix to directly search for USB0, and add…
Browse files Browse the repository at this point in the history
…itional error handling for running the asair sensors
  • Loading branch information
AnthonyNASC20 committed Oct 9, 2024
1 parent b6e8a46 commit dc1e5fa
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 dc1e5fa

Please sign in to comment.