PATH environment variable
每当我们使用 PyUSB 模块与 PC 进行 USB 通信时,PyUSB 模块将检查位置和位置中的 libusb0.dll 和 libusb-1.0.dll 文件(充当后端),C:\windows\System32
然后建立与 USB 设备的通信。由于我使用 libusb-win32-wizard 创建设备驱动程序,因此它使用 libusb0.dll。可以使用以下 DEBUG 程序找到执行过程:
import os
os.environ['PYUSB_DEBUG'] = 'debug'
import usb.core
print list(usb.core.find(find_all=True))
当我在Shell中执行上述程序时,我得到的输出是:
2016-03-26 11:41:44,280 ERROR:usb.libloader:'Libusb 1' could not be found
2016-03-26 11:41:44,280 ERROR:usb.backend.libusb1:Error loading libusb 1.0 backend
2016-03-26 11:41:44,280 ERROR:usb.libloader:'OpenUSB library' could not be found
2016-03-26 11:41:44,280 ERROR:usb.backend.openusb:Error loading OpenUSB backend
2016-03-26 11:41:44,280 INFO:usb.core:find(): using backend "usb.backend.libusb0"
2016-03-26 11:41:44,280 DEBUG:usb.backend.libusb0:_LibUSB.enumerate_devices()
2016-03-26 11:41:44,296 DEBUG:usb.backend.libusb0:_LibUSB.get_device_descriptor(<usb.backend.libusb0._usb_device object at 0x0200E530>)
2016-03-26 11:41:44,296 DEBUG:usb.backend.libusb0:_LibUSB.get_device_descriptor(<usb.backend.libusb0._usb_device object at 0x0200E5D0>)
2016-03-26 11:41:44,296 DEBUG:usb.backend.libusb0:_LibUSB.get_device_descriptor(<usb.backend.libusb0._usb_device object at 0x0200E6C0>)
2016-03-26 11:41:44,296 DEBUG:usb.backend.libusb0:_LibUSB.get_device_descriptor(<usb.backend.libusb0._usb_device object at 0x0200E7B0>)
2016-03-26 11:41:44,296 DEBUG:usb.backend.libusb0:_LibUSB.get_device_descriptor(<usb.backend.libusb0._usb_device object at 0x0200E8A0>)
2016-03-26 11:41:44,296 DEBUG:usb.backend.libusb0:_LibUSB.get_device_descriptor(<usb.backend.libusb0._usb_device object at 0x0200E990>)
2016-03-26 11:41:44,296 DEBUG:usb.backend.libusb0:_LibUSB.get_device_descriptor(<usb.backend.libusb0._usb_device object at 0x0200EA80>)
2016-03-26 11:41:44,296 DEBUG:usb.backend.libusb0:_LibUSB.get_device_descriptor(<usb.backend.libusb0._usb_device object at 0x0200EB70>)
[<DEVICE ID 046d:c05a on Bus 000 Address 001>, <DEVICE ID 046d:c31d on Bus 000 Address 002>, <DEVICE ID 046d:c31d on Bus 000 Address 003>, <DEVICE ID 046d:c31d on Bus 000 Address 004>, <DEVICE ID 04d8:feaa on Bus 000 Address 005>, <DEVICE ID 046d:082b on Bus 000 Address 006>, <DEVICE ID 046d:082b on Bus 000 Address 007>, <DEVICE ID 046d:082b on Bus 000 Address 008>]
所以在这里,因为我find_all=True
在usb.core.find()
函数中给出了参数,所以它返回每个连接到 PC 的设备 ID。同样在前 4 行它给出了错误,因为我们使用了 libusb0.dll 的 lib-usb-win32-wizard,因此在第 5 行它给出了INFO:usb.core:find(): using backend "usb.backend.libusb0"
这意味着它正在使用 libusb0.dll 与 USB 设备进行通信。