我正在尝试制作一个脚本(在 linux 上),它可以打开或关闭鼠标中的灯。
这是我到目前为止的代码:
import usb.core
import usb.util
import sys
interface = 0
dev = usb.core.find(idVendor=0x1532, idProduct=0x0017)
def main():
if dev is None:
print "device not found"
else:
print "device found"
if dev.is_kernel_driver_active(interface) is True:
print "but we need to detach kernel driver"
dev.detach_kernel_driver(interface)
print "claiming device"
usb.util.claim_interface(dev, interface)
print "release claimed interface"
usb.util.release_interface(dev, interface)
print "now attaching the kernel driver again"
dev.attach_kernel_driver(interface)
print "all done"
return 0
if __name__ == '__main__':
main()
这工作正常,但如果我尝试做一个:dev.set_configuration()
在claim_interface(dev, interface)之后
脚本返回错误:usb.core.USBError: Resource busy
为什么我分离了它的内核驱动后它仍然很忙?