电脑系统为WIN7 64位
python:为python3.6 32位
需要插件PyUSB-1.0.0.tar,pywinusb-0.4.2。
按照的步骤我偷懒了,自己百度一下。
我们先看设备管理的
测试代码如下
#!/usr/bin/python
# -*- coding:utf-8 -*-
import usb.util import sys #USBVID_1C4F&PID_0051 dev = usb.core.find(idVendor= 0x1C4F, idProduct= 0x0051) if dev is None: raise ValueError('Device not found') print(dev) # set the active configuration. With no arguments, the first # configuration will be the active one cfg = dev.get_active_configuration()
测试结果
Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 07:18:10) [MSC v.1900 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. >>> ================== RESTART: C:UserslibraDesktop2222.py ================== DEVICE ID 1c4f:0051 on Bus 003 Address 002 ================= bLength : 0x12 (18 bytes) bDescriptorType : 0x1 Device bcdUSB : 0x110 USB 1.1 bDeviceClass : 0x0 Specified at interface bDeviceSubClass : 0x0 bDeviceProtocol : 0x0 bMaxPacketSize0 : 0x8 (8 bytes) idVendor : 0x1c4f idProduct : 0x0051 bcdDevice : 0x110 Device 1.1 iManufacturer : 0x1 iProduct : 0x2 iSerialNumber : 0x0 bNumConfigurations : 0x1 CONFIGURATION 1: 100 mA ================================== bLength : 0x9 (9 bytes) bDescriptorType : 0x2 Configuration wTotalLength : 0x22 (34 bytes) bNumInterfaces : 0x1 bConfigurationValue : 0x1 iConfiguration : 0x0 bmAttributes : 0xa0 Bus Powered, Remote Wakeup bMaxPower : 0x32 (100 mA) INTERFACE 0: Human Interface Device ==================== bLength : 0x9 (9 bytes) bDescriptorType : 0x4 Interface bInterfaceNumber : 0x0 bAlternateSetting : 0x0 bNumEndpoints : 0x1 bInterfaceClass : 0x3 Human Interface Device bInterfaceSubClass : 0x1 bInterfaceProtocol : 0x2 iInterface : 0x0 ENDPOINT 0x81: Interrupt IN ========================== bLength : 0x7 (7 bytes) bDescriptorType : 0x5 Endpoint bEndpointAddress : 0x81 IN bmAttributes : 0x3 Interrupt wMaxPacketSize : 0x4 (4 bytes) bInterval : 0xa
如果先出现系统无法识别的话
可以参考
https://stackoverflow.com/questions/33972145/pyusb-on-windows-8-1-no-backend-available-how-to-install-libusb
I downloaded latest libusb windows binaries from here: http://sourceforge.net/projects/libusb/files/libusb-1.0/libusb-1.0.20/libusb-1.0.20.7z/download then I copied libusb1.dll according to this: when you are on 64-bit Windows, MS64dlllibusb-1.0.dll must be copied into C:WindowsSystem32 and (for running 32-bit applications that use libusb) MS32dlllibusb-1.0.dll must be copied into C:WindowsSysWOW64. and then I copied libusb1.lib from binaries to lib dir in python directory and now pyusb works for me. hope it helps. |
继续
#!/usr/bin/python
# -*- coding:utf-8 -*-
import usb.core import usb.util import sys #USBVID_1C4F&PID_0051 dev = usb.core.find(idVendor= 0x1C4F, idProduct= 0x0051) if dev is None: raise ValueError('Device not found') print(dev) # set the active configuration. With no arguments, the first # configuration will be the active one cfg = dev.get_active_configuration() print("#"*60) print(cfg)
================= RESTART: C:/Users/libra/Desktop/3333333.py ================= DEVICE ID 1c4f:0051 on Bus 003 Address 002 ================= bLength : 0x12 (18 bytes) bDescriptorType : 0x1 Device bcdUSB : 0x110 USB 1.1 bDeviceClass : 0x0 Specified at interface bDeviceSubClass : 0x0 bDeviceProtocol : 0x0 bMaxPacketSize0 : 0x8 (8 bytes) idVendor : 0x1c4f idProduct : 0x0051 bcdDevice : 0x110 Device 1.1 iManufacturer : 0x1 iProduct : 0x2 iSerialNumber : 0x0 bNumConfigurations : 0x1 CONFIGURATION 1: 100 mA ================================== bLength : 0x9 (9 bytes) bDescriptorType : 0x2 Configuration wTotalLength : 0x22 (34 bytes) bNumInterfaces : 0x1 bConfigurationValue : 0x1 iConfiguration : 0x0 bmAttributes : 0xa0 Bus Powered, Remote Wakeup bMaxPower : 0x32 (100 mA) INTERFACE 0: Human Interface Device ==================== bLength : 0x9 (9 bytes) bDescriptorType : 0x4 Interface bInterfaceNumber : 0x0 bAlternateSetting : 0x0 bNumEndpoints : 0x1 bInterfaceClass : 0x3 Human Interface Device bInterfaceSubClass : 0x1 bInterfaceProtocol : 0x2 iInterface : 0x0 ENDPOINT 0x81: Interrupt IN ========================== bLength : 0x7 (7 bytes) bDescriptorType : 0x5 Endpoint bEndpointAddress : 0x81 IN bmAttributes : 0x3 Interrupt wMaxPacketSize : 0x4 (4 bytes) bInterval : 0xa ############################################################ CONFIGURATION 1: 100 mA ================================== bLength : 0x9 (9 bytes) bDescriptorType : 0x2 Configuration wTotalLength : 0x22 (34 bytes) bNumInterfaces : 0x1 bConfigurationValue : 0x1 iConfiguration : 0x0 bmAttributes : 0xa0 Bus Powered, Remote Wakeup bMaxPower : 0x32 (100 mA) INTERFACE 0: Human Interface Device ==================== bLength : 0x9 (9 bytes) bDescriptorType : 0x4 Interface bInterfaceNumber : 0x0 bAlternateSetting : 0x0 bNumEndpoints : 0x1 bInterfaceClass : 0x3 Human Interface Device bInterfaceSubClass : 0x1 bInterfaceProtocol : 0x2 iInterface : 0x0 ENDPOINT 0x81: Interrupt IN ========================== bLength : 0x7 (7 bytes) bDescriptorType : 0x5 Endpoint bEndpointAddress : 0x81 IN bmAttributes : 0x3 Interrupt wMaxPacketSize : 0x4 (4 bytes) bInterval : 0xa