COM port Access
-
Hi All. I am after some code samples/info about controlling a device via the com port using C++/MFC (though I have never used it). Any info/articles/links appreciated. Specifically, would like to set up the com port (9600 baud, 8, None, 1) and send and recieve text strings (Hyperterminal Style). Cheers If sex is a pain in the ass, then you are doing it wrong!
-
Hi All. I am after some code samples/info about controlling a device via the com port using C++/MFC (though I have never used it). Any info/articles/links appreciated. Specifically, would like to set up the com port (9600 baud, 8, None, 1) and send and recieve text strings (Hyperterminal Style). Cheers If sex is a pain in the ass, then you are doing it wrong!
Hello Here is the way how i did it. Create a ActiveX Contrl-->Microsoft Communication Control32. and add a member Variable for it. Create a OnComm Event with the Wizard. Open the Port with: m_MSComm is the member variable for the Active X Control
m_MSComm.SetCommPort(1); m_MSComm.SetSettings(9600,N,8,1);//DCB in the help file m_MSComm.SetHandshaking(0); m_MSComm.SetInputLen(1); m_MSComm.SetRThreshold(1); m_MSComm.SetDTREnable(false); m_MSComm.SetRTSEnable(false); m_MSComm.SetPortOpen(true);
Close the Port: m_MSComm.SetPortOpen(false); Send a Bytem_MSComm.SetRTSEnable(true); CString str; str= //add the string you want to send vVar.vt = VT_BSTR; vVar.bstrVal=str.AllocSysString(); m_MSComm.SetOutput(vVar); SysFreeString(vVar.bstrVal); m_MSComm.SetRTSEnable(false);
Recieve something://COODE GENERATED BY THE WIZARD! BEGIN_EVENTSINK_MAP(CMainDlg, CDialog) //{{AFX_EVENTSINK_MAP(CMainDlg) ON_EVENT(CMainDlg, IDC_MSCOMM, 1 /* OnComm */, OnMscomm, VTS_NONE) //}}AFX_EVENTSINK_MAP END_EVENTSINK_MAP() //COODE GENERATED BY THE WIZARD END! //Called by an event of the COM void CMainDlg::OnMscomm() { // TODO: Add your control notification handler code here switch(m_MSComm.GetCommEvent()) { case 2: // CommEvReceive: CString Empf=m_MSComm.GetInput()); break; } }
That should it be. Mfg DarkMarine. DarkMarine@aon.at -
Hello Here is the way how i did it. Create a ActiveX Contrl-->Microsoft Communication Control32. and add a member Variable for it. Create a OnComm Event with the Wizard. Open the Port with: m_MSComm is the member variable for the Active X Control
m_MSComm.SetCommPort(1); m_MSComm.SetSettings(9600,N,8,1);//DCB in the help file m_MSComm.SetHandshaking(0); m_MSComm.SetInputLen(1); m_MSComm.SetRThreshold(1); m_MSComm.SetDTREnable(false); m_MSComm.SetRTSEnable(false); m_MSComm.SetPortOpen(true);
Close the Port: m_MSComm.SetPortOpen(false); Send a Bytem_MSComm.SetRTSEnable(true); CString str; str= //add the string you want to send vVar.vt = VT_BSTR; vVar.bstrVal=str.AllocSysString(); m_MSComm.SetOutput(vVar); SysFreeString(vVar.bstrVal); m_MSComm.SetRTSEnable(false);
Recieve something://COODE GENERATED BY THE WIZARD! BEGIN_EVENTSINK_MAP(CMainDlg, CDialog) //{{AFX_EVENTSINK_MAP(CMainDlg) ON_EVENT(CMainDlg, IDC_MSCOMM, 1 /* OnComm */, OnMscomm, VTS_NONE) //}}AFX_EVENTSINK_MAP END_EVENTSINK_MAP() //COODE GENERATED BY THE WIZARD END! //Called by an event of the COM void CMainDlg::OnMscomm() { // TODO: Add your control notification handler code here switch(m_MSComm.GetCommEvent()) { case 2: // CommEvReceive: CString Empf=m_MSComm.GetInput()); break; } }
That should it be. Mfg DarkMarine. DarkMarine@aon.atSuperb Stuff: Looks like I will be dragged (Kicking and Screming) into MFC. Thankyou. Were is .at at ? (Atlantis, Austria, Antartica) ? If sex is a pain in the ass, then you are doing it wrong!
-
Superb Stuff: Looks like I will be dragged (Kicking and Screming) into MFC. Thankyou. Were is .at at ? (Atlantis, Austria, Antartica) ? If sex is a pain in the ass, then you are doing it wrong!