libusb_open在Windows 7上返回’LIBUSB_ERROR_NOT_SUPPORTED’

前端之家收集整理的这篇文章主要介绍了libusb_open在Windows 7上返回’LIBUSB_ERROR_NOT_SUPPORTED’前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我一直在Linux上使用LibUSB开发USB驱动程序,但现在我想为Windows编译我的一个驱动程序(这是我第一次这样做).

我的环境

我正在使用MinGW编译器(也使用Dev-cpp IDE)在Windows 7上工作,我正在使用从this link下载的预编译的libusb库.

我的设备:这是一款HID触控设备.因此Windows不需要驱动程序.我有一个额外的端点来获取某些调试数据.

我的代码

我已编译代码列出连接到我的机器的所有设备和USB设备,代码可以工作.现在我添加代码来打开设备,以便获得设备句柄并开始通信.但该函数返回-12即LIBUSB_ERROR_NOT_SUPPORTED.

我该如何解决这个问题?

我在互联网上搜索并没有找到解决这个问题的明确方法.虽然它的代码在Linux上运行得很好.

P.S.:我在下面添加了整个代码. DoList();函数工作正常,但GetTRSDevice();功能在libusb_open(dev,& handle);失败.

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <libusb.h>
  5.  
  6.  
  7. libusb_device_handle* deviceHandle = NULL;
  8.  
  9. int DoList();
  10. libusb_device_handle* GetTRSDevice(void);
  11.  
  12. int main()
  13. {
  14. int ret = libusb_init(NULL);
  15. if (ret < 0) {
  16. printf("Failed to init libusb");
  17. return ret;
  18. }
  19.  
  20. DoList();
  21. deviceHandle = GetTRSDevice();
  22. if(!deviceHandle) {
  23. printf("Failed to locate device");
  24. goto fail_dev_open;
  25. }
  26.  
  27. printf("Device opened");
  28.  
  29. libusb_close(deviceHandle);
  30. fail_dev_open:
  31. libusb_exit(NULL);
  32.  
  33. return(ret);
  34. }
  35.  
  36. int DoList()
  37. {
  38. libusb_device **devs;
  39. ssize_t cnt;
  40.  
  41.  
  42. cnt = libusb_get_device_list(NULL,&devs);
  43. if (cnt < 0)
  44. return (int) cnt;
  45.  
  46. libusb_device *dev;
  47. int i = 0;
  48.  
  49. while ((dev = devs[i++]) != NULL) {
  50. struct libusb_device_descriptor desc;
  51. int r = libusb_get_device_descriptor(dev,&desc);
  52. if (r < 0) {
  53. fprintf(stderr,"Failed to get device descriptor");
  54. return(-1);
  55. }
  56.  
  57. printf("%04x:%04x (bus %d,device %d)\n",desc.idVendor,desc.idProduct,libusb_get_bus_number(dev),libusb_get_device_address(dev));
  58. }
  59. libusb_free_device_list(devs,1);
  60. return 0;
  61. }
  62.  
  63. libusb_device_handle* GetTRSDevice(void)
  64. {
  65. int i = 0;
  66. ssize_t cnt;
  67. libusb_device *dev;
  68. libusb_device **devs;
  69. libusb_device_handle* handle = NULL;
  70.  
  71. cnt = libusb_get_device_list(NULL,&devs);
  72. if (cnt < 0) {
  73. printf("Failed libusb_get_device_list");
  74. return(0);
  75. }
  76.  
  77. while ((dev = devs[i++]) != NULL) {
  78. struct libusb_device_descriptor desc;
  79. int ret = libusb_get_device_descriptor(dev,&desc);
  80. if (ret < 0) {
  81. printf("Failed libusb_get_device_descriptor");
  82. continue;
  83. }
  84. if(desc.idVendor == 0X238f && desc.idProduct == 1) {
  85. int ret = libusb_open(dev,&handle);
  86. if (ret < 0) {
  87. printf("Failed libusb_open: %d\n\r",ret);
  88. break;
  89. }
  90. #ifndef WIN32
  91. libusb_detach_kernel_driver(handle,0);
  92. #endif
  93. ret = libusb_claim_interface(handle,0);
  94. if (ret < 0) {
  95. libusb_close(handle);
  96. handle=NULL;
  97. break;
  98. }
  99. break;
  100. }
  101. }
  102. libusb_free_device_list(devs,1);
  103. return(handle);
  104. }
您似乎需要安装winusb驱动程序 – libusb可以获取有关没有此驱动程序的设备的信息,但它无法打开它们.

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

On Wed,Apr 4,2012 at 11:52 PM,Quân Phạm Minh <[hidden email]>
wrote:

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

是的,这是可能的.但是你无法打开设备并做进一步的工作的东西.对于新用户而言,这是一个令人困惑的部分libusb Windows后端,同样适用于Mac OS X. libusb的可以获取具有不正确驱动程序的设备的一些基本信息(例如:USB大容量存储设备),但无法打开设备没有将驱动程序更改为支持的驱动程序. – 小凡

猜你在找的Windows相关文章