-
Serial Communic
Hi All,
I have one porblem regarding WaitCommEvent() function.I written one program which is serially connected to modem and waiting for carrier detect event after dialing to modem using "ATDT3453" command.
Problem--> At the first time WaitCommEvent() function return after the carrier detect over modem.But at the second time in continously running program when I again dialing to modem and waiting for Carrier detect event using function WaitCommEvent(),so the problem is at the second time it will return before the detection of event(RLSD or Carrier Detect)
I am originally coding like this,
Code:
DWORD dwCommEvent;
SetCommMask(m_nCommPortHandle,EV_RLSD);
while(1)
{
WaitCommEvent(m_nCommPortHandle, &dwCommEvent, NULL);
if(dwCommEvent==EV_RLSD)
{
FlushFileBuffers(m_nCommPortHandle);
break;
}
}
return TRUE;
Rahul
Pune(INDIA)
-
You should check for errors and use EV_RLSD as a bit flag:
Code:
char buff[64];
DWORD dwCommEvent;
if (!SetCommMask(m_nCommPortHandle, EV_RLSD))
{
wsprintfA(buff, "LastError = %d", GetLastError());
MessageBoxA(0, buff, "SetCommMask() Failed", MB_OK);
return FALSE;
}//if
for(;;)
{
if (!WaitCommEvent(m_nCommPortHandle, &dwCommEvent, 0))
{
wsprintfA(buff, "LastError = %d", GetLastError());
MessageBoxA(0, buff, "WaitCommEvent() Failed", MB_OK);
return FALSE;
}//if
if (dwCommEvent & EV_RLSD)
{
FlushFileBuffers(m_nCommPortHandle);
break;
}//if
}//for
You should also know that using this method does not indicate what state the line is currently in - it only indicates that it has changed since the last call to WaitCommEvent() or SetCommMask().
If you need to know the actual state of the line (high or low), you can call GetCommModemStatus().
gg