ubuntu 尝试通过libusb_bulk_transfer接收时,LIBUSB_ERROR_TIMEOUT

hi3rlvi2  于 2024-01-06  发布在  其他
关注(0)|答案(1)|浏览(311)

嘿,我正在尝试通过Ubuntu 22.04.3 LTS上的USB与生病的激光雷达传感器进行通信。目前我可以打开并声明端口并发送数据。但是如果我尝试接收数据,我会收到LIBUSB_ERROR_TIMEOUT。我尝试了不同的端点,超时时间(1-6s)和传输大小(8-2048)没有成功。你可能知道为什么它不工作吗?Thank you:)
我的代码:

  1. int8_t endpointAddress = 0x85;
  2. int maxPacketSize = libusb_get_max_packet_size(libusb_get_device(handle), endpointAddress);
  3. std::vector<unsigned char> buffer(maxPacketSize);
  4. int transferred;
  5. int result = libusb_bulk_transfer(handle, endpointAddress, buffer.data(), sizeof(buffer), &transferred, 1000);
  6. if (result == 0) {
  7. std::cout << "Received " << transferred << " bytes of data:" << std::endl;
  8. for (int i = 0; i < transferred; ++i) {
  9. std::cout << std::hex << static_cast<int>(buffer[i]) << " ";
  10. }
  11. std::cout << std::dec << std::endl;
  12. } else {
  13. std::cerr << "Failed to receive data. libusb_bulk_transfer error: " << libusb_error_name(result) << std::endl;
  14. }

字符串
Libusb日志:

  1. [ 0.001609] [00005ec1] libusb: debug [libusb_get_device_list]
  2. [ 0.001624] [00005ec1] libusb: debug [libusb_get_device_list]
  3. [ 0.001627] [00005ec1] libusb: debug [libusb_get_device_descriptor]
  4. [ 0.001628] [00005ec1] libusb: debug [libusb_get_device_descriptor]
  5. [ 0.001629] [00005ec1] libusb: debug [libusb_get_device_descriptor]
  6. [ 0.001629] [00005ec1] libusb: debug [libusb_get_device_descriptor]
  7. [ 0.001631] [00005ec1] libusb: debug [libusb_open] open 1.4
  8. [ 0.001642] [00005ec1] libusb: debug [usbi_add_event_source] add fd 26 events 4
  9. [ 0.001644] [00005ec1] libusb: debug [libusb_detach_kernel_driver] interface 0
  10. [ 0.001648] [00005ec1] libusb: debug [libusb_claim_interface] interface 0
  11. [ 0.001745] [00005ec1] libusb: debug [libusb_get_device_list]
  12. [ 0.001810] [00005ec1] libusb: debug [libusb_submit_transfer] transfer 0x5555559f19b0
  13. [ 0.001812] [00005ec1] libusb: debug [add_to_flying_list] arm timer for timeout in 1000ms (first in line)
  14. [ 0.001816] [00005ec1] libusb: debug [submit_bulk_transfer] need 1 urbs for new transfer with length 20
  15. [ 0.001834] [00005ec1] libusb: debug [libusb_handle_events_timeout_completed] doing our own event handling
  16. [ 0.001835] [00005ec1] libusb: debug [handle_events] event sources modified, reallocating event data
  17. [ 0.001838] [00005ec1] libusb: debug [usbi_wait_for_events] poll() 3 fds with timeout in 60000ms
  18. [ 1.001824] [00005ec1] libusb: debug [usbi_wait_for_events] poll() returned 1
  19. [ 1.001838] [00005ec1] libusb: debug [libusb_cancel_transfer] transfer 0x5555559f19b0
  20. [ 1.001993] [00005ec1] libusb: debug [arm_timer_for_next_timeout] no timeouts, disarming timer
  21. [ 1.002003] [00005ec1] libusb: debug [libusb_handle_events_timeout_completed] doing our own event handling
  22. [ 1.002005] [00005ec1] libusb: debug [usbi_wait_for_events] poll() 3 fds with timeout in 60000ms
  23. [ 1.002007] [00005ec1] libusb: debug [usbi_wait_for_events] poll() returned 1
  24. [ 1.002009] [00005ec1] libusb: debug [reap_for_handle] urb type=3 status=-2 transferred=0
  25. [ 1.002010] [00005ec1] libusb: debug [handle_bulk_completion] handling completion status -2 of bulk urb 1/1
  26. [ 1.002011] [00005ec1] libusb: debug [handle_bulk_completion] abnormal reap: urb status -2
  27. [ 1.002012] [00005ec1] libusb: debug [handle_bulk_completion] abnormal reap: last URB handled, reporting
  28. [ 1.002014] [00005ec1] libusb: debug [usbi_handle_transfer_cancellation] detected timeout cancellation
  29. [ 1.002015] [00005ec1] libusb: debug [arm_timer_for_next_timeout] no timeouts, disarming timer
  30. [ 1.002016] [00005ec1] libusb: debug [usbi_handle_transfer_completion] transfer 0x5555559f19b0 has callback 0x7ffff79f1100
  31. [ 1.002017] [00005ec1] libusb: debug [sync_transfer_cb] actual_length=0
  32. [ 1.002019] [00005ec1] libusb: debug [libusb_free_transfer] transfer 0x5555559f19b0
  33. Failed to send data. libusb_bulk_transfer error: LIBUSB_ERROR_TIMEOUT


USB设备信息:

  1. Bus 001 Device 004: ID 19a2:2001 SICK AG SICK Safety Device
  2. Device Descriptor:
  3. bLength 18
  4. bDescriptorType 1
  5. bcdUSB 2.00
  6. bDeviceClass 255 Vendor Specific Class
  7. bDeviceSubClass 0
  8. bDeviceProtocol 255
  9. bMaxPacketSize0 64
  10. idVendor 0x19a2
  11. idProduct 0x2001
  12. bcdDevice 0.00
  13. iManufacturer 1 SICK AG
  14. iProduct 2 SICK Safety Device
  15. iSerial 4 109445223214336
  16. bNumConfigurations 1
  17. Configuration Descriptor:
  18. bLength 9
  19. bDescriptorType 2
  20. wTotalLength 0x0020
  21. bNumInterfaces 1
  22. bConfigurationValue 1
  23. iConfiguration 0
  24. bmAttributes 0xc0
  25. Self Powered
  26. MaxPower 100mA
  27. Interface Descriptor:
  28. bLength 9
  29. bDescriptorType 4
  30. bInterfaceNumber 0
  31. bAlternateSetting 0
  32. bNumEndpoints 2
  33. bInterfaceClass 255 Vendor Specific Class
  34. bInterfaceSubClass 0
  35. bInterfaceProtocol 0
  36. iInterface 3 SOPAS
  37. Endpoint Descriptor:
  38. bLength 7
  39. bDescriptorType 5
  40. bEndpointAddress 0x85 EP 5 IN
  41. bmAttributes 2
  42. Transfer Type Bulk
  43. Synch Type None
  44. Usage Type Data
  45. wMaxPacketSize 0x0040 1x 64 bytes
  46. bInterval 0
  47. Endpoint Descriptor:
  48. bLength 7
  49. bDescriptorType 5
  50. bEndpointAddress 0x05 EP 5 OUT
  51. bmAttributes 2
  52. Transfer Type Bulk
  53. Synch Type None
  54. Usage Type Data
  55. wMaxPacketSize 0x0040 1x 64 bytes
  56. bInterval 0
  57. Device Qualifier (for other device speed):
  58. bLength 10
  59. bDescriptorType 6
  60. bcdUSB 2.00
  61. bDeviceClass 255 Vendor Specific Class
  62. bDeviceSubClass 0
  63. bDeviceProtocol 255
  64. bMaxPacketSize0 64
  65. bNumConfigurations 1
  66. Device Status: 0x0001
  67. Self Powered


尝试改变端点、超时时间和传输大小,但都没有改变错误。

hfsqlsce

hfsqlsce1#

我找到了解决方案,代码没有任何问题,我需要在给传感器通电之前连接USB。现在我可以毫无问题地发送和接收传感器的数据。

相关问题