MSComm Help
-
Hi, I have a strange problem, I have no device connected to Com1 yet whatever I send via SetOutput() is waiting for me when I issue GetInput() I am using the MSComm ocx within my VC++ 6.0 as such: m_mscomm1.SetCommPort( 1 ); m_mscomm1.SetSettings( "9600,N,8,1" ); m_mscomm1.SetPortOpen( TRUE ); // now I write some date CString StringToWrite; StringToWrite = "Test"; COleVariant var; var.vt = VT_BSTR; var.bstrVal = StringToWrite.AllocSysString(); m_mscomm1.SetOutput( var ); // now I read the input buffer COleVariant oVA; CString ctmp; oVA.Attach( m_mscomm1.GetInput() ); ctmp.Format( "%s", oVA.bstrVal ); =========================== ctmp now = "Test";
-
Hi, I have a strange problem, I have no device connected to Com1 yet whatever I send via SetOutput() is waiting for me when I issue GetInput() I am using the MSComm ocx within my VC++ 6.0 as such: m_mscomm1.SetCommPort( 1 ); m_mscomm1.SetSettings( "9600,N,8,1" ); m_mscomm1.SetPortOpen( TRUE ); // now I write some date CString StringToWrite; StringToWrite = "Test"; COleVariant var; var.vt = VT_BSTR; var.bstrVal = StringToWrite.AllocSysString(); m_mscomm1.SetOutput( var ); // now I read the input buffer COleVariant oVA; CString ctmp; oVA.Attach( m_mscomm1.GetInput() ); ctmp.Format( "%s", oVA.bstrVal ); =========================== ctmp now = "Test";
There are two methods for reading... ---------------------- POLLING ======= ---------------------- Assuming the Mscomm control is on the form and has the name MyCom and that there is a form property named mybuffer, the following code illustrates how to poll for waiting characters ( this is in VB but same procedure you can use in VC) : Procedure myform.myproc IF Thisform.MyCom.InBufferCount > 0 Thisform.mybuffer = Thisform.mybuffer + Thisform.MyCom.Input ENDIF ENDPROC ---------------------- EVENT DRIVEN ( YOU SHOULD USE THIS BECAUSE THIS IS BETTER ) ===== ---------------------- For example, you can place the following code in the OnComm event to append received data to a property of a form called mybuffer: Procedure MyCom.OnComm IF This.CommEvent = 2 ThisForm.mybuffer = ThisForm.mybuffer + This.Input ENDIF ENDPROC ---------------------- Do this way and tell me if problem persist. Or You can read articles in msdn...(By searching in MSDN) one of good articles is : ****** INFO: Troubleshooting Tips for the MSComm Control ****** :-D :-D :-D :-D :-O :-O :-O :-O :-O :-O :-O :-O :) :-D :rose: :rose: :rose: :rose: -------------------------------------------------- Say Whatever You Know. Helping other people is good for health. ========= Manish ========= ---------------------------------------------------