yorkleo
驱动牛犊
驱动牛犊
  • 注册日期2008-04-08
  • 最后登录2009-08-27
  • 粉丝0
  • 关注0
  • 积分-2分
  • 威望32点
  • 贡献值1点
  • 好评度1点
  • 原创分0分
  • 专家分0分
阅读:4401回复:3

USB 驱动使用WriteFile传数据给设备,工作一段时间后出现"配额不足,无法完成请求的服务"

楼主#
更多 发布于:2009-07-16 09:46
我这个设备有两个功能: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;

}




sanone28
驱动牛犊
驱动牛犊
  • 注册日期2009-06-05
  • 最后登录2010-01-18
  • 粉丝1
  • 关注0
  • 积分20分
  • 威望181点
  • 贡献值1点
  • 好评度0点
  • 原创分0分
  • 专家分0分
沙发#
发布于:2009-08-04 16:44
顶一下,我碰到的问题是:在监听线程里,不断地读取D12返给PC端的数据,但是异步ReadFile返回的错误码刚开始是:ERROR_IO_PENDING,等过了一段时间就返回错误码:ERROR_WORKING_SET_QUOTA。应该一直都是ERROR_IO_PENDING啊,怎么时间一长就返回ERROR_WORKING_SET_QUOTA。请各位DX帮忙,谢谢。
create_ce
驱动牛犊
驱动牛犊
  • 注册日期2018-09-13
  • 最后登录2018-09-13
  • 粉丝0
  • 关注0
  • 积分1分
  • 威望10点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
  • 社区居民
板凳#
发布于:2018-09-13 17:29
这个问题后面有没有解决呀?我现在也是跟楼主一样的情况,USB HID开一个线程写一段时间后出现的!不知道楼主还来不来?
znsoft
管理员
管理员
  • 注册日期2001-03-23
  • 最后登录2023-10-25
  • 粉丝300
  • 关注6
  • 积分910分
  • 威望14796点
  • 贡献值7点
  • 好评度2410点
  • 原创分5分
  • 专家分100分
  • 社区居民
  • 最爱沙发
  • 社区明星
地板#
发布于:2019-03-03 18:30
现在做驱动的人少了:)
http://www.zndev.com 免费源码交换网 ----------------------------- 软件创造价值,驱动提供力量! 淡泊以明志,宁静以致远。 ---------------------------------- 勤用搜索,多查资料,先搜再问。
游客

返回顶部