libusb bulk transfers通信超时,急!

我的问题:libusb_bulk_transfer读数据报错:超时

我的USB设备信息:
Bus 001 Device 005: ID 2207:0011  
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.10
  bDeviceClass            0 (Defined at Interface level)
  bDeviceSubClass         0 
  bDeviceProtocol         0 
  bMaxPacketSize0        64
  idVendor           0x2207 
  idProduct          0x0011 
  bcdDevice            3.10
  iManufacturer           1 rockchip
  iProduct                2 rk3xxx
  iSerial                 3 6555895b72d658ff
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength           62
    bNumInterfaces          2
    bConfigurationValue     1
    iConfiguration          4 adb_mtp
    bmAttributes         0x80
      (Bus Powered)
    MaxPower              500mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           3
      bInterfaceClass       255 Vendor Specific Class
      bInterfaceSubClass    255 Vendor Specific Subclass
      bInterfaceProtocol      0 
      iInterface              5 MTP
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0200  1x 512 bytes
        bInterval               0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x01  EP 1 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0200  1x 512 bytes
        bInterval               0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x82  EP 2 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x001c  1x 28 bytes
        bInterval               6
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       0
      bNumEndpoints           2
      bInterfaceClass       255 Vendor Specific Class
      bInterfaceSubClass     66 
      bInterfaceProtocol      1 
      iInterface              6 ADB Interface
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x02  EP 2 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0200  1x 512 bytes
        bInterval               0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x83  EP 3 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0200  1x 512 bytes
        bInterval               0
Binary Object Store Descriptor:
  bLength                 5
  bDescriptorType        15
  wTotalLength           22
  bNumDeviceCaps          2
  USB 2.0 Extension Device Capability:
    bLength                 7
    bDescriptorType        16
    bDevCapabilityType      2
    bmAttributes   0x00000006
      Link Power Management (LPM) Supported
  SuperSpeed USB Device Capability:
    bLength                10
    bDescriptorType        16
    bDevCapabilityType      3
    bmAttributes         0x00
    wSpeedsSupported   0x000f
      Device can operate at Low Speed (1Mbps)
      Device can operate at Full Speed (12Mbps)
      Device can operate at High Speed (480Mbps)
      Device can operate at SuperSpeed (5Gbps)
    bFunctionalitySupport   1
      Lowest fully-functional device speed is Full Speed (12Mbps)
    bU1DevExitLat           1 micro seconds
    bU2DevExitLat         500 micro seconds
Device Status:     0x0000
  (Bus Powered)

我的测试代码:
#include 
#include 
#include "libusb.h"

int main(int argc, char *argv[])
{
    if (argc != 5) {  // 列如 ./a.out 0x2207 0x0011 0x01 0x81
        printf("参数不对!\n");
        return -1;
    }

    // init
    int nRet = libusb_init(NULL);
    if (nRet < 0)
    {
        printf("libusb_init(NULL) failed:[%s] \n", libusb_strerror(nRet));
        return -1;
    }
    printf("libusb_init(NULL) ok \n");

    // open device
    libusb_device_handle* pHandle = libusb_open_device_with_vid_pid(NULL, strtol(argv[1], NULL, 16), strtol(argv[2], NULL, 16));
    if (pHandle == NULL)
    {
        printf("libusb_open_device_with_vid_pid(%s, %s) failed \n", argv[1], argv[2]);
        libusb_exit(NULL);
        return -1;
    }
    printf("libusb_open_device_with_vid_pid(%s, %s) ok \n", argv[1], argv[2]);

  if (libusb_kernel_driver_active(pHandle, 0) == 1)   
  {
    printf("USB Kernel Driver Active \n");
    if (libusb_kernel_driver_active(pHandle, 0) == 0)
    {
      printf("Kernel Driver Detached \n");
    }
  }
  libusb_detach_kernel_driver(pHandle, 0);    

    // declare interface
    nRet = libusb_claim_interface(pHandle, 0);
    if (nRet < 0)
    {
        printf("libusb_claim_interface(0) failed:[%s] \n", libusb_strerror(nRet));
        libusb_close(pHandle);
        libusb_exit(NULL);
        return -1;
    }
    printf("libusb_claim_interface(0) ok \n");

    // write data
    char sBuf[] = "0123456789";
    int nActualBytes = 0;
    libusb_clear_halt(pHandle, strtol(argv[3], NULL, 16));
    nRet = libusb_bulk_transfer(pHandle, strtol(argv[3], NULL, 16), sBuf, sizeof(sBuf), &nActualBytes, 500);
    if (nRet < 0)
    {
        printf("libusb_bulk_transfer(%s) write failed:[%s] \n", argv[3], libusb_strerror(nRet));
        libusb_release_interface(pHandle, 0);
        libusb_close(pHandle);
        libusb_exit(NULL);
        return -1;
    }
    printf("libusb_bulk_transfer(%s) write size:[%d] \n", argv[3], nActualBytes);

    // read data
    char sBuf2[64] = {0};
    nActualBytes = 0;
    libusb_clear_halt(pHandle, strtol(argv[4], NULL, 16));
    nRet = libusb_bulk_transfer(pHandle, strtol(argv[4], NULL, 16), sBuf2, sizeof(sBuf2), &nActualBytes, 500);
    if (nRet < 0)
    {
        printf("libusb_bulk_transfer(%s) read failed:[%s] \n", argv[4], libusb_strerror(nRet));
        libusb_release_interface(pHandle, 0);
        libusb_close(pHandle);
        libusb_exit(NULL);
        return -1;
    }
    printf("libusb_bulk_transfer(%s) read size:[%d] \n", argv[4], nActualBytes);

    // release interface
    libusb_release_interface(pHandle, 0);

    // close device
    libusb_close(pHandle);

    // release 
    libusb_exit(NULL);

    return 0; 
}
这是程序运行的打印:
[root@RK356X:/userdata]# ./a.out 0x2207 0x0011 0x01 0x81
libusb_init(NULL) ok
libusb_open_device_with_vid_pid(0x2207, 0x0011) ok
libusb_claim_interface(0) ok
libusb_bulk_transfer(0x01) write size:[10]
libusb_bulk_transfer(0x81) read failed:[Operation timed out]

你这个USB的VID PID是瑞芯微的吧 你读的话要RK那边给你发数据才能读到啊 RK那边发数据了吗 你可以用Bus Hound监控一下

你需要在对端做一个数据处理和应答程序

接收数据时,函数libusb_bulk_transfer最后一个参数,超时时间设为0呢?

你看看这个博文的思路,是否帮助到你【libusb:libusb_bulk_transfer的timeout参数问题】:https://blog.csdn.net/u012247418/article/details/86252528

这篇文章 写了 对 libusb bulk transfers通信超时得可能存在得问题
https://www.codenong.com/46181087/
可以看看,有问题在一起探讨