c - LibUSB 驱动程序问题 : timeout

标签 c driver linux-device-driver libusb

我正在尝试为打印机编写 linux 驱动程序。我已经在 Windows XP 上运行 USBSnoop 并获得了日志。在此日志中,它将 wMaxPacketSize 设置为 1026。设置接口(interface)后,我得到 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 驱动程序。有任何想法吗?

最佳答案

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

关于c - LibUSB 驱动程序问题 : timeout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27139854/

相关文章:

c - 如何对链表指针进行排序

html - HTML 处理时出错

driver - 设备驱动程序与驱动程序堆栈

通过 sysfs 访问 Linux 驱动程序

c - 结构体定义末尾的变量名是什么意思?

c - 快速选择立方体贴图正确面的方法?

c - 如何以编程方式更改 Windows 音频设备的友好名称?

windows - 如何使用 NDIS 过滤器驱动程序发送任意数据包?

linux-kernel - 绕过 I/O 调度和 linux 内核页面缓冲

c++ - 在 Fedora 20 中查找简单设备驱动程序的头文件