Код: Выделить всё
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
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
Код: Выделить всё
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')
Подробнее здесь: https://stackoverflow.com/questions/442 ... tly-loaded