Iro*_*key 7 python usb libusb pyusb
我正在尝试制作一个脚本(在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()
Run Code Online (Sandbox Code Playgroud)
这工作正常,但如果我尝试做:dev.set_configuration()
在claim_interface(dev,interface)之后
该脚本返回错误:usb.core.USBError:资源忙
在分离内核驱动程序后,为什么它仍然很忙?
不确定这是否会解决,但是你的鼠标设置正确的udev规则是什么?我和朋友为我做的自定义设备有类似的问题,我通过添加如下规则解决了这个问题:
SUBSYSTEM !="usb_device", ACTION !="add", GOTO="device_rules_end"
SYSFS{idVendor} =="1532", SYSFS{idProduct} =="0017", SYMLINK+="mydevice"
MODE="0666", OWNER="<your-username-here>", GROUP="root"
LABEL="device_rules_end"
Run Code Online (Sandbox Code Playgroud)
在我的/etc/udev/rules.d
文件夹中.
HTH!
编辑:在添加规则之前,请尝试运行脚本sudo
.如果它将以这种方式工作,几乎可以肯定是一个权限设置将由上述规则修复.
归档时间: |
|
查看次数: |
14730 次 |
最近记录: |