This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes Interruptions from the serial port Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Interruptions from the serial port" Watch "Interruptions from the serial port" New topic
Author

Interruptions from the serial port

Carlos PQ
Greenhorn

Joined: May 07, 2003
Posts: 8
Hello!
Im programming an app in Java with a Modem in the serial port.
I already know how to make the app read the messages that the modem sends. Ive also created a thread that after some time, it wakes up and looks if there are messages in the serial port.
BUT, I would be interested in generate an interruption (or an exception, i dont know which is the best choice) that would wake my thread up when there is an incomming message in the serial port from the modem.
That is, the app is asleep (there is no CPU time), and when the Modem sends a message to the serial port, the app would wake up automatically (the interruption will execute a method in the app, or would wake up a thread... i dont know)
Somebody could help me???
Really thank you!
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi Carlos,
Welcome to JavaRanch. This sounds like a job for the Observer pattern. If you have your class that reads the modem extend Observable and the Runnable (thread) that checks for messages implement Observable, then you can have the thread wait() until a message becomes available. For example:



[ June 12, 2003: Message edited by: Michael Morris ]

Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Interruptions from the serial port
 
Similar Threads
Using SMS for data push -- how to send an SMS message from the server
JTextArea used as a modem terminal
Program architecture question
Interruptions from the serial port
Sending Fax thro java application