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. Serial Port interrupt

Serial Port interrupt

Scheduled Pinned Locked Moved C / C++ / MFC
helplounge
5 Posts 5 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.
  • A Offline
    A Offline
    aasstt
    wrote on last edited by
    #1

    My application is reading data from serial port. But the data may arrive at any random time. So i want to interrupt the application when data arrives on the serial port. Can anybody suggest me some solution to this problem. aasstt

    C K T 3 Replies Last reply
    0
    • A aasstt

      My application is reading data from serial port. But the data may arrive at any random time. So i want to interrupt the application when data arrives on the serial port. Can anybody suggest me some solution to this problem. aasstt

      C Offline
      C Offline
      Cedric Moonen
      wrote on last edited by
      #2

      You won't be able to use hardware interruptions in your program (and it's bad design also ;P). A better solution is in general to spawn a thread that will poll the serial port for data. A good design for doing that is starting this thread in a separate class that will send a message to your application when data is available (custom message). This may sound 'complicated' but if you don't want to freeze your GUI, it is the best way of doing that.

      M 1 Reply Last reply
      0
      • C Cedric Moonen

        You won't be able to use hardware interruptions in your program (and it's bad design also ;P). A better solution is in general to spawn a thread that will poll the serial port for data. A good design for doing that is starting this thread in a separate class that will send a message to your application when data is available (custom message). This may sound 'complicated' but if you don't want to freeze your GUI, it is the best way of doing that.

        M Offline
        M Offline
        Maxwell Chen
        wrote on last edited by
        #3

        Cedric Moonen wrote:

        to spawn a thread that will poll the serial port for data.

        From my experience in the past, polling eats processor resource even though we have added something in the loop in the thread like Sleep(1). Personally I prefer to feed an event to the serial port API, and use WaitForMultipleObjects or WaitForSingleObject ... :-D

        Cedric Moonen wrote:

        This may sound 'complicated' but if you don't want to freeze your GUI, it is the best way of doing that.

        Yes this is so true! Basically all those communication related applications have to be designed in multi-threading to prevent from GUI frozen.


        Maxwell Chen

        1 Reply Last reply
        0
        • A aasstt

          My application is reading data from serial port. But the data may arrive at any random time. So i want to interrupt the application when data arrives on the serial port. Can anybody suggest me some solution to this problem. aasstt

          K Offline
          K Offline
          kakan
          wrote on last edited by
          #4

          Use Overlapped I/O and WaitForSingleObject

          1 Reply Last reply
          0
          • A aasstt

            My application is reading data from serial port. But the data may arrive at any random time. So i want to interrupt the application when data arrives on the serial port. Can anybody suggest me some solution to this problem. aasstt

            T Offline
            T Offline
            ThatsAlok
            wrote on last edited by
            #5

            http://www.codeproject.com/system/simpleserialcomm.asp http://www.codeproject.com/system/cserialport.asp

            "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

            cheers, Alok Gupta VC Forum Q&A :- I/ IV

            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