Go4Expert

Go4Expert (http://www.go4expert.com/)
-   MFC (http://www.go4expert.com/forums/mfc/)
-   -   RS232 port programming issue (http://www.go4expert.com/forums/rs232-port-programming-issue-t6779/)

KaimTazz 11Oct2007 14:05

RS232 port programming issue
 
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


All times are GMT +5.5. The time now is 09:49.