【问题标题】:LibUSB driver issues: timeoutLibUSB 驱动程序问题:超时
【发布时间】:2014-11-26 01:30:35
【问题描述】:

我正在尝试为打印机编写 linux 驱动程序。我在 windows XP 上运行了 USBSnoop 并获得了日志。在此日志中,它将 wMaxPacketSize 设置为 1026。设置接口后,我得到 75 个字节的响应。如果我将它设置为 64(在 lsusb 输出中),我显然只能得到 64 个字节。

我的问题是批量传输到/从设备我得到超时。我想我和这里有同样的问题:http://libusb.6.n5.nabble.com/libusb-bulk-transfer-return-timeout-error-and-transferred-set-to-0-td5712761.html

我执行了 libusb_clear_halt(),得到了与上面链接的帖子类似的结果。在它的底部说“手动将缓冲区拆分为 64 个字节”来解决它。我的问题是如何拆分数据包?这是我第一次使用 LibUSB。

这是 lsusb -v 的输出

Bus 002 Device 009: ID 07ce:c000  
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.00
  bDeviceClass            7 Printer
  bDeviceSubClass         1 Printer
  bDeviceProtocol         2 Bidirectional
  bMaxPacketSize0        64
  idVendor           0x07ce 
  idProduct          0xc000 
  bcdDevice            1.00
  iManufacturer           1 COPAL
  iProduct                2 COPAL USB Printer
  iSerial                 0 
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength           32
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          0 
    bmAttributes         0xc0
      Self Powered
    MaxPower              200mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           2
      bInterfaceClass         7 Printer
      bInterfaceSubClass      1 Printer
      bInterfaceProtocol      2 Bidirectional
      iInterface              0 
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x01  EP 1 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x82  EP 2 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               0
Device Qualifier (for other device speed):
  bLength                10
  bDescriptorType         6
  bcdUSB               0.00
  bDeviceClass            0 (Defined at Interface level)
  bDeviceSubClass         0 
  bDeviceProtocol         0 
  bMaxPacketSize0         0
  bNumConfigurations      0
Device Status:     0x0001
  Self Powered

编辑:这是在 dmesg 中

usb 2-1.1: new high-speed USB device number 9 using ehci_hcd
usb 2-1.1: config 1 interface 0 altsetting 0 bulk endpoint 0x1 has invalid maxpacket 64
usb 2-1.1: config 1 interface 0 altsetting 0 bulk endpoint 0x82 has invalid maxpacket 64

编辑:我认为可能是 linux 正在阻碍。在wireshark上,我可以看到数据包正确返回,但没有调用我的回调函数。我已经删除了 usblp 驱动程序。有任何想法吗?

【问题讨论】:

  • 你有没有找到这个问题的根源——我遇到了类似的问题..
  • 不抱歉:/ 分心并开始做其他事情

标签: c driver linux-device-driver libusb


【解决方案1】:

遇到了类似的问题。还没有弄清楚为什么我会收到超时错误。尽管对于较大的包装尺寸,它们似乎更频繁地出现。如果您想拆分您的包,只需编写一个函数,将您的大 buffer[1024] 拆分为 64 字节的包,然后执行一个循环,始终从缓冲区中获取下一个 64 字节,将其放入 small_buffer[64] 并发送他们通过usb。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-02
    • 2012-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-11
    相关资源
    最近更新 更多