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

如何从HID设备数据首字节读取Report ID?及VNC2获取正确ID的问题

问题:获取条码阅读器正确的Report ID(0x03)

使用FTDI VNC2芯片作为USB主机,连接两台条码阅读器:

  • 一台返回8字节扫描数据
  • 另一台返回9字节数据,经Wireshark抓包确认,多出来的首字节为Report ID 0x03

但通过VNC2发送GET_DESCRIPTOR请求获取报告描述符时,得到的信息与实际不符:

  • (desc_dev.wValue >> 8) & 0xff = 0x5F
  • desc_dev.wValue & 0xff = 0x73

修改自VNC2示例的GET_DESCRIPTOR请求代码

// host controller device descriptor
usb_deviceRequest_t desc_dev;

// user ioctl to find control endpoint on this device  
hc_iocb.ioctl_code = VOS_IOCTL_USBHOST_DEVICE_GET_CONTROL_ENDPOINT_HANDLE;
hc_iocb.handle.dif = ifDev;
hc_iocb.get = &epCtrl;

status = vos_dev_ioctl(hUSBHOST_1, &hc_iocb);

if (status != USBHOST_OK) {
    break;
}

desc_dev.bmRequestType = USB_BMREQUESTTYPE_HOST_TO_DEV | USB_BMREQUESTTYPE_CLASS | USB_BMREQUESTTYPE_DEVICE;
desc_dev.bRequest = 0x06; // 0x06 means GET_DESCRIPTOR            

hc_iocb.ioctl_code = VOS_IOCTL_USBHOST_DEVICE_SETUP_TRANSFER;
hc_iocb.handle.ep = epCtrl;
hc_iocb.set = &desc_dev;

status = vos_dev_ioctl(hUSBHOST_1, &hc_iocb);            

if (status != USBHOST_OK) {
    break;
}

hid_reportid_2 = desc_dev.wValue & 0xff;
hid_reportid_3 = (desc_dev.wValue >> 8) & 0xff;

修改自VNC2 HID设备示例的报告描述符获取代码

hid_iocb.descriptorType = USB_DESCRIPTOR_TYPE_REPORT;
hid_iocb.descriptorIndex = USB_HID_DESCRIPTOR_INDEX_ZERO;
hid_iocb.Length = 0x40;
hid_iocb.get.data = &transfer_buf[0]; 
hid_iocb.ioctl_code = VOS_IOCTL_USBHOSTHID_GET_DESCRIPTOR;            

status = vos_dev_ioctl(hUSBHOST_HID, &hid_iocb);            

if (status != USBHOSTHID_OK)
{
    break;
}

hid_protocoltype = hid_iocb.protocolType;
hid_reporttype = hid_iocb.reportType;
hid_reportid = hid_iocb.reportID;

运行代码后得到以下值:

  • hid_protocoltype = 0x6F
  • hid_reporttype = 0x73
  • hid_reportid = 0x5F
  • hid_reportid_2 = 0x00
  • hid_reportid_3 = 0x00

请问如何获取正确的Report ID(即0x03)?望各位提供建议,非常感谢!

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.02 23:03:06