即使在路径中显示加载的dll,PyUSB也没有可用的后端

时间:2017-05-31 19:53:35

标签: python path usb pyusb libusb-1.0

我在pyusb中收到一个没有后端错误,尽管我在路径中安装了LibUSB 1,并且在代码的早期加载得很好。我的代码是

import usb.core
import usb.util
import usb.backend.libusb1
import sys

class USBConnection:
def __init__(self, vendor_id, product_id):
    usb.backend.libusb1.get_backend(find_library=lambda x: 'C:\Windows\System32\libusb-1.0.dll')
    self.device = usb.core.find(idVendor=vendor_id, idProduct=product_id)
    if self.device is None:
        sys.exit('Could not find device')
    else:
        print 'Device detected'
    self.device.set_configuration()
    self.configuration = self.device.get_active_configuration()
    self.description = self.configuration[(0, 0)]
    self.end_point = usb.util.find_descriptor(self.description, custome_match=lambda e: usb.util.endpoint_direction
                                              (e.bEndpointAddress) == usb.util.ENDPOINT_OUT)
    assert self.end_point is not None

def write(self, data):
    self.end_point.write(data)

if __name__ == '__main__':
    channel = USBConnection(vendor_id='2A19', product_id='1002')

运行此代码返回

Traceback (most recent call last):
  File "C:/Users/me/PycharmProjects/usbfreqsweep/usbsweep.py", line 126, in <module>
channel = USBConnection(vendor_id='2A19', product_id='1002')
  File "C:/Users/me/PycharmProjects/usbfreqsweep/usbsweep.py", line 110, in __init__
self.device = usb.core.find(idVendor=vendor_id, idProduct=product_id)
  File "C:\Python27\lib\site-packages\usb\core.py", line 1263, in find
raise NoBackendError('No backend available')
usb.core.NoBackendError: No backend available

我确实在我的路径中包含了llibusb-1.0.dll且安装了最新版本的libusb1的C:\ windows \ system32,但我仍然收到此错误。这是事实

    usb.backend.libusb1.get_backend(find_library=lambda x: 'C:\Windows\System32\libusb-1.0.dll')

不会返回错误。甚至更奇怪,设置

backend = usb.backend.libusb1.get_backend(find_library=lambda x: 'C:\Windows\System32\libusb-1.0.dll')

并在调试器中执行返回值为None的后端。有没有好办法解决这个问题?我正在使用Windows 7,如果有帮助的话。

0 个答案:

没有答案