Python 中的 USB 接口
USB interface in Python
我将此 (http://www.gesytec.de/en/download/easylon/p/16/) USB 设备连接到我的 Win7。我只是想读取供应商 ID 和产品 ID。我有 Python 2.7.
这是代码,
import usb
busses = usb.busses()
for bus in busses:
devices = bus.devices
for dev in devices:
print "Device:", dev.filename
print " idVendor: %d (0x%04x)" % (dev.idVendor, dev.idVendor)
print " idProduct: %d (0x%04x)" % (dev.idProduct, dev.idProduct)
我收到以下错误,
"File "<stdin>", line 1, in <module>
File "C:\Python27\lib\usb\core.py", line 846, in find
raise ValueError('No backend available')
ValueError: No backend available"
我在这里做错了什么?
你安装usb库包了吗?如果是这样,您可能需要将其添加到您的路径中。
我最终使用了制造商提供的 dll 而不是 USB 库。
currently used library
import usb.core
import usb.backend.libusb0
backend = usb.backend.libusb0.get_backend(find_library=lambda x: "C:\Windows\system32\libusb0.dll")
# find your device #1
devices = usb.core.find(find_all=True)
for d in devices:
print(d)
# find your device #2
import usb
busses = usb.busses()
for bus in busses:
devices = bus.devices
for dev in devices:
print("Device:", dev.filename)
print (" idVendor: %d (0x%04x)" % (dev.idVendor, dev.idVendor))
print (" idProduct: %d (0x%04x)" % (dev.idProduct, dev.idProduct))
我将此 (http://www.gesytec.de/en/download/easylon/p/16/) USB 设备连接到我的 Win7。我只是想读取供应商 ID 和产品 ID。我有 Python 2.7.
这是代码,
import usb
busses = usb.busses()
for bus in busses:
devices = bus.devices
for dev in devices:
print "Device:", dev.filename
print " idVendor: %d (0x%04x)" % (dev.idVendor, dev.idVendor)
print " idProduct: %d (0x%04x)" % (dev.idProduct, dev.idProduct)
我收到以下错误,
"File "<stdin>", line 1, in <module>
File "C:\Python27\lib\usb\core.py", line 846, in find
raise ValueError('No backend available')
ValueError: No backend available"
你安装usb库包了吗?如果是这样,您可能需要将其添加到您的路径中。
我最终使用了制造商提供的 dll 而不是 USB 库。
currently used library
import usb.core
import usb.backend.libusb0
backend = usb.backend.libusb0.get_backend(find_library=lambda x: "C:\Windows\system32\libusb0.dll")
# find your device #1
devices = usb.core.find(find_all=True)
for d in devices:
print(d)
# find your device #2
import usb
busses = usb.busses()
for bus in busses:
devices = bus.devices
for dev in devices:
print("Device:", dev.filename)
print (" idVendor: %d (0x%04x)" % (dev.idVendor, dev.idVendor))
print (" idProduct: %d (0x%04x)" % (dev.idProduct, dev.idProduct))