Windows pyusb的使用

1 USB驱动安装工具Zadig
Zadig - USB driver installation made easy
https://zadig.akeo.ie/

其中ie表示Ireland爱尔兰。Zadig基于libwdi(Windows Driver Installer library)开发。

2 libusb for Windows
2.1 注意点
测试pyusb与adb驱动通信时,需要运行adb kill-server,才可以使用pyusb;否则调用pyusb的API会返回没有权限错误

2.2 查找是否安装过libusb
import ctypes
from ctypes import util, cdll
import os
import sys

if sys.platform == 'win32':
    libname = ctypes.util.find_library('libusb-1.0')
else:
    libname = ctypes.util.find_library('usb-1.0')
if libname is None:
    raise OSError('USB library could not be found')

print (libname)

2.3 pyusb的安装及使用
1)安装Python 3.8
安装时选择安装pip工具

2)pyusb
https://github.com/pyusb/pyusb

python -m pip install pyusb
或者
cd PATH_TO\PyUSB
python setup.py install

3)libusb
https://libusb.info/

打开压缩包,选择MS64\dll\libusb-1.0.dll,复制到C:\Windows\System32
选择同目录下的MS64\dll\libusb-1.0.lib,复制到C:\Python38\Lib

4)例子
import os
os.environ['PYUSB_DEBUG'] = 'debug'
import usb.util
import usb.core
import sys

all_devs = usb.core.find(find_all=True)
for d in all_devs:
    if (d.idVendor == 0x8087) & (d.idProduct == 0x09ef):
        print(d)
        bmRequestType = usb.util.build_request_type(
            usb.util.CTRL_OUT, # 如果无数据传输,必须是CTRL_OUT,否则ctrl_transfer()不会返回     
            usb.util.CTRL_TYPE_STANDARD,
            usb.util.CTRL_RECIPIENT_INTERFACE)
        #d.ctrl_transfer(bmRequestType, 0x40, 0, 0, [])
        d.ctrl_transfer(bmRequestType, 0x40, 0, 0, "test")
        exit(0)

3 python hidapi
1)下载hidapi whl文件
hidapi 0.7.99.post21
https://pypi.org/project/hidapi/#files

2)安装hidapi whl
pip install PATH_TO\filename.whl

升级安装:
pip install -U PATH_TO\filename.whl

4 libusbK
libusbK:基于KMDF框架开发,与MS WinUSB同样的作用
libusb:Linux上基于usbfs;Windows上基于WinUSB或者libusbK

5 Abbreviations
ARC:Argonant RISC Core
AT91SAM9260:SAM means Smart ARM-based Microcontroller
ATMEL SAMBA:ATMEL Smart ARM-based Microcontroller Boot Assistant
CC2530:TI ChipCon2530
DWC2:Design Ware Controller 2,Apple的嵌入式设备,包括iPad和iPhone都是使用的DWC2
ISP1161:Philips' Integrated host Solution Pairs 1161,“Firms introduce USB host controllers”,https://www.eetimes.com/document.asp?doc_id=1290054
Quirks:the attributes of a device that are considered to be noncompliant with expected operation
SL811HS:Cypress/ScanLogic 811 Host/Slave,性能上与ISP1161(Integrated host Solution Pairs 1161)相当
TDI:TransDimension Inc.,该公司首先发明了将TT集成到EHCI RootHub中的方法,这样对于嵌入式系统来说,就省去了OHCI/UHCI的硬件,同时降低了成本,作为对该公司的纪念,Linux内核定义了宏ehci_is_TDI(ehci);产品UHC124表示USB Host Controller;收购了ARC USB技术;现已被chipidea收购,chipidea又被mips收购
TLV:TI Low Value,高性价比
TPS:TI Performance Solution
TT:Transaction Translator(事务转换器,将USB2.0的包转换成USB1.1的包)
USB BH reset:Bigger Hammer or Brad Hosler,表示warm reset;you may be confused why the USB 3.0 spec calls the same type of reset "warm reset" in some places and "BH reset" in other places. "BH" reset is supposed to stand for "Big Hammer" reset, but it also stands for "Brad Hosler". Brad died shortly after the USB 3.0 bus specification was started, and they decided to name the reset after him. The suggestion was made shortly before the spec was finalized, so the wording is a bit inconsistent
WHL:Python Wheel Package
Zadig:an Automated Driver Installer GUI application for WinUSB, libusb-win32 and libusbK

发布了124 篇原创文章 · 获赞 51 · 访问量 32万+

猜你喜欢

转载自blog.csdn.net/zoosenpin/article/details/75583633