会进 2022-11-09 17:10 采纳率: 50%
浏览 150
已结题

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 <stdio.h>
#include <stdlib.h>
#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]

  • 写回答

5条回答 默认 最新

  • 伍六七0804 2022-11-09 17:17
    关注
    获得3.30元问题酬金

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

    评论 编辑记录

报告相同问题?

问题事件

  • 系统已结题 11月17日
  • 创建了问题 11月9日

悬赏问题

  • ¥15 两台交换机分别是trunk接口和access接口为何无法通信,通信过程是如何?
  • ¥15 C语言使用vscode编码错误
  • ¥15 用KSV5转成本时,如何不生成那笔中间凭证
  • ¥20 ensp怎么配置让PC1和PC2通讯上
  • ¥50 有没有适合匹配类似图中的运动规律的图像处理算法
  • ¥15 dnat基础问题,本机发出,别人返回的包,不能命中
  • ¥15 请各位帮我看看是哪里出了问题
  • ¥15 vs2019的js智能提示
  • ¥15 关于#开发语言#的问题:FDTD建模问题图中代码没有报错,但是模型却变透明了
  • ¥15 uniapp的h5项目写一个抽奖动画