Click here to Skip to main content
15,914,335 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Question of style Pin
Chris Losinger12-Jun-02 13:26
professionalChris Losinger12-Jun-02 13:26 
GeneralRe: Question of style Pin
Shog912-Jun-02 13:28
sitebuilderShog912-Jun-02 13:28 
GeneralRe: Question of style Pin
redeemer12-Jun-02 10:23
redeemer12-Jun-02 10:23 
GeneralRe: Question of style Pin
Navin12-Jun-02 15:41
Navin12-Jun-02 15:41 
GeneralRe: Ok, here is the run down... Pin
Tim Smith12-Jun-02 16:11
Tim Smith12-Jun-02 16:11 
Generalhelp Pin
12-Jun-02 8:09
suss12-Jun-02 8:09 
GeneralRe: help Pin
Michael P Butler12-Jun-02 11:16
Michael P Butler12-Jun-02 11:16 
GeneralReadFile from Comm port Pin
JohnnyG12-Jun-02 7:19
JohnnyG12-Jun-02 7:19 
This code is from the mttty sample in MSDN but I'm not sure how ReadFile works. It says it does not return until it encounters an error or the actual amount of bytes read equals what was specified as a parameter. I'm wondering how this code works because it can only write the data to disk in the else block or after the WaitForMultipleObjects call. I've modified some of the code so that OutputABuffer() should now be OutputABufferToFile(). I'm a little confused how threading works here. If ReadFile doesn't return until 512 bytes are read then how does the WaitForMultipleObjects apply? It looks like the code in the WaitForMultipleObjects section does the same thing...write to a file, as the code after the else block of the ReadFile call.

#define AMOUNT_TO_READ 512

while ( !fThreadDone )
{

//
// If no reading is allowed, then set flag to
// make it look like a read is already outstanding.
//
if (NOREADING( TTYInfo ))
fWaitingOnRead = TRUE;

//
// if no read is outstanding, then issue another one
//
if (!fWaitingOnRead)
{
if (!ReadFile(COMDEV(TTYInfo), lpBuf, AMOUNT_TO_READ, &dwRead, &osReader))
{
if (GetLastError() != ERROR_IO_PENDING) // read not delayed?
ErrorInComm("ReadFile in ReaderAndStatusProc");

fWaitingOnRead = TRUE;
}
else
{ // read completed immediately
if ((dwRead != MAX_READ_BUFFER) && SHOWTIMEOUTS(TTYInfo))
UpdateStatus("Read timed out immediately.\r\n");

// modify section here to assemble 20 byte messages before writing to disk
if (dwRead)
{
if(gdwReceiveState == RECEIVE_CAPTURED)
{
OutputABufferToFile(ghFileCapture, lpBuf, dwRead);

}
}
}
}

.
.
.
//
// wait for pending operations to complete
//
if ( fWaitingOnStat && fWaitingOnRead )
{
dwRes = WaitForMultipleObjects(NUM_READSTAT_HANDLES, hArray, FALSE, STATUS_CHECK_TIMEOUT);
switch(dwRes)
{
//
// read completed
//
case WAIT_OBJECT_0:
if (!GetOverlappedResult(COMDEV(TTYInfo), &osReader, &dwRead, FALSE)) {
if (GetLastError() == ERROR_OPERATION_ABORTED)
UpdateStatus("Read aborted\r\n");
else
ErrorInComm("GetOverlappedResult (in Reader)");
}
else { // read completed successfully
if ((dwRead != MAX_READ_BUFFER) && SHOWTIMEOUTS(TTYInfo))
UpdateStatus("Read timed out overlapped.\r\n");

if (dwRead)
OutputABufferToFile(ghFileCapture, lpBuf, dwRead);
// OutputABuffer(hTTY, lpBuf, dwRead);
}

fWaitingOnRead = FALSE;
break;
.
.
.
case WAIT_TIMEOUT:
.
.
} // END WHILE LOOP

GeneralRe: ReadFile from Comm port Pin
JohnnyG12-Jun-02 10:16
JohnnyG12-Jun-02 10:16 
GeneralWindows Messaging Timing and Threads Pin
SanShou12-Jun-02 6:41
SanShou12-Jun-02 6:41 
GeneralRe: Windows Messaging Timing and Threads Pin
NormDroid12-Jun-02 9:40
professionalNormDroid12-Jun-02 9:40 
GeneralCallbakc Functions Pin
arthivjii12-Jun-02 6:36
arthivjii12-Jun-02 6:36 
GeneralRe: Callbakc Functions Pin
Chris Losinger12-Jun-02 6:55
professionalChris Losinger12-Jun-02 6:55 
GeneralRe: Callbakc Functions Pin
Alexandru Savescu12-Jun-02 8:43
Alexandru Savescu12-Jun-02 8:43 
GeneralRe: Callbakc Functions Pin
Chris Losinger12-Jun-02 9:00
professionalChris Losinger12-Jun-02 9:00 
GeneralInstallshield questions... Pin
Mike Zinni12-Jun-02 5:36
Mike Zinni12-Jun-02 5:36 
GeneralRe: Installshield questions... Pin
Navin12-Jun-02 8:33
Navin12-Jun-02 8:33 
QuestionHi! everybody! How about "graph line printing"? Pin
12-Jun-02 5:41
suss12-Jun-02 5:41 
QuestionHow to fill a vector or a list with data from a file! Pin
JMajors9812-Jun-02 4:50
JMajors9812-Jun-02 4:50 
AnswerRe: How to fill a vector or a list with data from a file! Pin
Chris Losinger12-Jun-02 5:39
professionalChris Losinger12-Jun-02 5:39 
AnswerRe: How to fill a vector or a list with data from a file! Pin
Joaquín M López Muñoz12-Jun-02 11:57
Joaquín M López Muñoz12-Jun-02 11:57 
AnswerRe: How to fill a vector or a list with data from a file! Pin
Mike Nordell13-Jun-02 3:23
Mike Nordell13-Jun-02 3:23 
GeneralParseCommandLine Pin
Anthony988712-Jun-02 4:45
Anthony988712-Jun-02 4:45 
GeneralRe: ParseCommandLine Pin
Le centriste12-Jun-02 5:37
Le centriste12-Jun-02 5:37 
GeneralRe: ParseCommandLine Pin
Navin12-Jun-02 8:39
Navin12-Jun-02 8:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.