Windows 上的 libusb 错误

问题描述 投票:0回答:1

我使用 STM32 (f446re)“创建”了一个非常基本的通信类 USB 设备,它每秒只发送一个句子。现在我正在编写一个程序来在设备连接的计算机上读取上述句子。我决定使用 libusb 库,因为它显然是跨平台的,而且看起来相当容易使用。

我在 Linux 上编写了我的小程序,因为它是我用来编码的操作系统,如果您愿意,我可以提供代码的详细信息,但基本上我:

  • 列出所有设备
  • 使用PID和VID选择我的
  • 打开它
  • 分离内核驱动程序
  • 领取界面
  • 然后提交批量转账接收数据并打印到终端

使用我的 VID 和 PID 设置一些自定义 udev 规则后,它工作得很好。

所以我决定在 Windows 上尝试一下,我遇到的第一个问题是尝试打开设备时出现 LIBUSB_ERROR_NOT_SUPPORTED。经过一番谷歌搜索后,我发现 USB CDC 在 Windows 或其他设备上默认没有驱动程序(与大容量存储设备和人机接口设备不同),因此我必须安装一些通用 USB 驱动程序,例如 WinUSB。所以我这样做了,使用名为 Zadig 的软件,我还删除了分离内核驱动程序的代码,因为我显然必须这样做,现在我可以打开设备,但传输失败并显示 LIBUSB_ERROR_NOT_FOUND

我尝试了很多方法,但都不起作用,这是从打开设备开始调试级别设置为 4 的完整日志:

[ 0.077542] [00005830] libusb: debug [libusb_open] open 3.2
[ 0.078566] [000022f0] libusb: debug [libusb_claim_interface] interface 0
[ 0.078694] [000022f0] libusb: debug [winusbx_claim_interface] claimed interface 0
[ 0.079206] [000022f0] libusb: debug [windows_assign_endpoints] (re)assigned endpoint 82 to interface 0
[ 0.079853] [00000280] libusb: debug [windows_iocp_thread] ignoring overlapped 000000FB54DFF8D0 for handle 000002181F1A3310

[ 0.080480] [00000280] libusb: debug [windows_iocp_thread] ignoring overlapped 000000FB54DFF8D0 for handle 000002181F1A3310
[ 0.081122] [000022f0] libusb: debug [libusb_submit_transfer] transfer 000002181F1930E0
[ 0.081842] [00000280] libusb: debug [windows_iocp_thread] ignoring overlapped 000000FB54DFF8D0 for handle 000002181F1A3310
[ 0.085782] [000022f0] libusb: debug [add_to_flying_list] arm timer for timeout in 2000ms (first in line)
[ 0.086302] [00000280] libusb: debug [windows_iocp_thread] ignoring overlapped 000000FB54DFF8D0 for handle 000002181F1A3310
[ 0.086975] [000022f0] libusb: error [winusbx_submit_bulk_transfer] unable to match endpoint to an open interface - cancelling transfer
[ 0.087657] [00000280] libusb: debug [windows_iocp_thread] ignoring overlapped 000000FB54DFF9B0 for handle 000002181F1A3310
[ 0.088588] [000022f0] libusb: debug [arm_timer_for_next_timeout] no timeouts, disarming timer
Failed to submit bulk transfer: LIBUSB_ERROR_NOT_FOUND
[ 0.091200] [000022f0] libusb: debug [libusb_free_transfer] transfer 000002181F1930E0
[ 0.091677] [000022f0] libusb: debug [libusb_release_interface] interface 0

我不明白,包括它说“(重新)分配端点 82”,即使在我的代码中端点设置为 81,因为这是我的 USB 设备发送数据的端点。

我可以使用 USBView 发布有关 USB 设备的详细信息,或者根据需要发送部分代码。

c++ c libusb libusb-1.0 winusb
1个回答
0
投票

如果您的 USB 设备实现 USB CDC 协议,它将显示为串行端口。所有最新的操作系统都默认安装了所需的驱动程序(甚至 Windows 也已经安装了大约 10 年)。

您有三种选择来使用它:

  1. 使用跨平台库进行串行通信。使用 Google 找到一个。
  2. 使用本机 API 进行串行通信。它们在 Linux 和 macOS 上几乎相同,但在 Windows 上不同。
  3. 使用libusb进行通信。为此,您必须卸载 USB CDC 驱动程序。在 Linux 上,这很容易实现。在 macOS 上,它需要 root 权限。在 Windows 上,您必须使用 Zadig 手动执行此操作。此外,您还必须安装 WinUSB 驱动程序。

很难说出您的具体问题是什么:

  • 除非您的 Windows 版本超过 10 年,否则它将具有 USB CDC 驱动程序。但它妨碍了libusb
  • 您可能卸载了 USB CDC 驱动程序,但没有安装 WinUSB 驱动程序。这是libusb所必需的。
  • 如果您的开发板是集成 ST-Link 的 STM 开发板,您可能卸载或更换了错误设备的驱动程序。 ST-Link 是一个具有串行端口、调试端口和可能的大容量存储的复合设备。

无论如何,使用串行端口的库或API,这样你就不必弄乱驱动程序。

© www.soinside.com 2019 - 2024. All rights reserved.