阅读:4634回复:3
USB 驱动使用WriteFile传数据给设备,工作一段时间后出现"配额不足,无法完成请求的服务"
我这个设备有两个功能:1.获得USB 设备的按键信息{开启了一个线程,在里面不断的轮讯这个设备看数据是否有输入即ReadFile}
2.向USB 设备传输信息 我不知道为什么.在写数据的时候工作一段时间后.就出现1453"配额不足,无法完成请求的服务"这个错误, 请高手指教,问题的原因是什么,我该如何解决?? void WriteOutputReport(int out_type,int num,char address1,char byte1,char byte2,char byte3,char byte4,char byte5) { //HANDLE hDevice; unsigned long numBytesReturned; BOOL bResult; OVERLAPPED HidOverlapped; HANDLE ReportEvent; DWORD dwError; DWORD dwErrorFlags; char szError[10]; COMSTAT ComStat; Sleep(1); /* Create a new event for report capture */ ReportEvent = CreateEvent(NULL, TRUE, FALSE, NULL); /* fill the HidOverlapped structure so that Windows knows which event to cause when the device sends an IN report */ HidOverlapped.hEvent = ReportEvent; HidOverlapped.Offset = 0; HidOverlapped.OffsetHigh = 0; /* Use WriteFile to send an output report to the HID device. In this case we are turning on the READY LED on the target */ //outbuffer[3]=1; outbuffer[0]=out_type;//type outbuffer[1]=num;//num outbuffer[2]=address1; outbuffer[3]=byte1; outbuffer[4]=byte2; outbuffer[5]=byte3; outbuffer[6]=byte4; outbuffer[7]=byte5; bResult = WriteFile(w_handle,&outbuffer[0],w_length,&numBytesReturned,(LPOVERLAPPED) &HidOverlapped); /* if (!bResult) { if ((dwError=GetLastError()) == ERROR_IO_PENDING) { while (!GetOverlappedResult(w_handle, &HidOverlapped,&numBytesReturned,TRUE)) { dwError = GetLastError(); if(dwError == ERROR_IO_INCOMPLETE) { ::MessageBox(m_hWnd,"write io pending",0,0); continue; } else { //an error occurred, try to recover wsprintf(szError, "\n\r <CE-%u>",dwError) ; ::MessageBox(m_hWnd,szError,0,0); ClearCommError(w_handle,&dwErrorFlags,&ComStat) ; if (dwErrorFlags>0) { wsprintf(szError,"\n\r <CE-%u>",dwErrorFlags) ; ::MessageBox(m_hWnd,szError,0,0); } break; } } } else { // some other error occurred wsprintf(szError, "\n\r <CE-%u>",dwError); ::MessageBox(m_hWnd,szError,0,0); ClearCommError(w_handle,&dwErrorFlags,&ComStat); if (dwErrorFlags>0) { wsprintf( szError, "\n\r <CE-%u>", dwErrorFlags) ; //OutputDebugString(szError); ::MessageBox(m_hWnd,szError,0,0); } return; } } */ bResult = WaitForSingleObject(ReportEvent,30000); if(bResult == WAIT_TIMEOUT || bResult == WAIT_ABANDONED) { //::MessageBox(m_hWnd,"!!!!!!!!",0,0); CancelIo(&w_handle); } CloseHandle(ReportEvent); } void UsbDevice_DataInput(LPVOID lpParameter) { unsigned long numBytesReturned; DWORD dwError; DWORD dwErrorFlags; char szError[10]; COMSTAT ComStat; BOOL bResult; OVERLAPPED HidOverlapped; HANDLE ReportEvent; char b; DataInputThreadActive = TRUE; //bOpenHidDevice(&r_handle,VID,PID); /* Create a new event for report capture */ ReportEvent = CreateEvent(NULL, TRUE, FALSE, NULL); /* fill the HidOverlapped structure so that Windows knows which event to cause when the device sends an IN report */ HidOverlapped.hEvent = ReportEvent; HidOverlapped.Offset = 0; HidOverlapped.OffsetHigh = 0; while(endthread == FALSE) { Sleep(1); //ClearCommError(r_handle,&dwErrorFlags,&ComStat); /* get a temperature report from the HID device. Note that this call to ReadFile only kicks off the reading of the report. If the input buffer is full then this routine will cause an event to happen and data will be presented immediately. If not the event will occur when the HID decide provides a HID report on the IN endpoint. */ bResult = ReadFile(r_handle, /* handle to device */ &inbuffer[0], /* IN report buffer to fill */ r_length, /* input buffer size */ &numBytesReturned, /* returned buffer size */ (LPOVERLAPPED) &HidOverlapped ); /* long pointer to an OVERLAPPED structure */ /*if (!bResult) { if ((dwError=GetLastError()) == ERROR_IO_PENDING) { // ::MessageBox(m_hWnd,"write io pending",0,0); while (!GetOverlappedResult(r_handle,&HidOverlapped,&numBytesReturned,TRUE)) { dwError = GetLastError(); if(dwError == ERROR_IO_INCOMPLETE) { break; } else { ClearCommError(r_handle,&dwErrorFlags,&ComStat); break; } } } else { // some other error occurred wsprintf( szError, "\n\r <CE-%u>",dwError); ::MessageBox(m_hWnd,szError,0,0); ClearCommError(r_handle,&dwErrorFlags,&ComStat); if (dwErrorFlags>0) { wsprintf(szError,"\n\r <CE-%u>",dwErrorFlags); ::MessageBox(m_hWnd,szError,0,0); } return ; } } */ /* wait for IN report event. Note that if a report does not occur in the time set by the 'dwMilliseconds' parameter, then this function returns with a FALSE result and the HID device did not provide a report. If the function returns TRUE, then a report did occur and the data is ready to be read from the buffer specified in the ReadFile function call.*/ bResult = WaitForSingleObject( ReportEvent, 20000); /* if the transaction timed out, then we have to manually cancel the request */ if(bResult == WAIT_TIMEOUT || bResult == WAIT_ABANDONED) { //::MessageBox(m_hWnd,"@@@@@@@@",0,0); CancelIo(&r_handle); } /* Process in the input data. Note that the first byte (i.e. inbuffer[0] is the report ID for the HID report. We can just ignore this value. The first data byte of interest is inbuffer[1] */ if(bResult == WAIT_OBJECT_0) { /* check if user pressed button */ if(inbuffer[1]!=00) { if(inbuffer[1]==0x23) { //::PostMessage(m_hWnd,UM_KeyUp,inbuffer[3],0); SendKeyEvent(m_hWnd,inbuffer[3]); } if(inbuffer[1]==0x24) { //::PostMessage(m_hWnd,UM_KeyUp,inbuffer[3],0); { b='0'+inbuffer[2]; ver[0]=b; b='0'+inbuffer[3]; ver[1]=b; b='0'+inbuffer[4]; ver[2]=b; b='0'+inbuffer[5]; ver[3]=b; } } } } } DataInputThreadActive = FALSE; } |
|
沙发#
发布于:2009-08-04 16:44
顶一下,我碰到的问题是:在监听线程里,不断地读取D12返给PC端的数据,但是异步ReadFile返回的错误码刚开始是:ERROR_IO_PENDING,等过了一段时间就返回错误码:ERROR_WORKING_SET_QUOTA。应该一直都是ERROR_IO_PENDING啊,怎么时间一长就返回ERROR_WORKING_SET_QUOTA。请各位DX帮忙,谢谢。
|
|
板凳#
发布于:2018-09-13 17:29
这个问题后面有没有解决呀?我现在也是跟楼主一样的情况,USB HID开一个线程写一段时间后出现的!不知道楼主还来不来?
|
|
地板#
发布于:2019-03-03 18:30
现在做驱动的人少了:)
|
|
|