Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to use ReadFile API Read HID Device synchronous

How to use ReadFile API Read HID Device synchronous

Scheduled Pinned Locked Moved C / C++ / MFC
questionjsonhelptutorial
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cedricvictor
    wrote on last edited by
    #1

    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.

    Richard Andrew x64R H 2 Replies Last reply
    0
    • C cedricvictor

      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.

      Richard Andrew x64R Offline
      Richard Andrew x64R Offline
      Richard Andrew x64
      wrote on last edited by
      #2

      Your question is not clear. It looks like you are asking how to set the variables preUsedSize and curUsedSize to zero. To that, the answer is:

      preUsedSize = 0;
      curUsedSize = 0;

      The difficult we do right away... ...the impossible takes slightly longer.

      1 Reply Last reply
      0
      • C cedricvictor

        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.

        H Offline
        H Offline
        Heng Xiangzhong
        wrote on last edited by
        #3

        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 !

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups