Advertisement
Aiduss

Untitled

Jun 28th, 2017
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. int CSerial::ReadData(void *buffer, int limit)
  2. {
  3.  
  4. if (!m_bOpened || m_hIDComDev == NULL) return(0);
  5.  
  6. BOOL bReadStatus;
  7. DWORD dwBytesRead, dwErrorFlags;
  8. COMSTAT ComStat;
  9.  
  10. ClearCommError(m_hIDComDev, &dwErrorFlags, &ComStat);
  11. if (!ComStat.cbInQue) return(0);
  12.  
  13. dwBytesRead = (DWORD)ComStat.cbInQue;
  14. if (limit < (int)dwBytesRead) dwBytesRead = (DWORD)limit;
  15.  
  16. bReadStatus = ReadFile(m_hIDComDev, buffer, dwBytesRead, &dwBytesRead, &m_OverlappedRead);
  17. if (!bReadStatus){
  18. if (GetLastError() == ERROR_IO_PENDING){
  19. WaitForSingleObject(m_OverlappedRead.hEvent, 2000);
  20. return((int)dwBytesRead);
  21. }
  22. return(0);
  23. }
  24.  
  25. return((int)dwBytesRead);
  26.  
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement