gpt4 book ai didi

python - 将 libusb 代码移植到 Python : interrupt transfer

转载 作者:行者123 更新时间:2023-11-30 05:14:43 26 4
gpt4 key购买 nike

这是在 C++ 中使用 libusb 执行中断传输的两行代码:

libusb_fill_interrupt_transfer(transfer_receive, handle, LIBUSB_ENDPOINT_IN | USB_INTERFACE_OUT, buffer_receive, sizeof(buffer_receive), cb_in, &usb_data, 30000);
r = libusb_submit_transfer(transfer_receive);

如何使用 PyUSB 在 Python 中做同样的事情?

最佳答案

有函数interruptWrite(self, endpoint, buffer, timeout = 100)interruptRead(self, endpoint, size, timeout = 100),见

https://github.com/walac/pyusb/blob/master/usb/legacy.py

interruptRead()函数类似于C++代码(轮询设备中断,从设备中断IN端点接收中断数据)

LIBUSB_ENDPOINT_IN | USB_INTERFACE_OUT (| is bitwise OR ) 在C++中类似使用指定的USB中断接口(interface)USB_INTERFACE_OUT从其指定端点LIBUSB_ENDPOINT_IN查询数据>

在后台 PyUSB 使用相同的函数 (write()) 进行批量中断等时传输,只有控制传输有特殊语法。 interruptWrite()interruptRead() 也使用了 write() 函数来抽象底层原生 USB 传输类型

USB has four flavors of transfers: bulk, interrupt, isochronous and control. [ ... ]

Control transfer is the only transfer that has structured data described in the spec, the others just send and receive raw data from USB point of view. Because of it, you have a different function to deal with control transfers, all the other transfers are managed by the same functions.

You issue a control transfer through the ctrl_transfer method. It is used both for OUT and IN transfers. The transfer direction is determined from the bmRequestType parameter.

来源:https://github.com/walac/pyusb/blob/master/docs/tutorial.rst

一般情况下,如果设备有中断未决,则设备仅在中断传输时应答,因此主机通过中断传输轮询设备的中断。这在发送中断请求(传输)并等待接收应答的 C++ 代码中变得很明显

http://mvidner.blogspot.com/2017/01/usb-communication-with-python-and-pyusb.html

关于python - 将 libusb 代码移植到 Python : interrupt transfer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43351244/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com