The developer's resource for computer interfacing, especially USB, serial (COM) ports, mass storage, and embedded networking. (Formerly Lvr.com)

Home > USB Central > HID Page > HID FAQ

HID FAQ

Questions relating to designing and programming USB devices in the human interface class.

Also see:

HID Page

Sending and Receiving Reports under Windows

How can an application request a report using a control transfer?

HidD_GetFeature requests a Feature report using a control transfer with a Get_Report request. Beginning with Windows XP, you can use HidD_GetInputReport to request an Input report with a control transfer and a Get_Report request.

How can an application send a report using a control transfer?

Under Windows 98 Gold (original version), WriteFile sends Output reports using control transfers with Set_Report requests. Under later Windows editions, WriteFile uses control transfers if the HID interface doesn't have an interrupt OUT endpoint. Otherwise, WriteFile uses interrupt transfers for Output reports. Beginning with Windows XP, you can use HidD_SetOutputReport to send an Output report with a control transfer and a Set_Report request. Under all Windows editions, HidD_SetFeature sends a Feature report using a control transfer with a Set_Report request.

How can an application request reports using interrupt transfers?

Use ReadFile or ReadFileEx. The first byte in the buffer is the Report ID

How can an application send reports using an interrupt transfers?

Use WriteFile or WriteFileEx. The Windows edition must be later than Windows 98 Gold (original version), the device's USB version and HID interface must be version 1.1 or later, and the HID interface must have an interrupt OUT endpoint. The first byte in the buffer is the Report ID.

How large is the ReadFile buffer?

Under Windows 98 Gold, 2 reports. Under Windows 98 SE, Windows 2000 and Windows Me, the default is 8 reports. Under Windows XP, the default is 32 reports. Under all but Windows 98 Gold, you can change the defaults with HidD_SetNumInputBuffers. The maximum size under Windows XP and later is 512. The maximum size under Windows 2000 is 200. Use HidD_GetNumInputBuffers to read the buffer size.

Where is the Windows documentation for accessing HIDs?

MSDN HID documentation.

Do I need the WDK to create applications that access HIDs?

C programmers will need the files hid.h and hidsdi.h from the WDK. My example applications for .NET include declarations for many of the HID API functions and don't require additional header files.

Does every HID require an interrupt IN endpoint and an Input report?

The HID specification says that every HID must have an interrupt IN endpoint, which suggests that the HID should have an Input report.

Why do I receive "Access denied" when attempting to access my HID?

Windows 2000 and later have exclusive read/write access to HIDs that are configured as a system keyboards or mice. An application can obtain a handle to a system keyboard or mouse by not requesting READ or WRITE access with CreateFile. Applications can then use HidD_SetFeature and HidD_GetFeature (if the device supports Feature reports).

How can applications receive Input reports from a system mouse or keyboard?

The Windows raw input API enables applications to read Input reports when communicating with system mice and keyboards.

On a system with multiple keyboards, mice, or joysticks how can my application determine which device is sending data?

Use raw input (see previous question).

Partner Links

Debugging

How can I transfer data faster?

On the interrupt endpoint(s), set bInterval to the minimum allowed value: 10 for low speed and 1 for full or high speed. Each call to ReadFile or WriteFile adds overhead, so send the data in fewer, longer reports and/or increase the ReadFile buffer size to enable reading multiple reports at once. (ReadFile returns as many reports as are available, up to ReadFile's buffer size.)

How can I keep my application from losing reports?

If the ReadFile buffer is full, on receiving a new report, the driver drops the oldest report. To prevent losing reports, use HidD_SetNumInputBuffers to increase the buffer size, use longer reports sent less frequently, have the application read reports more often, or increase the size of the buffer in the call to ReadFile. (ReadFile returns as many reports as are available, up to ReadFile's buffer size.)

Why does ReadFile hang my application when I request to read a report?

ReadFile returns when one of more reports of the expected size are available or on a timeout if implemented.

How can I find out if a report is available without hanging my application?

Use overlapped ReadFile with a short timeout or use ReadFileEx to signal when a report is available. In .NET, you can do asynchronous ReadFile calls with a delegate and BeginInvoke and EndInvoke methods.

Why do I receive "CRC Error" when attempting to send a report to my device?

This error can be caused by any of a number of firmware errors that results in the host's not seeing a valid response after sending a report.

How do Windows and Mac OS X handle multiple applications accessing the same HID?

Every open handle to the HID has its own report queue. Every report a device sends goes into all of the queues so multiple applications can read the same report.