本文介绍了HID设备丢失报告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,
我的HID设备每200毫秒发送一次IN报告。我每10毫秒调用一次::执行。但是,我失去了20%的IN报告。输入缓冲区计数为512.
当我增加WaitForSingleObject的超时值时,报告丢失的次数减少了。但我希望WaitForSingleObject函数在零超时的情况下工作。
void THid :: Execute( void )
// 执行设备
{
THidReportExt ReportExt;
HANDLE活动;
OVERLAPPED Overlapped;
DWORD ReadBytes;
if (!Handle){
return ;
}
Event = CreateEvent(NULL,TRUE,FALSE,NULL);
Overlapped.hEvent = Event;
Overlapped.Offset = 0 ;
Overlapped.OffsetHigh = 0 ;
while ( true ){
if (!ReadFile(Handle,& ReportExt,Capabilities.InputReportByteLength,& ReadBytes,& Overlapped)){
if (GetLastError()!= ERROR_IO_PENDING){
return ;
}
DWORD结果= WaitForSingleObject(事件, 0 );
if (Result == WAIT_TIMEOUT || Result == WAIT_ABANDONED){
CancelIo(Handle);
return ;
}
如果(结果!= WAIT_OBJECT_0){
返回 ;
}
if (!GetOverlappedResult(Handle,& Overlapped,& ReadBytes,FALSE)){
返回跨度>;
}
}
if (ReadBytes!=(DWORD)Capabilities.InputReportByteLength){
返回跨度>;
}
// 调用一些回调
}
} // 执行
这是我打开文件的方式:
Handle = CreateFile(Path,
GENERIC_WRITE | GENERIC_READ,
FILE_SHARE_WRITE | FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,
NULL);
解决方案
Hello,
my HID device sends IN report every 200 msec. I call THid::Execute every 10 msec. However, I lose 20% of IN reports. Input buffer count is 512.
When I increase timeout value for WaitForSingleObject I lose less reports. But I want the WaitForSingleObject function to work with zero timeout.
void THid::Execute(void) // Execute device { THidReportExt ReportExt; HANDLE Event; OVERLAPPED Overlapped; DWORD ReadBytes; if(!Handle) { return; } Event = CreateEvent(NULL, TRUE, FALSE, NULL); Overlapped.hEvent = Event; Overlapped.Offset = 0; Overlapped.OffsetHigh = 0; while(true) { if(!ReadFile(Handle, &ReportExt, Capabilities.InputReportByteLength, &ReadBytes, &Overlapped)) { if(GetLastError() != ERROR_IO_PENDING) { return; } DWORD Result = WaitForSingleObject(Event, 0); if(Result == WAIT_TIMEOUT || Result == WAIT_ABANDONED) { CancelIo(Handle); return; } if(Result != WAIT_OBJECT_0) { return; } if(!GetOverlappedResult(Handle, &Overlapped, &ReadBytes, FALSE)) { return; } } if(ReadBytes != (DWORD)Capabilities.InputReportByteLength) { return; } // call some callback } } // Execute
This is how I open the file:
Handle = CreateFile(Path, GENERIC_WRITE | GENERIC_READ, FILE_SHARE_WRITE | FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, NULL);
解决方案
这篇关于HID设备丢失报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!