您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

python – pyusb:无法设置配置

5b51 2022/1/14 8:22:38 python 字数 2521 阅读 568 来源 www.jb51.cc/python

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

概述

这是我到目前为止的代码

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:资源忙

在分离内核驱动程序后,为什么它仍然很忙?

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"

在我的/etc/udev/rules.d文件夹中.

HTH!

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

总结

以上是编程之家为你收集整理的python – pyusb:无法设置配置全部内容,希望文章能够帮你解决python – pyusb:无法设置配置所遇到的程序开发问题。


如果您也喜欢它,动动您的小指点个赞吧

除非注明,文章均由 laddyq.com 整理发布,欢迎转载。

转载请注明:
链接:http://laddyq.com
来源:laddyq.com
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。


联系我
置顶