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. MSComm Help

MSComm Help

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++
2 Posts 2 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.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    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";

    M 1 Reply Last reply
    0
    • L Lost User

      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";

      M Offline
      M Offline
      mProject
      wrote on last edited by
      #2

      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 ========= ---------------------------------------------------

      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