How to use ReadFile API Read HID Device synchronous
-
Dear all: I use ReadFile api to read HID device synchronous. My code show as below:
char preUsedSize = 0;
char curUsedSize = 0;while(1)
{
opening_HANDLE = TestHid.ReturnHandle();
BOOL bGot = FALSE;
Data64_t aData64;
DWORD dwBytes = 0;BOOL bSus = ::ReadFile(opening\_HANDLE, aData64.raw, sizeof(aData64), &dwBytes, NULL); if( bSus ) { PTOUCH\_REPORT inputData = (PTOUCH\_REPORT)aData64.raw; curUsedSize = inputData->actualCnt; if(curUsedSize > preUsedSize) { for(int i = 0; i<(curUsedSize - preUsedSize);i++) { Beep(0x7fff, 500); } } preUsedSize = curUsedSize; bGot = TRUE; } else { CloseHandle(opening\_HANDLE); } if(!bGot) { Sleep(500); }
}
My question is how do I clean preUsedSize and curUsedSize to 0, If I did not get any data from my device(not get data failed)? The FALSE of bSus means I get data from HID device fail, not no data income. Thanks for your help, Victor.
-
Dear all: I use ReadFile api to read HID device synchronous. My code show as below:
char preUsedSize = 0;
char curUsedSize = 0;while(1)
{
opening_HANDLE = TestHid.ReturnHandle();
BOOL bGot = FALSE;
Data64_t aData64;
DWORD dwBytes = 0;BOOL bSus = ::ReadFile(opening\_HANDLE, aData64.raw, sizeof(aData64), &dwBytes, NULL); if( bSus ) { PTOUCH\_REPORT inputData = (PTOUCH\_REPORT)aData64.raw; curUsedSize = inputData->actualCnt; if(curUsedSize > preUsedSize) { for(int i = 0; i<(curUsedSize - preUsedSize);i++) { Beep(0x7fff, 500); } } preUsedSize = curUsedSize; bGot = TRUE; } else { CloseHandle(opening\_HANDLE); } if(!bGot) { Sleep(500); }
}
My question is how do I clean preUsedSize and curUsedSize to 0, If I did not get any data from my device(not get data failed)? The FALSE of bSus means I get data from HID device fail, not no data income. Thanks for your help, Victor.
Your question is not clear. It looks like you are asking how to set the variables
preUsedSize
andcurUsedSize
to zero. To that, the answer is:preUsedSize = 0;
curUsedSize = 0;The difficult we do right away... ...the impossible takes slightly longer.
-
Dear all: I use ReadFile api to read HID device synchronous. My code show as below:
char preUsedSize = 0;
char curUsedSize = 0;while(1)
{
opening_HANDLE = TestHid.ReturnHandle();
BOOL bGot = FALSE;
Data64_t aData64;
DWORD dwBytes = 0;BOOL bSus = ::ReadFile(opening\_HANDLE, aData64.raw, sizeof(aData64), &dwBytes, NULL); if( bSus ) { PTOUCH\_REPORT inputData = (PTOUCH\_REPORT)aData64.raw; curUsedSize = inputData->actualCnt; if(curUsedSize > preUsedSize) { for(int i = 0; i<(curUsedSize - preUsedSize);i++) { Beep(0x7fff, 500); } } preUsedSize = curUsedSize; bGot = TRUE; } else { CloseHandle(opening\_HANDLE); } if(!bGot) { Sleep(500); }
}
My question is how do I clean preUsedSize and curUsedSize to 0, If I did not get any data from my device(not get data failed)? The FALSE of bSus means I get data from HID device fail, not no data income. Thanks for your help, Victor.
I can't understand your question well. Firstly, you read the file synchronous, so if no fails happens, it will be blocked here if no data income. I think so, happy to communicate with you !