From 3d52182d8f1d005a56f663856660d0cf3c15ccf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Catuhe?= Date: Tue, 17 Mar 2026 14:47:46 +0100 Subject: [PATCH] Fix Resume() to fully reinitialize USB device after suspend Replace the broken Resume() with a retry loop that does a full init.open() (USB re-enumeration + sensor init), giving the kernel time to enumerate the USB device after wake. - Call init.open() instead of init.open_common() for fresh USB handle - Retry up to 20 times with 100ms delay (2s max) for USB enumeration - Catch Exception since usb.open() raises plain Exception when device is not yet enumerated --- dbus_service/dbus-service | 11 +++++++---- validitysensor/usb.py | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/dbus_service/dbus-service b/dbus_service/dbus-service index 1c63e8d..1491ce5 100755 --- a/dbus_service/dbus-service +++ b/dbus_service/dbus-service @@ -72,10 +72,13 @@ class Device(dbus.service.Object): def Resume(self): logging.debug('In Resume') tls.reset() - try: - init.open_common() - except: - init.open_common() + for attempt in range(20): + try: + init.open() + return + except usb_core.USBError as e: + logging.debug('Resume attempt %d failed: %s' % (attempt + 1, repr(e))) + time.sleep(0.1) @dbus.service.method(dbus_interface=INTERFACE_NAME, in_signature="s", out_signature="as") def ListEnrolledFingers(self, user): diff --git a/validitysensor/usb.py b/validitysensor/usb.py index 464b092..2b1e68f 100644 --- a/validitysensor/usb.py +++ b/validitysensor/usb.py @@ -59,7 +59,7 @@ def match(d): def open_dev(self, dev: ucore.Device): if dev is None: - raise Exception('No matching devices found') + raise USBError('No matching devices found') self.dev = dev self.dev.default_timeout = 15000