Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Creating an event?

 
Peg Jennings
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Sachin Joshi
Ranch Hand
Posts: 83
Java Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Peg Jennings
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4181
21
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic