Skip to content

Commit

Permalink
Fix USB errors (commaai#2011)
Browse files Browse the repository at this point in the history
Fix LIBUSB_ERROR_PIPE [-9] when resetting over USB hubs or jungle V2
  • Loading branch information
dzid26 authored Sep 13, 2024
1 parent b8a2a86 commit 8545c68
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions python/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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()
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 8545c68

Please sign in to comment.