CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 13 of 13
  1. #1
    Join Date
    Feb 2012
    Posts
    181

    [RESOLVED] ComStat.cbInQue

    Is it possible, that ComStat.cbInQue contains value greater than 4096?

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398

    Re: ComStat.cbInQue

    Why not?
    Victor Nijegorodov

  3. #3
    Join Date
    Feb 2012
    Posts
    181

    Lightbulb Re: ComStat.cbInQue

    VictorN, I transmit file through Com with size ~4399 b, but "archive goal" only 4096)

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398

    Re: ComStat.cbInQue

    How could you write more bytes that internal buffer allows? You should have got ERROR_IO_PENDING!
    Victor Nijegorodov

  5. #5
    Join Date
    Feb 2012
    Posts
    181

    Question Re: ComStat.cbInQue

    VictorN,
    Internal buffer - 4096b?
    I write bytes on DOS device...

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398

    Re: ComStat.cbInQue

    Quote Originally Posted by AKE View Post
    VictorN,
    Internal buffer - 4096b?
    I write bytes on DOS device...
    I don't know the buffer capacity. But I don't care! My WriteFile calls care about it returning TRUE (if writing succeed) or FALSE, and GetLastError returns the reason of failure!
    Victor Nijegorodov

  7. #7
    Join Date
    Feb 2012
    Posts
    181

    Question Re: ComStat.cbInQue

    VictorN, Do you know how change buffer size?

  8. #8
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398

    Re: ComStat.cbInQue

    Quote Originally Posted by AKE View Post
    VictorN, Do you know how change buffer size?
    Why???
    Why not just fix your code instead?

    Besides, I doubt it could be possible at all!
    Victor Nijegorodov

  9. #9
    Join Date
    Feb 2012
    Posts
    181

    Re: ComStat.cbInQue

    Code:
    void Reader(void *args)
    {
      DWORD Err; COMSTAT ComStat;
      DWORD tmpBytesRead;
      while (true)
      {
      DWORD dwRead = 0;
      while (!dwRead)
      {
       if (Writing) break;     
       ClearCommError(hComPort, &Err, &ComStat);
       dwRead = ComStat.cbInQue;
       Sleep(10);
      }
      if (Writing) continue;
      DWORD dwRead2=0;
      while (dwRead != dwRead2)
      {
       dwRead2 = dwRead;
       Sleep(100);  
       ClearCommError(hComPort, &Err, &ComStat);
       dwRead = ComStat.cbInQue;  
      }
       BYTE *arr = new BYTE[1024*1024];
       if (ReadFile(hComPort, arr, min(dwRead, 1024*1024), &tmpBytesRead, NULL))
       {
         BYTE CRC = arr[dwRead-2];
         if ((CRC != GetCRC(arr, dwRead-2))||(arr[dwRead-1] != END_OF_PACKET))
    	MessageBox(NULL,L"CRC error or end file.", L"ComFile", 0);
    	 else
           {
             OPENFILENAME ofn;       // common dialog box structure
             wchar_t szFile[260];    // buffer for file name
             ZeroMemory(&ofn, sizeof(ofn));
             ofn.lStructSize = sizeof(ofn);
             ofn.hwndOwner = hwnd;
             ofn.lpstrFile = (LPWSTR) szFile;
             ofn.lpstrFile[0] = '\0';
             ofn.nMaxFile = sizeof(szFile);
             ofn.lpstrFilter = L"All\0*.*";
             ofn.nFilterIndex = 1;
             ofn.lpstrFileTitle = NULL;
             ofn.nMaxFileTitle = 0;
             ofn.lpstrInitialDir = NULL;
             ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
    	 HANDLE hf;
    	 DWORD Written;
    	 if (GetSaveFileName(&ofn)==TRUE)
    	 {
               hf = CreateFile(ofn.lpstrFile, 
                        GENERIC_WRITE,
                        0,
                        (LPSECURITY_ATTRIBUTES) NULL,
                        CREATE_ALWAYS,
                        FILE_ATTRIBUTE_NORMAL,
                        (HANDLE) NULL);
    		  if (!WriteFile(hf, arr, dwRead-2, &Written, NULL))
    	              MessageBox(hwnd,L"Error writing file", L"ComFile", 0); 
    			else  MessageBox(hwnd,L"Success", L"ComFile", 0);
    	     CloseHandle(hf);
    	   }
    	 }
       } else MessageBox(NULL,L"Error reading com-port.", L"ComFile", 0);
       PurgeComm(hComPort, PURGE_RXCLEAR);
      }
    }
    Last edited by AKE; March 21st, 2012 at 05:34 AM.

  10. #10
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398

    Re: ComStat.cbInQue

    And what is this code snippet supposed to do?
    And what did you expect from the Forum posting this very bad formatted code snippet with a lot of undeclared variables?
    Victor Nijegorodov

  11. #11
    Join Date
    Feb 2012
    Posts
    181

    Exclamation Re: ComStat.cbInQue

    And what is this code snippet supposed to do?
    Read com port, while data hadn't received. Than reading it and save to file (file name through save file name)...
    hComPort - handle of open com port
    Writting - if writting, that reading absent.
    END_OF_PACKET - Symbol of packet end

  12. #12
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398

    Re: ComStat.cbInQue

    And does this bad written, very bad formatted, not compilable and buggy code have to do with your OP:
    Quote Originally Posted by AKE
    Is it possible, that ComStat.cbInQue contains value greater than 4096?
    Victor Nijegorodov

  13. #13
    Join Date
    Feb 2012
    Posts
    181

    Exclamation Re: ComStat.cbInQue

    Quote Originally Posted by VictorN View Post
    And does this bad written, very bad formatted, not compilable and buggy code have to do with your OP:
    Thanks
    I had found "SetupComm". Problem had resolved.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured