permaculture playing cards
The moose likes I/O and Streams and the fly likes Serial port question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Serial port question" Watch "Serial port question" New topic

Serial port question

Pradeep Kumar T

Joined: Apr 14, 2007
Posts: 12
I have an app in which I need to communicate some data( an int array ) over a serial port connection. The way I need to do this is first send the first item of data and then wait for an echo from the device connected to the serial port and then send the subsequent items of data.
So each item of data will be sent as a response to an echo received from the device.
The way I am doing this now I have the serial port implement the SerialPortEventListener interface and use the serialevent() method in the interface to listen to serial events of type DATA_AVAILABLE. Once I receive this event, I write an item of data to the serial and then wait for the DATA_AVAILABLE event once again. This works fine sometimes, but a lot of the time the SerialEvent is either not trigerred or is somehow missed and the serialevent() method is simply not called. My program send the first item of data and just stops.
What exactly am I doing worng? The device that I am sending data to is supposed to be echoing back the data within 5ms. Should I have the data sending code operating in a separate thread or do I need to use Thread.sleep() to wait for the serial event to be generated. I have tried all of those things, but they do not seem to work.
Please advice!
Thanks a lot in advance!
I agree. Here's the link:
subject: Serial port question
It's not a secret anymore!