python libusb_usb之python(pyusb)

电脑系统为WIN7 64位

python:为python3.6 32位

需要插件PyUSB-1.0.0.tar,pywinusb-0.4.2。

按照的步骤我偷懒了,自己百度一下。

我们先看设备管理的

测试代码如下

#!/usr/bin/python

# -*- coding:utf-8 -*-

importusb.utilimportsys#USB\VID_1C4F&PID_0051

dev = usb.core.find(idVendor= 0x1C4F, idProduct= 0x0051)if dev isNone: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 32bit (Intel)] on win32

Type"copyright", "credits" or "license()" formore information.>>>

================== RESTART: C:\Users\libra\Desktop\2222.py ==================DEVICE ID 1c4f:0051 on Bus 003 Address 002 =================bLength :0x12 (18bytes)

bDescriptorType :0x1Device

bcdUSB :0x110 USB 1.1bDeviceClass :0x0Specified at interface

bDeviceSubClass :0x0bDeviceProtocol :0x0bMaxPacketSize0 :0x8 (8bytes)

idVendor :0x1c4fidProduct :0x0051bcdDevice :0x110 Device 1.1iManufacturer :0x1iProduct :0x2iSerialNumber :0x0bNumConfigurations :0x1CONFIGURATION1: 100 mA ==================================bLength :0x9 (9bytes)

bDescriptorType :0x2Configuration

wTotalLength :0x22 (34bytes)

bNumInterfaces :0x1bConfigurationValue :0x1iConfiguration :0x0bmAttributes :0xa0Bus Powered, Remote Wakeup

bMaxPower :0x32 (100mA)

INTERFACE 0: Human Interface Device====================bLength :0x9 (9bytes)

bDescriptorType :0x4Interface

bInterfaceNumber :0x0bAlternateSetting :0x0bNumEndpoints :0x1bInterfaceClass :0x3Human Interface Device

bInterfaceSubClass :0x1bInterfaceProtocol :0x2iInterface :0x0ENDPOINT0x81: Interrupt IN ==========================bLength :0x7 (7bytes)

bDescriptorType :0x5Endpoint

bEndpointAddress :0x81IN

bmAttributes :0x3Interrupt

wMaxPacketSize :0x4 (4bytes)

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, MS64\dll\libusb-1.0.dll must be copied into C:\Windows\System32 and (for running 32-bit applications that use libusb) MS32\dll\libusb-1.0.dll must be copied into C:\Windows\SysWOW64. 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 -*-

importusb.coreimportusb.utilimportsys#USB\VID_1C4F&PID_0051

dev = usb.core.find(idVendor= 0x1C4F, idProduct= 0x0051)if dev isNone: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 (18bytes)

bDescriptorType :0x1Device

bcdUSB :0x110 USB 1.1bDeviceClass :0x0Specified at interface

bDeviceSubClass :0x0bDeviceProtocol :0x0bMaxPacketSize0 :0x8 (8bytes)

idVendor :0x1c4fidProduct :0x0051bcdDevice :0x110 Device 1.1iManufacturer :0x1iProduct :0x2iSerialNumber :0x0bNumConfigurations :0x1CONFIGURATION1: 100 mA ==================================bLength :0x9 (9bytes)

bDescriptorType :0x2Configuration

wTotalLength :0x22 (34bytes)

bNumInterfaces :0x1bConfigurationValue :0x1iConfiguration :0x0bmAttributes :0xa0Bus Powered, Remote Wakeup

bMaxPower :0x32 (100mA)

INTERFACE 0: Human Interface Device====================bLength :0x9 (9bytes)

bDescriptorType :0x4Interface

bInterfaceNumber :0x0bAlternateSetting :0x0bNumEndpoints :0x1bInterfaceClass :0x3Human Interface Device

bInterfaceSubClass :0x1bInterfaceProtocol :0x2iInterface :0x0ENDPOINT0x81: Interrupt IN ==========================bLength :0x7 (7bytes)

bDescriptorType :0x5Endpoint

bEndpointAddress :0x81IN

bmAttributes :0x3Interrupt

wMaxPacketSize :0x4 (4bytes)

bInterval :0xa

############################################################

CONFIGURATION 1: 100 mA ==================================bLength :0x9 (9bytes)

bDescriptorType :0x2Configuration

wTotalLength :0x22 (34bytes)

bNumInterfaces :0x1bConfigurationValue :0x1iConfiguration :0x0bmAttributes :0xa0Bus Powered, Remote Wakeup

bMaxPower :0x32 (100mA)

INTERFACE 0: Human Interface Device====================bLength :0x9 (9bytes)

bDescriptorType :0x4Interface

bInterfaceNumber :0x0bAlternateSetting :0x0bNumEndpoints :0x1bInterfaceClass :0x3Human Interface Device

bInterfaceSubClass :0x1bInterfaceProtocol :0x2iInterface :0x0ENDPOINT0x81: Interrupt IN ==========================bLength :0x7 (7bytes)

bDescriptorType :0x5Endpoint

bEndpointAddress :0x81IN

bmAttributes :0x3Interrupt

wMaxPacketSize :0x4 (4bytes)

bInterval :0xa

View Code

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值