pyusb:无法设置配置

2024-01-01

我正在尝试制作一个脚本(在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()

之后声明_接口(开发,接口)

脚本返回错误: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"

in my /etc/udev/rules.d folder.

HTH!

编辑:在添加规则之前,尝试使用以下命令运行脚本sudo。如果它能以这种方式工作,那么几乎可以肯定这是一个将由上述规则修复的权限设置。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

pyusb:无法设置配置 的相关文章

随机推荐