Reputation: 95
I implemented a HID USB PC application which seems to work fine for connecting, readin and writing to an external USB device. The problem is when attemping to read large data files, some packets get lost.
Here is the code im using:
DWORD result;
uint8_t u8_dataBuffer[size] = { 0 };
DWORD bytesRead;
ReadFile(Handle, u8_dataBuffer,
size + 1,
&bytesRead,
(LPOVERLAPPED)&m_HidOverlapped))
result = WaitForSingleObject(Handle, 6000);
switch (result) {
case WAIT_OBJECT_0: {
break;
}
case WAIT_TIMEOUT: {
result = CancelIo(Handle);
CloseHandle(Handle);
deviceFound = false;
break;
}
default: {
break;
}
}
Upvotes: 0
Views: 447
Reputation: 1431
HID reports are saved in a ring buffer. So if you don't fast enough to read all pending input reports - they could be lost. Size of this buffer could be changed via HidD_SetNumInputBuffers call or IOCTL_SET_NUM_DEVICE_INPUT_BUFFERS IOCTL on HID device handle.
By default, the HID class driver maintains an input report ring buffer that holds 32 reports.
See Troubleshooting HID Reports#Dropped HID Reports for additional info.
Upvotes: 1