Libusb_open returns 'LIBUSB_ERROR_NOT_SUPPORTED' on Windows 7

I am developing USB drivers using LibUSB on Linux, but now I want one of my drivers to be compiled for Windows (this is the first time I do this).

My environment

I am working on Windows 7 using the MinGW compiler (also using the Dev-cpp IDE), and I am using the pre-compiled libusb library downloaded from this link .

My device: This is a HID touch device. Therefore, Windows drivers are not required. I have an extra endpoint for getting certain debugging data.

My code is:

I compiled the code to list all the devices and USB devices connected to my machine and the code works. Now I am adding code to open the device, to get the device descriptor and start communication. But the function returns -12 That is, LIBUSB_ERROR_NOT_SUPPORTED.

How can I fix this problem?

I searched through the Internet and did not find a specific solution to this problem. Although this is code that works great on Linux.

PS: I added all the code below. Function DoList(); works fine, but the GetTRSDevice(); function GetTRSDevice(); working with the error libusb_open(dev, &handle); .

 #include <stdio.h> #include <stdlib.h> #include <string.h> #include <libusb.h> libusb_device_handle* deviceHandle = NULL; int DoList(); libusb_device_handle* GetTRSDevice(void); int main() { int ret = libusb_init(NULL); if (ret < 0) { printf("Failed to init libusb"); return ret; } DoList(); deviceHandle = GetTRSDevice(); if(!deviceHandle) { printf("Failed to locate device"); goto fail_dev_open; } printf("Device opened"); libusb_close(deviceHandle); fail_dev_open: libusb_exit(NULL); return(ret); } int DoList() { libusb_device **devs; ssize_t cnt; cnt = libusb_get_device_list(NULL, &devs); if (cnt < 0) return (int) cnt; libusb_device *dev; int i = 0; while ((dev = devs[i++]) != NULL) { struct libusb_device_descriptor desc; int r = libusb_get_device_descriptor(dev, &desc); if (r < 0) { fprintf(stderr, "failed to get device descriptor"); return(-1); } printf("%04x:%04x (bus %d, device %d)\n", desc.idVendor, desc.idProduct, libusb_get_bus_number(dev), libusb_get_device_address(dev)); } libusb_free_device_list(devs, 1); return 0; } libusb_device_handle* GetTRSDevice(void) { int i = 0; ssize_t cnt; libusb_device *dev; libusb_device **devs; libusb_device_handle* handle = NULL; cnt = libusb_get_device_list(NULL, &devs); if (cnt < 0) { printf("Failed libusb_get_device_list"); return(0); } while ((dev = devs[i++]) != NULL) { struct libusb_device_descriptor desc; int ret = libusb_get_device_descriptor(dev, &desc); if (ret < 0) { printf("Failed libusb_get_device_descriptor"); continue; } if(desc.idVendor == 0X238f && desc.idProduct == 1) { int ret = libusb_open(dev, &handle); if (ret < 0) { printf("Failed libusb_open: %d\n\r",ret); break; } #ifndef WIN32 libusb_detach_kernel_driver(handle, 0); #endif ret = libusb_claim_interface(handle,0); if (ret < 0) { libusb_close(handle); handle=NULL; break; } break; } } libusb_free_device_list(devs, 1); return(handle); } 
+7
source share
2 answers

It seems you need to install the winusb driver - libusb can get device information without this driver, but it cannot open them.

http://libusb.6.n5.nabble.com/LIBUSB-ERROR-NOT-SUPPORTED-td5617169.html :

On Wed, Apr 4, 2012 at 11:52 am, QuΓ’n PhαΊ‘m Minh <[hidden email]> wrote:

although I never install the winusb driver, but I use libusb to get my usb information (kingston usb, and already recognized by the system)

Yes it is possible. But you cannot open the device and do things. This is a confusing part for new users regarding Windows libusb, as well as Mac OS X. libusb may get some basic information for a device with an unreliable driver (for example: a USB storage device), but it cannot open without changing the driver to a supported one.

- Xiaofan

+8
source

You can easily install the WinUSB driver or other drivers supported by libusb (libusb-win32 and libusbK) using the Zadig application, which was developed only to solve this problem. See http://zadig.akeo.ie .

However, remember that if you replace the Mass Storage driver or HID (which is automatically installed by Windows) using WinUSB, you will be able to access your device via libusb and you will not be able to access your device as Mass Storage or HID until you uninstall the WinUSB driver.

Finally, if you have control over the firmware for your device, it is also possible to create devices that automatically install the WinUSB driver in Vista or later, so that users do not have to go through the manual driver installation (this may require a connection to Windows Update for Windows 7 or earlier, but it should work even without an Internet connection for Windows 8 or later). See https://github.com/pbatard/libwdi/wiki/WCID-Devices .

[DISCLAIMER] I am the author of Zadig / libwi, WCID wiki pages, and contributor to the libusb Windows backend.

+6
source

All Articles