Skip to content

Commit

Permalink
removed 'discovering ...' print happening twice
Browse files Browse the repository at this point in the history
  • Loading branch information
AviaAv committed Jan 24, 2024
1 parent ed722cf commit 6332f70
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 29 deletions.
33 changes: 17 additions & 16 deletions unit-tests/py/rspy/acroname.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,28 +335,29 @@ def get_port_by_location(self, usb_location):
if match:
return get_port_from_usb(int(match.group(1)), int(match.group(2)))


specs = None
def discover(retries = 0):
"""
Return all Acroname module specs in a list. Raise NoneFoundError if one is not found!
"""

log.d( 'discovering Acroname modules ...' )
global specs
# see https://acroname.com/reference/_modules/brainstem/module.html#Module.discoverAndConnect
try:
log.debug_indent()
for i in range(retries + 1):
specs = brainstem.discover.findAllModules(brainstem.link.Spec.USB)
if specs is None:
log.d('discovering Acroname modules ...')
try:
log.debug_indent()
for i in range(retries + 1):
specs = brainstem.discover.findAllModules(brainstem.link.Spec.USB)
if not specs:
time.sleep(1)
else:
for spec in specs:
log.d( '...', spec )
break
if not specs:
time.sleep(1)
else:
for spec in specs:
log.d( '...', spec )
break
if not specs:
raise NoneFoundError()
finally:
log.debug_unindent()
raise NoneFoundError()
finally:
log.debug_unindent()

return specs

Expand Down
29 changes: 16 additions & 13 deletions unit-tests/py/rspy/ykush.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,24 +197,27 @@ def get_port_by_location(self, usb_location):
return get_port_from_usb(int(usb_location.split(".")[1]))


ykush_dev = None
def discover(retries = 0, serial = None, path = None):
"""
Return a YKUSH device. Raise YKUSHNotFound if none found
If it was called more than once when there's only one device connected, return it
"""
ykush_dev = None
for i in range(retries + 1):
try:
ykush_dev = pykush.YKUSH(serial=serial, path=path)
except pykush.YKUSHNotFound as e:
log.w("YKUSH device not found!")
except Exception as e:
log.w("Unexpected error occurred!", e)
finally:
if not ykush_dev and i < retries:
time.sleep(1)
else:
break
global ykush_dev
if ykush_dev is None:
log.d('discovering YKUSH modules ...')
for i in range(retries + 1):
try:
ykush_dev = pykush.YKUSH(serial=serial, path=path)
except pykush.YKUSHNotFound as e:
log.w("YKUSH device not found!")
except Exception as e:
log.w("Unexpected error occurred!", e)
finally:
if not ykush_dev and i < retries:
time.sleep(1)
else:
break
return ykush_dev


Expand Down

0 comments on commit 6332f70

Please sign in to comment.