Skip to content

Commit

Permalink
Merge pull request #84 from Larbino1/patch-1
Browse files Browse the repository at this point in the history
Change error messages when connecting to a vicra device over serial to accurately reflect what went wrong.
  • Loading branch information
thompson318 authored Jun 6, 2024
2 parents 6776a36 + 99dbbae commit 404bf84
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions sksurgerynditracker/nditracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ def _get_serial_port_name(configuration):
:raises: IOError if port not found or port probe fails
"""

serial_connection_errmsg = """
Please check the following:\n
\t1) Is an NDI device connected to your computer?\n
\t2) Is the NDI device switched on?\n
\t3) Do you have sufficient privilege to connect to
the device? (e.g. on Linux are you part of the "dialout"
group?)'
"""

with _open_logging(configuration.get('verbose', False)) as fileout:
serial_port = configuration.get("serial port", None)
ports_to_probe = configuration.get("ports to probe", 20)
Expand All @@ -65,30 +74,33 @@ def _get_serial_port_name(configuration):
" Result: ", result, file=fileout)
if result == ndicapy.NDI_OKAY:
break
else:
# If we did not break from the for loop:
raise IOError('Could not find any NDI device in '
f'{ports_to_probe} serial port candidates checked. '
+ serial_connection_errmsg)

else:
if isinstance(serial_port, int):
if serial_port < len(serial_ports):
name = serial_ports[serial_port].device
result = ndicapy.ndiProbe(name)
print("Probing port: ", serial_port, " got name: ", name,
" Result: ", result, file=fileout)
else:
raise IOError(f'Could not connect to serial port {serial_port} '
f'as there are only {len(serial_ports)} ports available.'
+ serial_connection_errmsg)

if isinstance(serial_port, str):
name = serial_port
result = ndicapy.ndiProbe(name)
print("Probing port: ", name,
" Result: ", result, file=fileout)

if result != ndicapy.NDI_OKAY:
raise IOError(
'Could not find any NDI device in '
f'{ports_to_probe} serial port candidates checked. '
'Please check the following:\n'
'\t1) Is an NDI device connected to your computer?\n'
'\t2) Is the NDI device switched on?\n'
'\t3) Do you have sufficient privilege to connect to '
'the device? (e.g. on Linux are you part of the "dialout" '
'group?)')


if result != ndicapy.NDI_OKAY:
raise IOError(f'Could not connect to an NDI device on the chosen port, {serial_port}.'
+ serial_connection_errmsg)
return name


Expand Down

0 comments on commit 404bf84

Please sign in to comment.