Skip to content

Commit

Permalink
trunner: adjust find_port for multiple possible devices
Browse files Browse the repository at this point in the history
JIRA: CI-500
  • Loading branch information
maska989 committed Oct 4, 2024
1 parent c3b2ba6 commit 812212a
Showing 1 changed file with 31 additions and 14 deletions.
45 changes: 31 additions & 14 deletions trunner/target/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,42 @@
from trunner.types import TestOptions, TestResult


def find_port(port_hint: str) -> str:
port = None

for p in list_ports.grep(port_hint):
if port is not None:
raise PortNotFound(
"More than one port was found! Maybe more than one device is connected? Hint used to find port:"
f" {port_hint}"
)

port = p

if port is None:
def vid_pid_parser(vid_pid_string):
list = []
for vid_pid in vid_pid_string:
try:
vid_str, pid_str = vid_pid.split(":")
vid = int(vid_str, 16)
pid = int(pid_str, 16)
list.append((vid, pid))
except ValueError:
raise PortNotFound(f"Wrong format: {vid_pid}. Use 'VID:PID'.")
return list


def find_port(port_hint: list[str]) -> list:

all_ports = list_ports.comports()
vid_pid_list = vid_pid_parser(port_hint)
ports = []

for port in all_ports:
for vid, pid in vid_pid_list:
if port.vid == vid and port.pid == pid:
ports.append(port)

if len(ports) > 1:
raise PortNotFound(
"More than one port was found! Maybe more than one device is connected? Hint used to find port:"
f" {port_hint}"
)
elif len(ports) < 1:
raise PortNotFound(
"Couldn't find port to communicate with device! Make sure device is connected. Hint used to find port:"
f" {port_hint}"
)

return port.device
return ports[0].device


class PsuPloLoader(TerminalHarness, PloInterface):
Expand Down

0 comments on commit 812212a

Please sign in to comment.