1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

RS232 port programming issue

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

  1. KaimTazz

    KaimTazz New Member

    Aug 8, 2007
    Likes Received:
    Trophy Points:
    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.
    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