title: ReadFile only reading one buffer character?
body: <p>I'm writing a program to communicate to a motor drive through a virtual com port via USB.  I'm making use of the windows.h file-io to communicate with it (CreateFile, WriteFile, ReadFile). I can write to the drive perfectly fine, but I run into an issue when trying to read from it. For some reason, the ReadFile only seems to read in one character from the buffer. Here's my code:</p>
  
  <pre><code>#define READ_BUFF_SIZE 500
  #define READ_TIMEOUT 5000
  void ReadInput(HANDLE hComm)
  {
      DWORD dwRead, dwRes;
      BOOL fWaitingOnRead = FALSE;
      OVERLAPPED osReader = {0};
      char lpBuf[READ_BUFF_SIZE] = {0};
  
      osReader.hEvent = CreateEvent(NULL,TRUE,FALSE,NULL);
      if(osReader.hEvent==NULL){
          cerr&lt;&lt;"Error creating overlapped handle!";return;}
  
      if(!fWaitingOnRead){
          if(!ReadFile(hComm, lpBuf, READ_BUFF_SIZE, &amp;dwRead, &amp;osReader)){
              if(GetLastError()!=ERROR_IO_PENDING)
                  {cout&lt;&lt;"Error: "&lt;&lt;GetLastError()&lt;&lt;endl;return;}
              else
                  fWaitingOnRead = TRUE;
          }
          else {cout&lt;&lt;"a\n";PrintInput(lpBuf,dwRead);}
      }
  
      if(fWaitingOnRead){
          dwRes = WaitForSingleObject(osReader.hEvent,READ_TIMEOUT);
          cout&lt;&lt;"\n\nAfter WaitForSingleObject."&lt;&lt;endl;
          switch(dwRes)
          {
          case WAIT_OBJECT_0:
              if(!GetOverlappedResult(hComm,&amp;osReader,&amp;dwRead,TRUE))
                  cout&lt;&lt;"Error in Comm"&lt;&lt;endl;
              else
                  {cout&lt;&lt;"b\n\n";PrintInput(lpBuf,dwRead);}
              fWaitingOnRead = FALSE;
              break;
  
          case WAIT_TIMEOUT:
              cout&lt;&lt;"wait timeout"&lt;&lt;endl;
              break;
  
          default:
              cout&lt;&lt;"Default Case"&lt;&lt;endl;
              break;
          }
  
      }
  }
  </code></pre>
  
  <p>dwRead always seems to be set to 1. I'll get the first character that the drive outputs (an apostrophe), but it won't read the rest. I've found some workarounds in that if I modify it to expect only one character and then loop through the reading, it will perform.<br>
  Additionally, I need the query the drive for a response, so before calling this ReadInput function, I have to call a WriteBuffer to send a character. If I put a delay (~10-50ms) between the read and write calls, it reads the whole thing.  </p>
  
  <p>Anyone have any ideas on this? It's not a huge issue since I've found some workarounds, but it has been bothering me for the past few days.  </p>
  
  <p><strong>Edit:</strong> Clarification for tinman's questions.</p>