Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix USB errors #2011

Merged
merged 1 commit into from
Sep 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading