PyUSB usb.core.USBError: [Errno 5] Input/Output Error in Windows

PyUSB usb.core.USBError: [Errno 5] Input/Output Error in Windows

我有一个 Python 代码使用 PyUSB 与如下所示的设备通信:

import usb.core
import usb.util

device = usb.core.find(idVendor=0xC251, idProduct=0x2201)

packet = [90]
number_of_bytes_sent = device.ctrl_transfer(
    bmRequestType = 0x21,
    bRequest = 9,
    wValue = 0x200,
    wIndex = 0,
    data_or_wLength = packet,
)
print(f'{number_of_bytes_sent} bytes were sent')

我得到

usb.core.USBError: [Errno 5] Input/Output Error

device.ctrl_transfer 通话中。该代码在同一台设备上 Linux 上运行,但在 Windows 上运行失败 10。可能是什么问题?

随机尝试后我发现在 Windows 中填充长度不超过 64 的零是可行的。不要问我为什么。所以现在我的代码是:

import usb.core
import usb.util
import platform

device = usb.core.find(idVendor=0xC251, idProduct=0x2201)

packet = [90]
if platform.system() == 'Windows':
    packet = packet + (64-len(packet))*[0] # I don't know why this has to be done on Windows.
number_of_bytes_sent = device.ctrl_transfer(
    bmRequestType = 0x21,
    bRequest = 9,
    wValue = 0x200,
    wIndex = 0,
    data_or_wLength = packet,
)
print(f'{number_of_bytes_sent} bytes were sent')