-
March 21st, 2012, 04:05 AM
#1
[RESOLVED] ComStat.cbInQue
Is it possible, that ComStat.cbInQue contains value greater than 4096?
-
March 21st, 2012, 04:14 AM
#2
Re: ComStat.cbInQue
Victor Nijegorodov
-
March 21st, 2012, 04:25 AM
#3
Re: ComStat.cbInQue
VictorN, I transmit file through Com with size ~4399 b, but "archive goal" only 4096)
-
March 21st, 2012, 04:42 AM
#4
Re: ComStat.cbInQue
How could you write more bytes that internal buffer allows? You should have got ERROR_IO_PENDING!
Victor Nijegorodov
-
March 21st, 2012, 04:45 AM
#5
Re: ComStat.cbInQue
VictorN,
Internal buffer - 4096b?
I write bytes on DOS device...
-
March 21st, 2012, 04:54 AM
#6
Re: ComStat.cbInQue
Originally Posted by AKE
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
-
March 21st, 2012, 05:03 AM
#7
Re: ComStat.cbInQue
VictorN, Do you know how change buffer size?
-
March 21st, 2012, 05:06 AM
#8
Re: ComStat.cbInQue
Originally Posted by AKE
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
-
March 21st, 2012, 05:11 AM
#9
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.
-
March 21st, 2012, 05:19 AM
#10
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
-
March 21st, 2012, 05:32 AM
#11
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
-
March 21st, 2012, 05:46 AM
#12
Re: ComStat.cbInQue
And does this bad written, very bad formatted, not compilable and buggy code have to do with your OP:
Originally Posted by AKE
Is it possible, that ComStat.cbInQue contains value greater than 4096?
Victor Nijegorodov
-
March 21st, 2012, 05:51 AM
#13
Re: ComStat.cbInQue
Originally Posted by VictorN
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|