Windows pyusb的使用

Download Data Center Software from Total Phase.

1 SEP5010 DriverStudio
NuMega DriverStudio, acquired by Compuware.

2 USB驱动安装工具Zadig
Akeo Consulting is a small Software Development company, established in the North-West of Ireland, in the breathtaking wilderness of County Donegal.
Zadig - USB driver installation made easy, based on Windows Driver Installer library (libwdi).
https://zadig.akeo.ie/

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

3.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)

3.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/

打开压缩包,选择VS2015-x64\dll\libusb-1.0.dll,复制到C:\Windows\System32,System32 for both 32bit and 64bit applications。
选择同目录下的VS2015-x64\dll\libusb-1.0.lib,复制到C:\Python38\Lib。使用命令where python查找python在Win10的安装路径。

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

def control_out(d):
    bmRequestType =
        usb.util.build_request_type(
        # 如果无数据传输,必须是CTRL_OUT,
        # 否则ctrl_transfer()不会返回
        usb.util.CTRL_OUT,
        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")

def bulkloop(d):
    # bytes stream
    data = b'\x01\x02'
    len = d.write(0x02, data, 1000)
    pkt = d.read(0x86, len, 1000)
    # print(type(pkt))
    data = bytes(pkt)

all_devs = usb.core.find(find_all=True)
for d in all_devs:
    if (d.idVendor == 0x04B4) &
        (d.idProduct == 0x1004):
        print(d)
        control_out(d)
        bulkloop(d)

4 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

5 libusb backend
C:\Windows\System32\winusb.dll
C:\Windows\System32\drivers\winusb.sys
libusb/os/windows_common.c, windows_init() will find a valid Windows backend dll.

6 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

  • 0
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
嗨!对于使用Python编程来控制USB设备,你可以使用`pyusb`库。`pyusb`允许你与USB设备进行通信,发送和接收数据。 如果你还没有安装`pyusb`库,你可以使用以下命令在Python环境中安装它: ``` pip install pyusb ``` 一旦你安装好了`pyusb`库,你可以开始使用它来控制USB设备。你需要先找到你要控制的USB设备的设备号,然后打开连接并与设备进行通信。 下面是一个简单的例子,演示如何使用`pyusb`发送和接收数据: ```python import usb.core # 在这里设置你的USB设备的vendor id和product id vendor_id = 0xXXXX product_id = 0xXXXX # 查找设备 dev = usb.core.find(idVendor=vendor_id, idProduct=product_id) # 打开设备连接 dev.open() # 发送数据 data = [0x01, 0x02, 0x03] dev.write(1, data) # 接收数据 recv_data = dev.read(0x81, 64) # 关闭设备连接 dev.close() ``` 在上面的代码中,你需要替换`vendor_id`和`product_id`为你要控制的USB设备的对应值。然后,使用`usb.core.find()`方法查找设备并打开连接。然后,你可以使用`dev.write()`方法发送数据,使用`dev.read()`方法接收数据,并使用`dev.close()`方法关闭连接。 请注意,使用`pyusb`控制USB设备需要一些USB设备的相关知识,如设备的vendor id、product id、端点地址等。你需要查找并了解你要控制的具体USB设备的规格和协议。 希望这个例子能帮到你!如果有任何更多的问题,请随时提问。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值