尝试在pyusb中调用后端模块时出错." AttributeError:“模块"对象没有属性“后端""

编程入门 行业动态 更新时间:2024-10-26 03:26:54
本文介绍了尝试在pyusb中调用后端模块时出错." AttributeError:“模块"对象没有属性“后端""的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我最近为此项目安装了pyusb,该项目试图尝试写入 USB LED消息登上,并收到此错误:

I recently installed pyusb for this project, which is trying to attempt at writing to a USB LED Message Board and received this error:

AttributeError:模块"对象没有属性后端"

我不知道为什么,我检查了pyusb模块文件,它显然有一个名为"backend"的文件夹.并且里面有正确的文件.

I don't know why this is, I checked the pyusb module files and it clearly has a folder named "backend" and inside has the correct files.

这是我所有的代码:

import usb.core import usb.util import sys backend = usb.backend.libusb01.get_backend(find_library=lambda C: "Users\absolute\Desktop\libusb-win32-bin-1.2.6.0\lib\msvc_x64") #LED Display Message device identify MessageDevice = usb.core.find(idVendor=0x1D34, idProduct=0x0013, backend=backend) if MessageDevice is None: raise ValueError('LED Message Display Device could not be found.') MessageDevice.set_configuration() # get an endpoint instance cfg = MessageDevice.get_active_configuration() interface_number = cfg[(0,0)].bInterfaceNumber print interface_number alternate_settting = usb.control.get_interface(interface_number) intf = usb.util.find_descriptor( cfg, bInterfaceNumber = interface_number, bAlternateSetting = alternate_setting ) ep = usb.util.find_descriptor( intf, # match the first OUT endpoint custom_match = \ lambda e: \ usb.util.endpoint_direction(e.bEndpointAddress) == \ usb.util.ENDPOINT_OUT ) assert ep is not None # write the data ep.write('\x00\x06\xFE\xBA\xAF\xFF\xFF\xFF')

要关注的代码:

backend = usb.backend.libusb01.get_backend(find_library=lambda C: "Users\absolute\Desktop\libusb-win32-bin-1.2.6.0\lib\msvc_x64")

我在其他代码中也注意到人们根本没有后端.但是,当我尝试删除代码的后端部分时,它将显示:

Also I've noticed in other code people don't have the backend at all. But when I try to remove the backend part of my code it displays:

MessageDevice = usb.core.find(idVendor=0x1D34, idProduct=0x0013) File "C:\Python27\lib\site-packages\usb\core.py", line 846, in find raise ValueError('No backend available') ValueError: No backend available

一些额外的信息:

  • Windows 8 64位
  • Python 2.7
  • pyusb-1.0.0a2
推荐答案

我知道这个问题已有4个月了,但是如果有帮助,我认为您缺少导入声明:

I know this question is 4 months old, but in case it helps I think you're missing an import statement:

import usb.backend.libusb1

请参见 github/walac/pyusb/blob/master/docs/tutorial.rst#specifying-libraries-hand 了解详情.

更多推荐

尝试在pyusb中调用后端模块时出错." AttributeError:“模块"对象没有属性“后端""

本文发布于:2023-10-22 08:16:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1516962.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:模块   后端   属性   对象   pyusb

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!