Skip to content

Commit

Permalink
Issue #40 put free ports into a separate function and call it from _f…
Browse files Browse the repository at this point in the history
…ind_wired_ports and well as _read_sroms_from_file
  • Loading branch information
thompson318 committed Nov 9, 2023
1 parent 85bd6a0 commit 84e5779
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
20 changes: 13 additions & 7 deletions sksurgerynditracker/nditracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,13 +327,7 @@ def close(self):
self._device = None
self._state = None

def _read_sroms_from_file(self):
if not self._device:
raise ValueError('read srom called with no NDI device')

if self._state == "tracking":
self.stop_tracking()

def _free_ports(self):
#free ports that are waiting to be freed
ndicapy.ndiCommand(self._device, 'PHSR:01')
number_of_tools = ndicapy.ndiGetPHSRNumberOfHandles(self._device)
Expand All @@ -342,6 +336,15 @@ def _read_sroms_from_file(self):
ndicapy.ndiCommand(self._device, f"PHF:{port_handle:02x}")
self._check_for_errors(f'freeing port handle {tool_index:02x}.')

def _read_sroms_from_file(self):
if not self._device:
raise ValueError('read srom called with no NDI device')

if self._state == "tracking":
self.stop_tracking()

self._free_ports()

for tool in self._tool_descriptors:
ndicapy.ndiCommand(self._device, 'PHRQ:*********1****')
port_handle = ndicapy.ndiGetPHRQHandle(self._device)
Expand Down Expand Up @@ -381,6 +384,9 @@ def _find_wired_ports(self, verbose = False):
raise ValueError('find wired ports called with no NDI device')

with _open_logging(verbose) as fileout:

self._free_ports()

while True:
ndicapy.ndiCommand(self._device, 'PHSR:02')
number_of_tools = ndicapy.ndiGetPHSRNumberOfHandles(
Expand Down
16 changes: 7 additions & 9 deletions tests/test_sksurgerynditracker_mockndi_aurora.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,24 +86,22 @@ def test_connect_aurora_mock(mocker):
mockndiGetPHSRNumberOfHandles.number_of_tool_handles = 3
tracker = NDITracker(SETTINGS_AURORA)

assert spy.call_count == 13
assert spy.call_count == 11
assert spy.call_args_list[0] == call(True, 'INIT:')
assert spy.call_args_list[1] == call(True, 'COMM:50000')
assert spy.call_args_list[2] == call(True, 'PHSR:02')
assert spy.call_args_list[3] == call(True, 'PINIT:00')
assert spy.call_args_list[4] == call(True, 'PINIT:01')
assert spy.call_args_list[2] == call(True, 'PHSR:01')
assert spy.call_args_list[3] == call(True, 'PHF:00')
assert spy.call_args_list[4] == call(True, 'PHF:01')
assert spy.call_args_list[5] == call(True, 'PHSR:02')
assert spy.call_args_list[6] == call(True, 'PINIT:00')
assert spy.call_args_list[7] == call(True, 'PHSR:02')
assert spy.call_args_list[8] == call(True, 'PHSR:02')
assert spy.call_args_list[9] == call(True, 'PINIT:00')
assert spy.call_args_list[10] == call(True, 'PINIT:01')
assert spy.call_args_list[11] == call(True, 'PINIT:00')
assert spy.call_args_list[12] == call(True, 'PHSR:03')
assert spy.call_args_list[10] == call(True, 'PHSR:03')
tracker.start_tracking()
assert spy.call_args_list[13] == call(True, 'TSTART:')
assert spy.call_args_list[11] == call(True, 'TSTART:')
tracker.stop_tracking()
assert spy.call_args_list[14] == call(True, 'TSTOP:')
assert spy.call_args_list[12] == call(True, 'TSTOP:')
tracker.close()
del tracker

Expand Down

0 comments on commit 84e5779

Please sign in to comment.