我正在尝试制作一个脚本(在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()
这很好,但如果我尝试执行a:dev.set_configuration()
在索赔界面(dev,interface)之后
脚本返回错误:usb.core.usb error:Resource busy
为什么在我分离了它的内核驱动程序之后它仍然很忙?
不确定这是否能解决问题,但您的鼠标的udev规则设置是否正确?我有一个朋友为我做的自定义设备的类似问题,我通过添加如下规则解决了这个问题:
在我的
/etc/udev/rules.d
文件夹中。啊!
编辑:在添加规则之前,请尝试使用
sudo
运行脚本。如果它能以这种方式工作,几乎可以肯定的是,权限设置将由上述规则固定。我也有这个问题。如果您先“设置配置”,然后才声明接口,则代码可以正常工作。这也是这里建议的顺序:http://libusb.sourceforge.net/api-1.0/caveats.html
相关问题 更多 >
编程相关推荐