From 8545c68e4d51eab55803c9c28cdf8bb7bfaa261e Mon Sep 17 00:00:00 2001 From: Radek Date: Fri, 13 Sep 2024 15:12:35 -0700 Subject: [PATCH] Fix USB errors (#2011) Fix LIBUSB_ERROR_PIPE [-9] when resetting over USB hubs or jungle V2 --- python/__init__.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/python/__init__.py b/python/__init__.py index f982d3bcf5..0e531dfc75 100644 --- a/python/__init__.py +++ b/python/__init__.py @@ -255,7 +255,7 @@ def connect(self, claim=True, wait=False): self._handle = None while self._handle is None: # try USB first, then SPI - self._context, self._handle, serial, self.bootstub, bcd = self.usb_connect(self._connect_serial, claim=claim) + self._context, self._handle, serial, self.bootstub, bcd = self.usb_connect(self._connect_serial, claim=claim, no_error=wait) if self._handle is None: self._context, self._handle, serial, self.bootstub, bcd = self.spi_connect(self._connect_serial) if not wait: @@ -347,7 +347,7 @@ def spi_connect(cls, serial, ignore_version=False): return None, handle, spi_serial, bootstub, None @classmethod - def usb_connect(cls, serial, claim=True): + def usb_connect(cls, serial, claim=True, no_error=False): handle, usb_serial, bootstub, bcd = None, None, None, None context = usb1.USBContext() context.open() @@ -357,7 +357,9 @@ def usb_connect(cls, serial, claim=True): try: this_serial = device.getSerialNumber() except Exception: - logger.exception("failed to get serial number of panda") + # Allow to ignore errors on reconnect. USB hubs need some time to initialize after panda reset + if not no_error: + logger.exception("failed to get serial number of panda") continue if serial is None or this_serial == serial: @@ -451,7 +453,7 @@ def reconnect(self): # wait up to 15 seconds for _ in range(15*10): try: - self.connect() + self.connect(claim=False, wait=True) success = True break except Exception: