From 688e0f3d178785fff44503088c2ffe3f154f67c0 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Tue, 15 Mar 2016 22:24:49 +0100 Subject: [PATCH] lglaf.py: Fix "Resource busy" error Detach kernel driver (cdc_acm) to avoid this error: usb.core.USBError: [Errno 16] Resource busy Deliberately do not call attach_kernel_driver for the detached devices, it is likely that the user runs lglaf multiple times. The user can unplug and re-insert their device if they want to re-attach the kernel driver. --- lglaf.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lglaf.py b/lglaf.py index b0d2bab..8cafda8 100755 --- a/lglaf.py +++ b/lglaf.py @@ -215,6 +215,10 @@ class USBCommunication(Communication): "has a kernel driver claimed the interface?") raise e for intf in cfg: + if self.usbdev.is_kernel_driver_active(intf.bInterfaceNumber): + _logger.debug("Detaching kernel driver for intf %d", + intf.bInterfaceNumber) + self.usbdev.detach_kernel_driver(intf.bInterfaceNumber) if self._match_interface(intf): self._set_interface(intf) assert self.ep_in