Serial Communic

This is a discussion on Serial Communic within the Windows Programming forums, part of the Platform Specific Boards category; Hi All, I have one porblem regarding WaitCommEvent() function.I written one program which is serially connected to modem and waiting ...

  1. #1
    Registered User
    Join Date
    Jul 2005
    Posts
    1

    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)

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,691
    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Lame null append cause buffer to crash
    By cmoo in forum C Programming
    Replies: 8
    Last Post: 12-29-2008, 03:27 AM
  2. Music Programming - Serial Matrix Display (Help needed)
    By CrazyHorse in forum C Programming
    Replies: 1
    Last Post: 11-13-2007, 04:28 PM
  3. Music Programming - Serial Matrix Display
    By CrazyHorse in forum C Programming
    Replies: 1
    Last Post: 11-12-2007, 04:16 PM
  4. Please help with serial communication problem - Long
    By spdylude in forum Windows Programming
    Replies: 3
    Last Post: 04-06-2005, 10:41 AM
  5. DOS, Serial, and Touch Screen
    By jon_nc17 in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 01-08-2003, 04:59 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21