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

Crashes when a kernel driver has claimed the interface #4

Closed
ChristopherNeufeld opened this issue Feb 4, 2017 · 1 comment
Closed

Comments

@ChristopherNeufeld
Copy link

I recently plugged in a new USB wireless keyboard, and the powerusb script stopped working. The kernel HID driver was now claiming the powerusb interface, and so an exception was raised when the script tried to claim the interface.
I fixed the issue for myself with:

diff --git a/powerusb/hidapi.py b/powerusb/hidapi.py
index f697456..054e7dc 100644
--- a/powerusb/hidapi.py
+++ b/powerusb/hidapi.py
@@ -138,6 +138,10 @@ class HIDDevice():
 
     def open(self):
         self.dh = self.usb_device.open()
+       try:
+           self.dh.detachKernelDriver(0)
+       except:
+           pass
         self.dh.claimInterface(0)
 
     def close(self):

A better patch would record whether the detach was successful, and reattach it upon exit, but I am not familiar enough with Python to be confident of doing that.

@markllama
Copy link
Owner

I used this verbatim. I agree, there must be a better way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants