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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Serial Port Communication in MFC

Serial Port Communication in MFC

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++question
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.
  • Q Offline
    Q Offline
    QuickDeveloper
    wrote on last edited by
    #1

    Hi I Wrote a program to Communicate with a Serial Port in MFC.The problem is if i use WriteFile and ReadFile immediately i get the correct data.But if i Start a thread and use WaitCommEvent then the Program gets stuck up in WriteFile. I hav filled the DCB structure too. what could be the problem with WriteFile?? PS:I am not using Overlapped I/O Any Links Would do Fine.

    "Every morning I go through Forbes list of 40 richest people in the world. If my name is not in there, I go to work..!!!"

    CPalliniC R 2 Replies Last reply
    0
    • Q QuickDeveloper

      Hi I Wrote a program to Communicate with a Serial Port in MFC.The problem is if i use WriteFile and ReadFile immediately i get the correct data.But if i Start a thread and use WaitCommEvent then the Program gets stuck up in WriteFile. I hav filled the DCB structure too. what could be the problem with WriteFile?? PS:I am not using Overlapped I/O Any Links Would do Fine.

      "Every morning I go through Forbes list of 40 richest people in the world. If my name is not in there, I go to work..!!!"

      CPalliniC Offline
      CPalliniC Offline
      CPallini
      wrote on last edited by
      #2

      I think you have to post the relevant code. :)

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

      In testa che avete, signor di Ceprano?

      1 Reply Last reply
      0
      • Q QuickDeveloper

        Hi I Wrote a program to Communicate with a Serial Port in MFC.The problem is if i use WriteFile and ReadFile immediately i get the correct data.But if i Start a thread and use WaitCommEvent then the Program gets stuck up in WriteFile. I hav filled the DCB structure too. what could be the problem with WriteFile?? PS:I am not using Overlapped I/O Any Links Would do Fine.

        "Every morning I go through Forbes list of 40 richest people in the world. If my name is not in there, I go to work..!!!"

        R Offline
        R Offline
        Roger Stoltz
        wrote on last edited by
        #3

        QuickDeveloper wrote:

        if i Start a thread and use WaitCommEvent then the Program gets stuck up in WriteFile.....I am not using Overlapped I/O

        If you're not using overlapped I/O, you can only issue one request at any given time to the driver. If you issue another it will block waiting for the previously issued request, which is exactly what happens in your case: ::WaitCommEvent() is waiting for something to happen before returning while blocking the ::WriteFile() call. If you're writing an application that is supposed to issue both read and write requests, you should only consider the overlapped alternative. Have a look at an example on overlapped I/O here[^].


        "It's supposed to be hard, otherwise anybody could do it!" - selfquote
        "High speed never compensates for wrong direction!" - unknown

        Q 1 Reply Last reply
        0
        • R Roger Stoltz

          QuickDeveloper wrote:

          if i Start a thread and use WaitCommEvent then the Program gets stuck up in WriteFile.....I am not using Overlapped I/O

          If you're not using overlapped I/O, you can only issue one request at any given time to the driver. If you issue another it will block waiting for the previously issued request, which is exactly what happens in your case: ::WaitCommEvent() is waiting for something to happen before returning while blocking the ::WriteFile() call. If you're writing an application that is supposed to issue both read and write requests, you should only consider the overlapped alternative. Have a look at an example on overlapped I/O here[^].


          "It's supposed to be hard, otherwise anybody could do it!" - selfquote
          "High speed never compensates for wrong direction!" - unknown

          Q Offline
          Q Offline
          QuickDeveloper
          wrote on last edited by
          #4

          Thanks Roger ...i am using Overlapped I/O and it's Working Fine.

          "Every morning I go through Forbes list of 40 richest people in the world. If my name is not in there, I go to work..!!!"

          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