
Andreas,
Thanks for the help. I looked at the example you pointed me to, but am still
having problems.
I am using overlapped i/o and I bumped the priority up to above normal for
the transmit thread and highest for the receive thread but no luck.
For some reason ReadModem just is not getting any data in my thread. The
TransmitThread seems to work ok though.
I know ReadModem works since I used it earlier in my program in a non
threaded function during the logging in process to the calling program.
I thought it was getting data earlier but it turned out that some how the
buffer I used in ReceiveThread was getting overwritten with data in the
transmit thread. No events ever got signalled and dwReadLen in the ReadFile
call always returns 0 so I know it is not working right.
My code follows below. I made the ReceiveThread as simple as possible to
test it. The SendCommand function is the most important part of the
TransmitThread as far as TAPI is concerned.
ReadModem and WriteModem are the functions that use TAPI. ReceiveThread and
TransmitThread are the threads that use ReadModem and WriteModem,
respectively.
Do you have any ideas what I am doing wrong or what is going on?
Thanks,
Greg
bool CTapiModem::WriteModem(int len, unsigned char *buf, int timeout)
{
DWORD dwWriteLen =0;
int nRet;
char *szText;
OVERLAPPED ov = {0, 0, 0, 0, NULL}; // Initialization is important!
ov.hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
ov.Offset = 0;
ov.OffsetHigh = 0;
nRet = WriteFile(m_hSerialHandle,buf,len,&dwWriteLen,&ov);
if(!nRet)
{
nRet = GetLastError();
if(nRet != ERROR_IO_PENDING)
{
GetErrorString(nRet,szText);
return FALSE;
}
switch(WaitForSingleObject(ov.hEvent,timeout))
{
case WAIT_OBJECT_0:
GetOverlappedResult(m_hSerialHandle, &ov, &dwWriteLen,FALSE);
return TRUE;
break;
default:
break;
}
}
return FALSE;
}
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();