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); }
Prajosh premdas
source share