Question

I am a USB HID newbie and I am trying to use the HIDAPI for my application.

I have a question about using HIDAPI (in Visual Studio) regarding the report ID.

When I try to use the HIDAPI and connect to the Microchip Custom Demo, I am confused about this aspect: The 65-byte report does not make sense to me!

Even if I don't want to set a report ID, I need to set the first byte to 0 and send the 65-byte buffer to the device, but I only receive 64 bytes of data from the Microchip device (because the report is 64 bytes long).

It looks like:

    **Host**                       **Device**

         *write_hid*
      65 byte  --------------->

          *read_hid*
       <------------------   64byte

However, it seems weird to me.

Isn't the report that is sent or received always 64 bytes? Because the specifications say the report should have a 64-byte maximum and be sent every 1 ms.

If the answer is yes, why does the API maintain 65 bytes for 1-byte report ID?

Is the report ID contained in the 64 bytes?

The 65-byte data length does not make sense to me.

Was it helpful?

Solution

If your application does not include a Report ID in the HID descriptor, then there shouldn't be a Report ID prepended.

As you can see in the documentation of hid_write, HIDAPI should only send 64-bytes if the first byte is 0 (i.e. there is no Report ID):

unsigned char data[65];
buf[0] = 0; /* Single report */
// Fill report starting at buf[1]
hid_write(device, data, sizeof(data));

When looking at the source code for the libusb implementation, you can see that the Report ID is correctly stripped. On Windows however, the data is passed straight to Windows. I don't know Windows programming, but perhaps this makes a difference. Try testing this on Linux instead.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top