You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu下SICK激光雷达USB通信LIBUSB_ERROR_TIMEOUT问题求助

问题:Ubuntu下SICK激光雷达USB通信接收超时(LIBUSB_ERROR_TIMEOUT)

在Ubuntu 22.04.3 LTS系统上通过USB与SICK激光雷达(ID 19a2:2001)通信,已成功打开并占用端口,能正常发送数据,但接收数据时持续出现LIBUSB_ERROR_TIMEOUT错误。已尝试更换端点、调整超时时间(1-6秒)及传输大小(8-2048字节),均未解决问题。

代码片段

int8_t endpointAddress = 0x85;
int maxPacketSize = libusb_get_max_packet_size(libusb_get_device(handle), endpointAddress);

std::vector<unsigned char> buffer(maxPacketSize);

int transferred;
int result = libusb_bulk_transfer(handle, endpointAddress, buffer.data(), sizeof(buffer), &transferred, 1000);

if (result == 0) {
    std::cout << "Received " << transferred << " bytes of data:" << std::endl;
    for (int i = 0; i < transferred; ++i) {
        std::cout << std::hex << static_cast<int>(buffer[i]) << " ";
    }
    std::cout << std::dec << std::endl;
} else {
    std::cerr << "Failed to receive data. libusb_bulk_transfer error: " << libusb_error_name(result) << std::endl;
}

Libusb调试日志

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

USB设备信息

Bus 001 Device 004: ID 19a2:2001 SICK AG SICK Safety Device
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.00
  bDeviceClass          255 Vendor Specific Class
  bDeviceSubClass         0 
  bDeviceProtocol       255 
  bMaxPacketSize0        64
  idVendor           0x19a2 
  idProduct          0x2001 
  bcdDevice            0.00
  iManufacturer           1 SICK AG
  iProduct                2 SICK Safety Device
  iSerial                 4 109445223214336
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength       0x0020
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          0 
    bmAttributes         0xc0
      Self Powered
    MaxPower              100mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           2
      bInterfaceClass       255 Vendor Specific Class
      bInterfaceSubClass      0 
      bInterfaceProtocol      0 
      iInterface              3 SOPAS
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x85  EP 5 IN
        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     0x05  EP 5 OUT
        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               2.00
  bDeviceClass          255 Vendor Specific Class
  bDeviceSubClass         0 
  bDeviceProtocol       255 
  bMaxPacketSize0        64
  bNumConfigurations      1
Device Status:     0x0001
  Self Powered

排查思路

  • 确认传感器是否处于主动发送数据状态:部分SICK传感器需要先发送特定SOPAS协议指令(如启动扫描、请求数据帧)才会返回数据,检查发送的指令是否正确触发输出
  • 核对端点配置:设备IN端点为0x85,确认接收逻辑未误用OUT端点;日志显示已成功claim接口0,这部分无需调整
  • 遵循SOPAS协议规范:该传感器使用SICK私有协议,需确保发送的请求帧包含正确的帧头、校验位,部分设备需先建立会话或配置参数才会回传数据
  • 测试异步传输:替换同步libusb_bulk_transfer为异步传输接口(libusb_alloc_transfer+libusb_submit_transfer),避免同步超时逻辑的限制
  • 排查硬件稳定性:更换USB2.0端口、优质USB线缆,排除连接干扰;确认传感器供电正常(设备为自供电,无需USB供电)
  • 验证设备可用性:使用SICK官方SOPAS ET软件连接传感器,确认设备能正常输出数据,排除硬件故障
  • 检查权限:用sudo临时运行程序测试,或配置udev规则为当前用户授予USB设备读写权限

内容的提问来源于stack exchange,提问作者Pete

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.04 22:25:54