RS232 port programming issue

Discussion in 'MFC' started by KaimTazz, Oct 11, 2007.

  1. KaimTazz

    KaimTazz New Member

    Joined:
    Aug 8, 2007
    Messages:
    24
    Likes Received:
    0
    Trophy Points:
    0
    Hello Everybody,
    Please help me to solve the following trouble.
    I want to write an application to send and receive data through com port.
    I am using VC++ .Net 2003 for creating this MFC application.
    I write a Function to write data on com port as follows.
    Code:
    void CSerialCommTesterDlg ::WriteData ()
    {	
    	BOOL ans;
    	int length=0 ;
    	
             UpdateData ();
    	length = m_enter_text.GetAllocLength ();
    	ans=WriteFile(hComm , &m_enter_text, length, &dwWritten, &ovlw);
    	error_no = GetLastError ();
    	if(GetOverlappedResult(hComm ,&ovlw,&dwWritten ,TRUE)==S_OK )
    	{
    		m_idc_status.Format("No of Bytes send: %d", dwWritten );
    		UpdateData (FALSE);
    	}
    	error_no = GetLastError ();
    }
    I have successfully initialized com port and set the DCB.
    WriteFile() function returns 0, that means it has failed.
    and GetLastError returns 997, i.e. I/O pending, but in this situation dwWritten in GetOverLappedResult() is still giving me the exact no. of bytes written.
    Thus I am not able to send data. Plz help
     
    Last edited by a moderator: Oct 11, 2007

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice