libusb_open返回libusb_error_not_supported在Windows 10
操作系统:Windows 10 64bit
编译器:MSVC 19 STD:C ++ 20
静态链接
我的代码下方,该代码只是初始化并打印了有关该设备的一些信息
#include "libusb.h"
#include <iostream>
int main()
{
libusb_context* cntx{ nullptr };
int status{ libusb_init(&cntx) };
if (status != LIBUSB_SUCCESS)
{
std::cerr << libusb_strerror(status);
return -1;
}
libusb_device** devices;
ssize_t numberOfDevices{ libusb_get_device_list(cntx, &devices) };
if (numberOfDevices <= 0)
{
std::cerr << "Device does NOT found\n";
return -1;
}
std::cout << "Found " << numberOfDevices << " Devices\n";
int index{ 0 };
std::cout << std::hex;
std::cout << "Device Address: " << +libusb_get_device_address(devices[index]) << '\n'
<< "Port Number: " << +libusb_get_port_number(devices[index]) << '\n'
<< "Bus Number: " << +libusb_get_bus_number(devices[index]) << '\n'
<< "Device Speed: ";
switch (libusb_get_device_speed(devices[index])
{
case LIBUSB_SPEED_SUPER: std::cout << "5Gb\n"; break;
case LIBUSB_SPEED_SUPER_PLUS: std::cout << "10Gb\n"; break;
case LIBUSB_SPEED_FULL: std::cout << "12Mb\n"; break;
case LIBUSB_SPEED_LOW: std::cout << "1.5Mb\n"; break;
case LIBUSB_SPEED_HIGH: std::cout << "480Mb\n"; break;
default: std::cout << "UNKNOWN\n"; break;
}
,但是当我想打开(例如)设备时, ],libusb_error_not_supported
将返回:
constexpr std::uint16_t VID{ 0x8086 };
constexpr std::uint16_t PID{ 0x1D26 };
libusb_device_handle* device{ nullptr };
status = libusb_open(devices[index], &device);
if (status)
{
std::cerr << "Can NOT open the device: " << libusb_strerror(status) << '\n';
device = libusb_open_device_with_vid_pid(cntx, VID, PID);
if (!device)
{
std::cerr << "Can NOT open the device with VID & PID\n";
return -1;
}
}
std::cout << "Device opened\n";
return 0;
}
两项工作。 顺便说一句,该设备是由微型程序员编程的,因此我不知道他是如何编程的,我的工作只是从设备中获取数据。
OS: Windows 10 64bit
Compiler: MSVC 19 std:c++20
static linking
I have below code which just initialize and print some information about the device
#include "libusb.h"
#include <iostream>
int main()
{
libusb_context* cntx{ nullptr };
int status{ libusb_init(&cntx) };
if (status != LIBUSB_SUCCESS)
{
std::cerr << libusb_strerror(status);
return -1;
}
libusb_device** devices;
ssize_t numberOfDevices{ libusb_get_device_list(cntx, &devices) };
if (numberOfDevices <= 0)
{
std::cerr << "Device does NOT found\n";
return -1;
}
std::cout << "Found " << numberOfDevices << " Devices\n";
int index{ 0 };
std::cout << std::hex;
std::cout << "Device Address: " << +libusb_get_device_address(devices[index]) << '\n'
<< "Port Number: " << +libusb_get_port_number(devices[index]) << '\n'
<< "Bus Number: " << +libusb_get_bus_number(devices[index]) << '\n'
<< "Device Speed: ";
switch (libusb_get_device_speed(devices[index])
{
case LIBUSB_SPEED_SUPER: std::cout << "5Gb\n"; break;
case LIBUSB_SPEED_SUPER_PLUS: std::cout << "10Gb\n"; break;
case LIBUSB_SPEED_FULL: std::cout << "12Mb\n"; break;
case LIBUSB_SPEED_LOW: std::cout << "1.5Mb\n"; break;
case LIBUSB_SPEED_HIGH: std::cout << "480Mb\n"; break;
default: std::cout << "UNKNOWN\n"; break;
}
so far so good, but when I want to open the (for example) devices[0], LIBUSB_ERROR_NOT_SUPPORTED
will return:
constexpr std::uint16_t VID{ 0x8086 };
constexpr std::uint16_t PID{ 0x1D26 };
libusb_device_handle* device{ nullptr };
status = libusb_open(devices[index], &device);
if (status)
{
std::cerr << "Can NOT open the device: " << libusb_strerror(status) << '\n';
device = libusb_open_device_with_vid_pid(cntx, VID, PID);
if (!device)
{
std::cerr << "Can NOT open the device with VID & PID\n";
return -1;
}
}
std::cout << "Device opened\n";
return 0;
}
neither works.
btw, the device was programmed by a micro-programmer so I don't know about how he programmed it, my job is just to get data from the device.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
libusb 可以枚举所有USB设备。但是它只能打开已安装 winusb 驱动程序(或 libusbk 或 libusb0 )的设备。 winusb 是直接与USB设备及其端点进行交互的通用驱动程序,而无需实现和提供自己的设备驱动程序。
如果设备不实施任何标准USB协议(质量存储,相机,音频,串行端口等),这是适当的,Windows为其提供并加载标准驱动程序,并且该设备不带有其自己的驱动程序,需要先安装。
在Linux和MacOS上,这是一个非问题,因为没有任何驱动程序麻烦的应用程序可以使用没有专用驱动程序的USB设备。
为了安装 winusb , zadig 可以使用。确保选择正确的设备,如果出现问题,可以将其拔掉。如果将驱动程序用于关键设备,例如USB主机控制器,键盘等,则PC可能不再引导。
为了自动化 winusb 安装,该设备可以实现其他USB控制请求。有两个选项:
libusb can enumerate all USB devices. But it can only open devices that have the WinUSB driver (or libusbK or libusb0) installed. WinUSB is the generic driver to interact directly with USB devices and their endpoints, without the need for implementing and providing your own device driver.
This is appropriate if the device does not implement any of the standard USB protocols (mass storage, camera, audio, serial port etc.), for which Windows provides and loads standard drivers, and if the device does not come with its own driver that needs to be installed first.
On Linux and macOS, this is a non-issue as USB devices without a dedicated driver are available to applications without any driver hassles.
In order to install WinUSB, Zadig can be used. Make sure you select the correct device, which can be unplugged if a problem occurs. If the driver is replaced for a crucial device such a USB host controller, a keyboard etc., the PC might no longer boot.
To automate the WinUSB installation, the device can implement additional USB control requests. There are two options:
安装libusb-winusb驱动程序解决了我的问题。 Zadig找不到我的ESP-Prog板,但 https://visalgdb.com/usbdrivertool/ 做到了。
如果您使用它,请连接ESP-Prog。
下载并运行
Installing the Libusb-WinUSB driver fixed my problem. zadig didn't find my ESP-PROG board but https://visualgdb.com/UsbDriverTool/ did.
Connect ESP-PROG if you will be using it.
Download and run https://visualgdb.com/UsbDriverTool/
Look for the device matching vendor ID 0403 and product ID 6010.
Change the driver to Libusb-WinUSB.