This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Reading from a Vendor Defined HID device

Hi,

I have a vendor defined hid device with Usage Page: 0xFF00 and Usage: 0x01. I can read it through CreateFile, ReadFile function on Windows XP. However, the data rate (500 msec after 2 packets received) is far lower than the MCU transmission rate (15-byte/packet in 5ms).

Could anyone give me a hint on this situation? Thanks a lot !!!!

Danny

  • Thanks for the reply

    The HID device is sending out packet every 5 ms. It is proved by USBlyze. Although PC receive with low data rate, NO missing packet is found. I can read those packet with continuous frame number. Therefore i think that the hardware would be ok.

    Then I looked into PC side, i found that it took 500 ms to run "ReadFile" function. I have no idea why it happens. Could you give me some hints? Also, how do i know if the hardware support "HidD_GetInputreport" function?

    Thanks

    Danny

  • The sniffer catches low-level USB traffic, before the PC HID driver examines the packets.

    a) PC HID driver drops the packets, because the packet format doesn't match to those on the report descriptor.

    OR

    b) Your PC application doesn't read the packets quick enough.

    1) Post the report descriptor
    2) Post the PC application code, around CreateFile() and ReadFile()



    > how do i know if the hardware support "HidD_GetInputreport" function?

    HidD_GetInputreport() reads packet over the default endpoint, by Get_Report request.
    It can't read from the interrupt IN endpoint.

    Tsuneo

  • Here is the report descriptor

    Usage Page: 06 00 FF
    Usage: 09 01
    Collection: A1 01 Report ID: 85 01 Usage: 09 00 Logical Min: 15 00 Logical Max: 26 FF 00 Report Size: 75 08 Report Count: 95 0D Input: 81 02 Usage: 09 00 Logical Min: 15 00 Logical Max: 26 FF 00 Report Size: 75 08 Report Count: 95 06 Output: 91 02
    End Collection C0

    The following codes are run in a thread
    Source code:
    hHandle = CreateFile(hDevice->DevicePath, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);

    while(1)
    { Result = ReadFile( hHandle, buffer, // unsigned char *buffer = new unsigned char[256] capLength, // read from "HidP_GetCaps" and it is 14 (0x0E) &NumberOfBytesRead, // always return 0 but the data received is correct NULL );

    if (Result) print out the received frame number WaitForSingleObject(hEventObject,50); ResetEvent(hEventObject);
    }

    Output:
    1 2
    (delay 500ms)
    3 4
    (delay 500ms)
    ...
    10
    11
    (delay 500ms)
    ...

  • 1) Report format
    Your report descriptor is

    Usage Page    : 06 00 FF
    Usage         : 09 01
    Collection    : A1 01
    
    Report ID     : 85 01
    
    Usage         : 09 00
    Logical Min   : 15 00
    Logical Max   : 26 FF 00
    Report Size   : 75 08
    Report Count  : 95 0D
    Input         : 81 02
    
    Usage         : 09 00
    Logical Min   : 15 00
    Logical Max   : 26 FF 00
    Report Size   : 75 08
    Report Count  : 95 06
    Output        : 91 02
    
    End Collection: C0
    


    This report descriptor defines single input and single output report.
    The format of each packet is,

    Input report
     byte offset
        0     report ID (1)
      1 - 13  report body (13 bytes)
    
    Output report
     byte offset
        0     report ID (1)
      1 - 6   report body (6 bytes)
    

    Your firmware has to send 14 bytes input report packet, starting with report ID(1).
    If the packet size wouldn't be 14 bytes, or if the packet wouldn't start with 1,
    PC HID driver drops such a packet.

    If you wouldn't have any plan to extend the report descriptor to exchange another size of input or output report, you may delete the Report ID definition from your report descriptor. And then, the report ID field is deleted from the input and report packets.

    2) PC code
    hHandle = CreateFile(hDevice->DevicePath, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);

    CreateFile opens the device synchronously (non-OVERLAPPED).
    It means, ReadFile doesn't return until it gets an input report.

    I'm not sure, what is WaitForSingleObject() waiting.
    If it would wait for ReadFile completion, it should be useless, because ReadFile returns just when it completes.

    Tsuneo

  • Thanks for the detailed explanation on the report descriptor!

    As you said the "ReadFile" will wait until the it get the input report. Yes, it is true. Those 500ms delay time is mostly on running "ReadFile" function. Does Bulk and Interrupt Transfer help this situation because I findthat USBlyze could read those data without 500ms delay. Or is there any tricky thing to deal with "ReadFile" function? Or It is the limitation set up by Windows?

    Thanks!

    Danny

  • Just delete WaitForSingleObject().
    Maybe, it makes the trouble.

    Tsuneo

  • Heh, then bus hound is not reliable.

    Tsuneo