Java and I/O thru a COM port

I’ve had a project dumped in my lap that was started in Java. I dream in C/C++…

Most of what I see I understand, but I’m kind of flying blind because I don’t yet know where to find the Java documentation to the level I’m accustomed to in C/C++.

What is the proper way to set up I/O through a serial COM port? The easiest way I know is to define the port as a file, and read or write using the old file procedures or the file stream stuff. There is also the primitive way by messing with buffers, pointers, and device registers.

How do I accomplish the same thing in Java? I assume that I can make use of the java.io package to do the file type of port manipulation.

I had a similar project dumped in my lap a while back. I wrote one end of the connection in C for an embedded instrument and the “receiving” end in Java. Sun has the Java Communications API but it’s only available for Solaris SPARC, Solaris x86, and Linux x86. Since I was writing for windows the alternative that I ended up using is RXTX. If I recall correctly, I essentially ended up writing a wrapper class for RXTX which opens the port, listens for incoming reads and places them in a BlockingQueue. It also has methods for writing to the port and closing it. My main app starts a seperate thread which waits for reads to enter the BlockingQueue and then does something with them.

Take a look at RXTX and see if it helps.

LarsenMTL

Thanks, Lars