Asked By vandenberg_greg
20-Jan-10 09:17 PM

Andreas,
I tried the suggestions of increasing the read thread's priority to highest,
and double checked my ReadModem function that uses an overlapped read and I
still cannot see why it is not getting any data. The WaitForSingleObject
always times out before it gets WAIT_OBJECT_0. If I set it the timeout to
INFINITE it just sits there. Do you have any ideas, suggestions etc. Please
help.
Greg
int CTapiModem::ReadModem(unsigned char *buf, int *count, int timeout)
{
// read "count" bytes at a time from modem
DWORD dwReadLen =0;
int nRet;
char *szText;
OVERLAPPED ov = {0, 0, 0, 0, NULL}; // Initialization is important!;
//createEvent parameters:
//1 - pointer to security attibutes structure
//2 - manual reset
//3 - initial state
//4 name of event object
ov.hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
ov.Offset = 0;
ov.OffsetHigh = 0;
if (m_hSerialHandle != NULL)
{
nRet = ReadFile(m_hSerialHandle,buf,*count,&dwReadLen,&ov);
if (!nRet)
{
nRet = GetLastError();
if(nRet != ERROR_IO_PENDING)
{
GetErrorString(nRet,szText);
if (nRet == ERROR_INVALID_HANDLE)
{
return 1;
}
}
}
if (WaitForSingleObject(ov.hEvent,timeout) == WAIT_OBJECT_0)
{
GetOverlappedResult(m_hSerialHandle, &ov, &dwReadLen,FALSE);
}
else
{
return 2; //timeout elapsed, objects state = non-signalled
// = buffer empty
}
if (dwReadLen == 0)
{
return 3;
}
else
{
*count = dwReadLen;
return 0;
}
}
else
{
*buf = NULL;
return 5; //m_hSerialHandle == NULL
}
}