Click here to Skip to main content
15,880,608 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a question

I declared a USB HID DEVICE, HID report as follows:

Usage Page (Vendor-Defined 1) 06 00 FF
Usage (Vendor-Defined 2) 09 02
Collection (Application) A1 01
Logical Minimum (0) 15 00
Logical Maximum (255) 26 FF 00
Report Size (8) 75 08
Report ID (1) 85 01
Report Count (7) 95 07
Usage (Vendor-Defined 2) 09 02
Input (Data,Var,Abs,NWrp,Lin,Pref,NNul,Bit) 81 02
Usage (Vendor-Defined 2) 09 02
Output (Data,Var,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) 91 02
Report ID (2) 85 02
Report Count (63) 95 3F
Usage (Vendor-Defined 2) 09 02
Input (Data,Var,Abs,NWrp,Lin,Pref,NNul,Bit) 81 02
Usage (Vendor-Defined 2) 09 02
Output (Data,Var,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) 91 02
End Collection C0
USB HID device success send 8 bytes data to pc. (01 35 00 00 00 00 00 00)

HidP_GetCaps(pPreData, &cap) get cap.InputReportByteLength = 64
Part of the source code:

C++
{
memset(ReadReportBuffer, 0, sizeof(ReadReportBuffer));
ReadFile(m_hReadHandle,
ReadReportBuffer,
64, 
NULL,
&ReadOverlapped);
}
dObject = WaitForMultipleObjects(2, hArray, FALSE, INFINITE);
if (dObject == WAIT_OBJECT_0)
{
if (!MyDevFound)//Device extract also set the event 
{
continue;
}
GetOverlappedResult(m_hReadHandle,
&ReadOverlapped,
&nBytesRead,
TRUE);//you can also set the last parameter False
if (nBytesRead != 0)
{
m_strTemp = ReadReportBuffer;
m_strLog.Format(_T("Read the Report Data Length is %d.(%02d:%02d:%02d)"),
nBytesRead, sysTime.wHour, sysTime.wMinute, sysTime.wSecond);
m_strLog += m_strTemp;
Display_Info::SendEvent(m_strLog);
//Display Receive Data
pDlg->DisplayDataHex(ReadReportBuffer, nBytesRead);
}

why nBytesRead value = 64?
Posted
Updated 19-Mar-15 23:21pm
v2

1 solution

Why shouldn't it? You asked for 64 bytes and it read 64 bytes...
 
Share this answer
 
Comments
Member 11540842 23-Mar-15 6:10am    
How do I get the actual length of the USB transmission?
den2k88 23-Mar-15 6:16am    
My idea would be to loop asking 64 (or n) bytes and storing inside a buffer until either ReadFile returns FALSE or it reads less bytes than asked.

When you have to read an unknown amount of data it is the simplest way, and in many cases the only one.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900