Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. COM port Access

COM port Access

Scheduled Pinned Locked Moved C / C++ / MFC
c++com
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    wogerdoger
    wrote on last edited by
    #1

    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!

    A 1 Reply Last reply
    0
    • W wogerdoger

      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!

      A Offline
      A Offline
      Anonymous
      wrote on last edited by
      #2

      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 Byte m_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

      W 1 Reply Last reply
      0
      • A Anonymous

        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 Byte m_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

        W Offline
        W Offline
        wogerdoger
        wrote on last edited by
        #3

        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!

        L 1 Reply Last reply
        0
        • W wogerdoger

          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!

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Glad that i could help you. and .at is Austria. :) Mfg DarkMarine

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups