Skip to content

Commit

Permalink
Update core.py
Browse files Browse the repository at this point in the history
Avoid a potential connection error.
  • Loading branch information
kzhao1228 authored Oct 16, 2021
1 parent 5533cd5 commit f6b6a00
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions stage/motor_ini/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,6 @@ def find_stages():

# The loop below will find all identified stage controllers and
for dev in usb.core.find(find_all=True, custom_match= lambda x: x.bDeviceClass != 9):
try:
#FIXME: this avoids an error related to https://github.com/walac/pyusb/issues/139
#FIXME: this could maybe be solved in a better way?
dev._langids = (1033, )
# KDC101 3-port is recognized as FTDI in newer kernels
if not (dev.manufacturer == 'Thorlabs' or dev.manufacturer == 'FTDI'):
raise Exception('No manufacturer found')
except usb.core.USBError:
print("No stage controller found: make sure your device is connected")
break

if platform.system() == 'Linux':
# this is to check if the operating system is Linux, if not the code won't work. N.B. codename of MacOS
# is Darwin.
Expand All @@ -34,7 +23,18 @@ def find_stages():

else:
raise NotImplementedError("Your operating system is not supported. " \
"PyStage_APT only works on Linux.")
"PyStage_APT only works on Linux.")
try:
#FIXME: this avoids an error related to https://github.com/walac/pyusb/issues/139
#FIXME: this could maybe be solved in a better way?
dev._langids = (1033, )
# KDC101 3-port is recognized as FTDI in newer kernels
if not (dev.manufacturer == 'Thorlabs' or dev.manufacturer == 'FTDI'):
### raise Exception('No manufacturer found')
continue ### until the device is found
except usb.core.USBError:
print("No stage controller found: make sure your device is connected")
break

# we make sure at each iteration only one port entry is contained in port candidates
# i.e. the ports are accessed one by one NOT all at one go.
Expand Down

0 comments on commit f6b6a00

Please sign in to comment.