TAPIaroundTheWorld
(1)
GetOverlappedResult
(1)
GetLastError
(1)
CTapiModem
(1)
LineInitializeEx
(1)
TransmitThread
(1)
HSerialHandle
(1)
ReceiveThread
(1)

TAPI modem doesn't seem to receive all the data being sent to it

Asked By vandenberg_greg
11-Jan-10 11:34 PM
Andreas, thanks for the help with lineInitializeEx constanly returning
LINEERR_OPERATIONFAILED. It turned out that setting the thread priority to
Normal fixed it.

However now I am having a problem with my application skipping data that gets
sent to it. I have two separate threads that read and write from the modem.
My program sends a message to the calling program letting it know that
everything connected ok. The calling program immediately responds (< 1
millisecond) with its response, but this message is not getting picked up by
my program. After around 9 seconds the calling program sends the same
response again which is then picked up by my program, so it kind of works but
my boss does not like the delay. The old software that my application is based
on had custom written modem software in 16 bit assembly language and only
runs in DOS, but it appears to get everything written to it.

Could it be that the readfile and writefile functions my thread uses are
stepping on each other? is there a way to fix this? I tried putting a mutex
lock and unlock around the pertinant bits of code but this did not appear to
do anything.

Greg, you are welcome.

Andreas Marschall [exMVP TAPI] replied to vandenberg_greg
12-Jan-10 06:25 AM
Greg, you are welcome.


When you are using UniModem TSP to transfer data then you have to use
OVERLAPPED IO.
In addition it may even be required to increase (read and write) thread
priority above normal.
Please see the TapiComm sample from MS P-SDK:
http://www.tapi.info/default.aspx/TAPI/PSDKSamples.html
Especially see TapiComm.Doc for "overlapped" and "priority".

--
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,Thanks for the help.

vandenberg_greg replied to vandenberg_greg
15-Jan-10 10:46 PM
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();

Greg,Out of curiosity, can you reboot and try to run this application again?

mikenac replied to vandenberg_greg
02-Feb-10 12:03 PM
Greg,

Out of curiosity, can you reboot and try to run this application again? I am
having a similar issue that occurs when the TAPI service gets "Goofed Up".
The service will not restart once the "Goof Up" occurs and requires a reboot
for me to again get data.
Post Question To EggHeadCafe