TAPIaroundTheWorld
(1)
ReadIntervalTimeout
(1)
GetOverlappedResult
(1)
SetCommTimeouts
(1)
GetLastError
(1)
CTapiModem
(1)
ExMVP
(1)
HSerialHandle
(1)

ReadFile still not working in thread

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
}

}

So is my problem with readfile not a tapi issue but communication port issue?

vandenberg_greg replied to vandenberg_greg
25-Jan-10 11:15 PM
So is my problem with readfile not a tapi issue but communication port issue?
I have 5 threads going on at once. Is this too mamy threads? This is really
frustrating.

Greg,I guess so.TAPI / UniModem TSP is only providing the comm handle.

Andreas Marschall [exMVP TAPI] replied to vandenberg_greg
26-Jan-10 08:49 AM
Greg,
I guess so.
TAPI / UniModem TSP is only providing the comm handle.


I do not think so.
What CPU usage does Task-Manager show?
In TaskMgr you can add colums for #handles, #threads, cpu% etc.

--
Best Regards
Andreas Marschall
Microsoft MVP for TAPI / Windows SDK / Visual C++ 2003-2008
TAPI / TSP Developer and Tester
My TAPI and TSPI FAQ:
http://www.I-B-A-M.de/Andreas_Marschall's_TAPI_and_TSPI_FAQ.htm
My Toto® Tools (a collection of free, mostly TAPI related tools):
http://www.i-b-a-m.de/Andreas_Marschall's_Toto_Tools.htm
TAPI development around the world (Frappr! map):
http://www.frappr.com/TAPIaroundTheWorld
* Please post all messages and replies to the newsgroup so all may
* benefit from the discussion.  Private mail is usually not replied to.
* This posting is provided "AS IS" with no warranties, and confers no
rights.

Andreas,I looked at the task manager performance window and the CPU usage was

vandenberg_greg replied to Andreas Marschall [exMVP TAPI]
26-Jan-10 09:27 PM
Andreas,

I looked at the task manager performance window and the CPU usage was around
15~20%. I looked in the Processes window and my applications CPU usage was
around 5~8%, Memory usage 8676 K, Handles around 200, and Threads were 8.
I created 5 threads plus the GUI. I do not know where the other 2 threads
came from.
I use Sleep() in some of the threads to keep the cpu usage down, is this a
problem?

I am thinking of writing a simple program to go through the login sequence
with the calling program, then just have a read thread and a write thread to
see if I can get any data.

Is there a Discussion Group for readfile comm issues?

Thanks,
Greg
After much web study and experimentation I was finally able to get readfileto
vandenberg_greg replied to vandenberg_greg
06-Apr-10 12:05 AM
After much web study and experimentation I was finally able to get readfile
to read data. I needed to do a ResetEvent to my overlapped structures before
each readfile and writefile, and I had to call SetCommTimeouts to set the
ReadIntervalTimeout to 100 ms.
After much web study and experimentation I was finally able to get readfileto
vandenberg_greg replied to vandenberg_greg
06-Apr-10 01:24 PM
After much web study and experimentation I was finally able to get readfile
to read data. I needed to do a ResetEvent to my overlapped structures before
each readfile and writefile, and I had to call SetCommTimeouts to set the
ReadIntervalTimeout to 100 ms.
Post Question To EggHeadCafe