From 693cbc503fcc98154f767daa6ae35144df39ef67 Mon Sep 17 00:00:00 2001 From: Ben Sartori <149951068+bensartori@users.noreply.github.com> Date: Fri, 7 Jun 2024 06:59:18 +0200 Subject: [PATCH] Explicitly closing libusb-device. On some systems using libusb it was not possible to call the program (write to the device) a second time without detaching the device. Dispose_resources + reset should solve this problem. --- lednamebadge.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lednamebadge.py b/lednamebadge.py index ae3ee42..35b3f3d 100755 --- a/lednamebadge.py +++ b/lednamebadge.py @@ -436,6 +436,7 @@ class WriteLibUsb(WriteMethod): _module_loaded = False try: import usb.core + import usb.util _module_loaded = True print("Module usb.core detected") except: @@ -480,6 +481,9 @@ class WriteLibUsb(WriteMethod): for i in range(int(len(buf) / 64)): time.sleep(0.1) self.dev.write(1, buf[i * 64:i * 64 + 64]) + WriteLibUsb.usb.util.dispose_resources(self.dev) + self.dev.reset() + self.dev = None class WriteUsbHidApi(WriteMethod): @@ -525,6 +529,7 @@ class WriteUsbHidApi(WriteMethod): sendbuf.extend(buf[i*64:i*64+64]) WriteUsbHidApi.pyhidapi.hid_write(self.dev, sendbuf) WriteUsbHidApi.pyhidapi.hid_close(self.dev) + self.dev = None class LedNameBadge: