Serial Port interrupt
-
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
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.
-
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.
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 useWaitForMultipleObjects
orWaitForSingleObject
... :-DCedric 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
-
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
-
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
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