[Rxtx] RXTX rocks... little story.

Linuxguy123 linuxguy123 at gmail.com
Fri May 29 17:35:05 MDT 2009


I'm building this application whereby a user on the Internet needs to
control an RS232 device located somewhere in "the field". 

The application needs to have 2 parts, the remote part (ie client) that
runs wherever the user is (in cyberspace) and the local part (ie the
server) that runs on the server computer "the field" so that it can be
physically connected to the RS232 device. 

I develop in Eclipse.  

I brewed up the client using the visual editor and the SWT library.  

Pretty simple, except that I needed real time response to the GUI and I
used a socket connection to connect the client to the server
component.  

Solution: wrap the socket stuff in in a class, give it its own custom
event and run it as a separate thread.  Who cares if the socket blocks ?
It doesn't stop the GUI when you do it this way.  Even better, the
InputStream class has the available() method which returns immediately
and lets you know if its even worth doing a read.  Throw in some
thread.sleep() statements and the client GUI is responsive to the socket
and it runs great. 

The server component is a little bit more tricky.  It needs to be
responsive to both the client via a socket and the RS232 device, pretty
much in real time.  There are no masters in this system.  If something
happens to the device, it needs to send a message.  Ditto for the
client.  Thus the server needs to be able to receive messages from both
at any time. 

For reasons I won't discuss, initially I wrote the server component in
C.  I got the RS232 stuff running without too much trouble. Then I shut
it off.  Then I got the socket stuff running.  

This afternoon it came time to get them both running (serial and socket)
at the same time... not so nice.  It was doable, but it was ugly.

So, I started thinking.  Why don't I do the server in Java ?   At least
the socket stuff would be nicer.  Did I mention how much I love how Java
handles sockets compared to C/C++ ?  And I could reuse the message class
and socket code I have already written in Java on the client side.

What I didn't know is how I was going to do the RS232 stuff.  I've used
RXTX twice before for little projects.  Really simple polled stuff.  But
when I looked at the classes again today, there was the InputStream
class again, just like the socket setup I liked so much in Java.  So now
my server component design has 2 receiver classes, one for the socket
and another for the serial port, each with their own custom events.  

Its totally sweet.   The code went from a tangled mess of the fudged C
select() statement to each magically calling their event handler where
things are actually handled.

Plus... I really like programming in Java because of the OO classes,
etc.  And I don't have to rebuild anything for another platform if they
decide to use a Windows server instead of a Linux server.  

Its great that RXTX fits into the Java framework like it does.  RXTX
just made my project about 10x nicer than it would have otherwise been.

Kudos to those who developed and continue to work on RXTX.  I am truly
thankful !




More information about the Rxtx mailing list