Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C USB从设备获取数据_C_Usb_Libusb - Fatal编程技术网

C USB从设备获取数据

C USB从设备获取数据,c,usb,libusb,C,Usb,Libusb,我正在尝试从设备读取数据。我有一个USB嗅探器捕获,基本上可以: Get Device Descriptor Get Device Descriptor Set Address Get Configuration Descriptor Get Configuration Descriptor Set Configuration Set Idle Get Input Report Get Input Report Get Input Report Get Input Report Set Feat

我正在尝试从设备读取数据。我有一个USB嗅探器捕获,基本上可以:

Get Device Descriptor
Get Device Descriptor
Set Address
Get Configuration Descriptor
Get Configuration Descriptor
Set Configuration
Set Idle
Get Input Report
Get Input Report
Get Input Report
Get Input Report
Set Feature Report
Get Input Report
Set Feature Report
Get Input Report
Get Input Report
Set Output Report
Get Input Report
Set Feature Report
Input Report
Input Report
似乎设置了
输入报告
之前的所有内容,
输入报告
是从设备定期收集的数据

在这方面,我正在做以下工作:

usb_init();
usb_find_busses();
usb_find_devices();

loop through busses
    loop through devices
        if correct vendor and correct product
            handle = usb_open(device)
            break

usb_set_configuration(dev_handle, 1)

// Endpoint 0 is a 'write endpoint', endpoint 1 is a 'read endpoint'.
endpoint = &device->config[0].interface[0].altsetting[0].endpoint[1]
usb_claim_interface(dev_handle, 0)
usb_set_altinterface(dev_handle, 0)

usb_bulk_read(dev_handle, endpoint->bEndpointAddress, buffer, endpoint->wMaxPacketSize, 1);
我猜驱动程序和代码在
usb\u set\u配置
之前与嗅探器分析在
set配置
之前相对应

代码中的所有内容都会成功,直到
usb\u bulk\u read
失败

  • 如何
    设置空闲
    获取输入报告
    设置功能报告
    设置输出报告
  • 为什么
    usb\u bulk\u read
    会失败
  • 我还需要做什么来设置与设备的通信
  • HID设备[…] usb_批量_读取

    哎哟。USB批量读取仅在批量端点上使用,HID没有

    HID端点是中断端点,因此需要
    usb\u中断\u传输()
    。您确实查看了端点描述符,是吗?它应该将端点类型声明为中断。

    我是libusb新手,一般来说,因此我不确定这是否正确,但在查看了USB嗅探器的输出(例如)并调整了一些内容后,我提出了以下协议项:

    usb接口 当我申请一个接口(
    usb\u claim\u interface
    )并取消我的应用程序时,我在后续运行中处于不可操作状态。我尝试了各种重置(
    usb\u-reset
    usb\u-resetep
    ),但仍然无法正确使用
    usb\u-control\u-msg

    SetReport/GetReport
    USBlyzer
    显示相关数据包,其中
    获取描述符
    选择配置
    设置报告
    ,以及
    获取报告
    Get Descriptor
    Select Configuration
    分别与
    usb\u Get\u Descriptor
    usb\u set\u Configuration
    明确关联

    一些
    Get Report
    数据包包含
    featureid
    和其他
    Input Id
    。我能够用以下参数将这些参数与usb控制msg进行匹配(帮助 让我想想看):


    这可能不是实现所有这些的“正确”方式,我当然希望能够更深入地了解计算机的各种功能。但是这可以让我的主机从设备捕获所有相关数据。

    您使用哪个usb嗅探器来获取上述报告?一些hid设备也有控制端点(端点输入和端点输出),用于设置输出端口和获取输入端口。基本上用于配置部分-设置功能报告。
    requesttype = USB_ENDPOINT_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE
    value = 0x01 (for GetReport)
    index = id | (0x03 << 8) (for FeatureId)
    
    requesttype = USB_ENDPOINT_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE
    value = 0x09 (for SetReport)
    index = id | (0x03 << 8) (for FeatureId)