Skip to content

Commit

Permalink
Update nditracker.py error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Larbino1 authored May 23, 2024
1 parent 6776a36 commit d93a819
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions sksurgerynditracker/nditracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@
from sksurgerynditracker.serial_utils.com_ports import \
fix_com_port_greater_than_9

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?)'
"""

@contextlib.contextmanager
def _open_logging(verbose):
"""
Expand Down Expand Up @@ -65,30 +74,31 @@ def _get_serial_port_name(configuration):
" Result: ", result, file=fileout)
if result == ndicapy.NDI_OKAY:
break
else:
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 d93a819

Please sign in to comment.