| Author |
Creating an event?
|
Peg Jennings
Greenhorn
Joined: Aug 11, 2008
Posts: 7
|
|
I'm trying to create an event that reads serial ports, and despite looking through countless websites describing how to make a custom event, I'm having trouble. Can someone describe to me how I would be able to do this? Thanks in advance -pegs
|
I'm bad.
|
 |
Sachin Joshi
Ranch Hand
Joined: Aug 06, 2008
Posts: 83
|
|
In my opinion creating a custom event would be nothing different from writing a polling thread which keeps listening to the port you are interested. And as soon as it finds some data on the port it fires the event. Fundamentally every event should have a code which triggers it and then all listeners would listen for that trigger to initiate. So I think serial port reader event would be a polling code which keeps watch over the serial port and as soon as you find an activity you should trigger it. By the way ...why do you want to write a event code for this?
|
Web Development Tips and Tutorials - By Sachin
|
 |
Peg Jennings
Greenhorn
Joined: Aug 11, 2008
Posts: 7
|
|
Thanks, that's what I was told by others of what you had to do. Honestly, threads aren't my strong point, so I was crossing my fingers that there was something else I could use. I have this device that I'm connecting to through a serial port. It sends out data, and then reads data. It's for my company. I'm an intern here, and my understanding of J2ME is limited...that's why I'm going around asking for help. Once again, thank you for replying!
|
 |
Steve Luke
Bartender
Joined: Jan 28, 2003
Posts: 3041
|
|
Threads can be scary to start with, but like anything else in Java, after using them a few times they get comfortable. I would suggest taking a long look at the java.util.concurrent package, it will help you a lot. For example, the ExecutorServices make generating and monitoring Threads and Thread Pools easy. The various implementations of BlockingQueue make good tools for event dispatching (your event dispatcher thread listening to the Serial Port put()s an event in the Queue, and the event consumer thread take()s from the BlockingQueue). [ August 11, 2008: Message edited by: Steve Luke ]
|
Steve
|
 |
Nitesh Kant
Bartender
Joined: Feb 25, 2007
Posts: 1638
|
|
Sachin: So I think serial port reader event would be a polling code which keeps watch over the serial port and as soon as you find an activity you should trigger it.
Java NIO provides support for selectors on sockets. They do the event publishing bit for you. I am not sure how much of it is a part of J2ME though.
|
apigee, a better way to API!
|
 |
 |
|
|
subject: Creating an event?
|
|
|