pyusb:无法设置配置 [英] pyusb: cannot set configuration

查看:232
本文介绍了pyusb:无法设置配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作一个脚本(在Linux上),该脚本可以打开或关闭鼠标中的灯.

I am trying to make a script (on linux) that can turn a light in my mouse on or off.

这是我到目前为止的代码:

This is the code I have so far:

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()

This works fine but if I try to do a: dev.set_configuration()

claim_interface(dev,interface)

脚本返回错误: usb.core.USBError:资源繁忙

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

Why is it still busy after I have detached its kernel driver?

推荐答案

不确定是否可以解决,但是鼠标的udev规则是否正确设置?我在一个朋友为我做的自定义设备上也遇到了类似的问题,我通过添加如下规则来解决了这个问题:

Not sure if this will solve, but are the udev rules for your mouse being set up correctly? I had a similar problem with a custom device a friend did for me and I solved by adding a rule like:

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运行脚本.如果它将以这种方式工作,则几乎可以肯定是上述规则将修复的权限设置.

Before adding the rule, try running your script with sudo. If it will work that way it's almost certainly a permission setting that will be fixed by the above rule.

这篇关于pyusb:无法设置配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆