Skip to content

Commit c79c3f2

Browse files
committed
re-initialize io.usb if previous failed
1 parent 18a10d3 commit c79c3f2

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

pylabrobot/io/usb.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,16 +296,18 @@ def ctrl_transfer(
296296
async def setup(self):
297297
"""Initialize the USB connection to the machine."""
298298

299+
if self.dev is not None:
300+
# previous setup did not properly finish,
301+
# or we are re-initializing the device.
302+
logger.warning("USB device already connected. Closing previous connection.")
303+
await self.stop()
304+
299305
if not USE_USB:
300306
raise RuntimeError(
301307
"USB is not enabled. Please install pyusb and libusb. "
302308
"https://docs.pylabrobot.org/installation.html"
303309
)
304310

305-
if self.dev is not None:
306-
logging.warning("Already initialized. Please call stop() first.")
307-
return
308-
309311
logger.info("Finding USB device...")
310312

311313
devices = self.get_available_devices()

0 commit comments

Comments
 (0)