我对此很新,所以请和我一起出去!
我最近为这个项目安装了pyusb,它试图写入USB LED Message Board并收到此错误:
AttributeError: 'module' object has no attribute 'backend'
我不知道为什么会这样,我检查了pyusb模块文件,它显然有一个名为“backend”的文件夹,里面有正确的文件 .
这是我的所有代码:
import usb.core
import usb.util
import sys
backend = usb.backend.libusb01.get_backend(find_library=lambda C: "Users\nabakin\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\nabakin\Desktop\libusb-win32-bin-1.2.6.0\lib\msvc_x64")
我也注意到在其他代码中人们根本没有后端 . 但是,当我尝试删除代码的后端部分时,它会显示:
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
谢谢大家,我真的很感激你在这里做的
1 回答
我知道这个问题是4个月大,但是如果它有所帮助我认为你错过了一个import语句:
有关详细信息,请参阅https://github.com/walac/pyusb/blob/master/docs/tutorial.rst#specifying-libraries-by-hand .