PSS ID Number: 175551
Article Last Modified on 12/21/2001
DWORD WINAPI
ReadThread (LPVOID pvarg)
{
DWORD BytesTransferred;
DWORD fdwCommMask;
DWORD dwErrors;
COMSTAT Stat;
COMMTIMEOUTS CommTimeouts;
DWORD t;
BYTE ReadBuffer[1024];
GetCommTimeouts (hPort, &CommTimeouts);
CommTimeouts.ReadIntervalTimeout = MAXDWORD;
CommTimeouts.ReadTotalTimeoutMultiplier = 0;
CommTimeouts.ReadTotalTimeoutConstant = 0; // Read timeout at 50msec
SetCommTimeouts (hPort, &CommTimeouts);
SetCommMask (hPort, EV_RXCHAR | EV_CTS | EV_DSR | EV_RLSD | EV_RING);
while (!v_bStopThread) {
WaitCommEvent (hPort, &fdwCommMask, 0);
// Reset the comm Mask
SetCommMask (hPort, EV_RXCHAR | EV_CTS | EV_DSR | EV_RING);
if (fdwCommMask &= EV_RXCHAR) {
// Loop getting data.
// Need to loop because our buffer is only 1024 bytes
while (TRUE)
{
ClearCommError( hPort,&dwErrors,&Stat);
if (!Stat.cbInQue)
break;
else
{
ReadFile ( hPort,
&ReadBuffer,
(Stat.cbInQue>1024)?1024:Stat.cbInQue,
&BytesTransferred,
0
);
// do something with data
}
// Loop around and check for more data
// In case additional byte has arrived while reading.
}
}
}
return 0;
}
Keywords: kbAPI kbinfo KB175551
Technology: kbAudDeveloper kbWin32API kbWin32sSearch kbWinCESearch