Java Comm Serial API How-To for Linux

Using RXTX and JCL

Preface

Special thanks to Trent Jarvi and Kevin Hester for putting together RXTX and JCL.  These two gentlemen have done an excellent job of porting the original Sun Java Comm API to the Linux OS.  However, with all due respect, and not to be insulting, their installation documentation leaves much to be desired.  This is the primary reason I have chosen to put this document together.

Getting Started

Before insalling the Comm API on your Linux box, be sure you have a JSDK installed.  You can obtain a JSDK for your version of linux from Blackdown.org or Sun Microsystems.  To install and configure Java in Linux, please follow the instructions provided here.

For the purposes of this paper, it will be assumed that you have installed a JSDK and it is located in:

/usr/java/j2sdk1.4.0/

And java is then located in:

/usr/java/j2sdk1.4.0/bin/

If your setup is different, please adjust accordingly. 

Installing RXTX

First, obtain the RXTX bins package from:

http://www.linux.org.uk/~taj/rxtx-bins.1.tar.gz
                        (In IE, right click and "Save Target As")

Decompress and Untar this package:

/bin/gzip --decompress rxtx-bins.1.tar.gz

/bin/tar xf rxtx-bins.1.tar

At this point, you'll have an rxtx-bins.1 directory.  Next, you'll need to copy the shared objects into your java installation:

cp rxtx-bins.1/1.4/i386-pc-linux/libParallel.so /usr/java/j2sdk1.4.0/jre/lib/i386/

cp rxtx-bins.1/1.4/i386-pc-linux/libSerial.so /usr/java/j2sdk1.4.0/jre/lib/i386/

If you are installing on an architecture other than an x86, you'll need to adjust both the /i386-pc-linux/ and the /i386/ accordingly.

Next, you'll need to install the jcl.jar file:

cp rxtx-bins.1/1.4/jcl.jar /usr/java/j2sdk1.4.0/jre/lib/ext/

At this point, the RXTX installation is complete.

Installing Comm

The final step to getting the Java Comm API working under Linux, is to install the Comm API itself.  At this point, you have all of the necessary kernel-level drivers installed.  Because Linux is a form of Unix, the authors of RXTX and JCL have wisely decided to reuse sun's solaris (unix) comm library.  At this point, you must download and install this library:

http://java.sun.com/products/javacomm/  

Make sure you choose the Solaris/SparcTM version.  Next, you must Decompress and Untar this package:

/bin/gzip --decompress javax_comm-2_0_2-solsparc.tar.Z

/bin/tar xf javax_comm-2_0_2-solsparc.tar

Next, you'll need to install the comm.jar file:

cp commapi/comm.jar /usr/java/j2sdk1.4.0/jre/lib/ext/

At this point, we are almost finished.  We just need to create the properties file that the Comm API will use to load the drivers (.so files).  To create this file, type the following command:

/bin/echo Driver=gnu.io.RXTXCommDriver > /usr/java/j2sdk1.4.0/jre/lib/javax.comm.properties

Congratulations!  You have installed the Linux Comm API.

Tips

While windows uses COM and LPT designators for port identifiers, Linux is a bit different.  Use the following table to identify your ports:

Port Windows port identifier What you use in Linux
Serial Port 1 COM1 /dev/ttyS0
Serial Port 2 COM2 /dev/ttyS1
Parallel Port 1 LPT1 /dev/lp0

Troubleshooting

Several people have emailed me and reported that they get the following error:

Exception in thread "main" java.lang.VerifyError: (class:
gnu/io/RXTXPort$SerialOutputStream, method: write signature: ([BII)V) Illegal
use of nonvirtual function call
at gnu.io.RXTXPort.<init>(RXTXPort.java)
at gnu.io.RXTXCommDriver.getCommPort(RXTXCommDriver.java)
at javax.comm.CommPortIdentifier.open(CommPortIdentifier.java:547)


I personally have not experienced this problem, but if you encounter this error, you can work around it by adding -noverify to your command line:

java -classpath your classpath -noverify your class

Also, it has been suggested that recompiling the jcl with the java compiler you have chosen will resolve this issue.  As I have never experienced this verification problem, I have no way to test this.  It should also be noted that the purpose of this paper is to be a quick and easy way to get serial and parallel port access in Java on Linux.  Most of the instructions on this page as well as the VerifyError are irrelevant if you chose to download the RXTX source and do a manual compile and installation.

Other Resources

  1. Trent Jarvi's RXTX Homepage.  (http://www.rxtx.org)
  2. Kevin Hester's JCL Homepage.  (http://www.geeksville.com/~kevinh/linuxcomm.html)
  3. Sun Microsystem's Java Comm FAQ.  (http://java.sun.com/products/javacomm/reference/faqs/index.html)

Reader Comments:

05/17/2016 11:33 PM - Jared wrote:
Will I have to work shifts? <a href=" #infection ">taxpayer funded viagra viagra</a> "I think Eli would be the first to say that he's not the way we want him to be," said Coughlin, whose biggest concern was a running game that gained 1.2 yards a carry. "Somehow, we've got to stop the interceptions. You're looking at a two-edged sword. You've got to put yourself in a position where you are throwing it and not running it."

05/17/2016 3:59 PM - Alex wrote:
Where's the nearest cash machine? <a href=" ">generic viagra and cialis from india</a> &ldquo;I've got some thoughts about how we can move forward in the remainder of the year and stay focused on the job at hand, because there is a lot of work ahead of us, including our need to earn back the trust of the American people that has been lost over the last few weeks,&rdquo; he said. &ldquo;And we can begin to do that by addressing the real issues that they care about.&rdquo;

05/17/2016 3:59 PM - Elias wrote:
Where do you live? <a href=" ">gzvxay viagra online</a> ** Hedge fund Jana Partners LLC disclosed in a regulatoryfiling on Tuesday that it had acquired a 6.2 percent stake ingrocery chain Safeway Inc. Jana said it has held talkswith Safeway management about reviewing strategic alternativesfor the Pleasanton, California-based company and that its sharesare undervalued.

05/17/2016 8:07 AM - Jarred wrote:
Do you know what extension he's on? <a href=" ">iscoun cialis fedex</a> BEIJING/HONG KONG - China reiterated its opposition on Thursday to a European Union plan to limit airline carbon dioxide emissions and called for talks to resolve the issue a day after its major airlines refused to pay any carbon costs under the new law.

04/12/2016 1:53 PM - Brent wrote:
This is your employment contract brand name levitra sales brand levitra on sale But there will be no shocking benching of the two-time Super Bowl MVP this season, and Giants coach Tom Coughlin made that clear on Wednesday during his conference call with Minnesota Vikings reporters.

04/12/2016 1:53 PM - Alonso wrote:
It's OK ommentar von natural viagra am 16.1.2012 13 Xu said she was not aware of any formal investigation intothe sector. While the association's survey did not ask questionsabout corruption, Xu said regulators would likely focus on suchpractices at some stage.

04/12/2016 1:53 PM - Angelina wrote:
One moment, please buy levitra in australia there are abnormalities. A few days earlier ?????? on Aug. 30 ?????? the free-wheeling fiend was seen rolling through Nobu 57 on W. 57th St. near Sixth Ave. at 11:30 p.m., where he police say he grabbed a pricey Coach purse a 34-year-old diner had placed under the bar.

04/12/2016 7:48 AM - Dorian wrote:
Enter your PIN costco pharmacy in tempe At the same time, a chilling message delivered by Beijing&rsquo;s top official for economic crime, Gao Feng, left the rest of the industry in no doubt that they too could face the same treatment.

04/12/2016 7:48 AM - Pablo wrote:
I'd like , please gohou drugs online AstraZeneca is this country??????s second biggest drugs manufacturer with 8,000 of its 61,000 global workforce employed in the UK at sites such as Alderley Park, Avonmouth near Bristol, Brixham in Devon, and London as well as with affiliated companies in Liverpool, Cambridge and Luton.

04/12/2016 4:09 AM - Domenic wrote:
I've just graduated pharmacy buyer wage Although following the nutritional recommendations of the American Academy of Pediatrics and the Institute of Medicine does decrease the risk of kids becoming overweight and obese, "parents cannot now do anything to prevent this disease in their children, and it's important not to worry them before we really know."

04/12/2016 2:20 AM - Milford wrote:
Could I have a statement, please? alamo discount pharmacy alamo ga Speaking to the BBC from her adopted home in Montreal, Canada, where she sought refuge almost three decades ago, Carmen talks slowly, carefully recounting each detail of the events that scarred her mentally and physically.

04/12/2016 12:30 AM - Santiago wrote:
My battery's about to run out best drugstore oil control primer The cash-strapped ex-Soviet republic's ability to pay debtshas aroused concern among rating agencies as it prepares nextmonth to sign association and free trade agreements with theEuropean Union despite threats from traditional partner Russia.

04/12/2016 12:29 AM - Rocco wrote:
Could you tell me the dialing code for ? rx drugs.com For the neocons, largely sidelined these last few years, Cheney is a tantalising prospect who can be seen regularly on Fox News bashing Obama for his lily-livered, apologist foreign policy while hammering at the Republicans to get over their 2012 defeat, and on to the offensive.

04/11/2016 5:37 PM - Desmond wrote:
We've got a joint account best drugstore pencil eyeliner uk &#8220;In today&#8217;s era, young dudes are getting better and more prepared to come up to the big leagues,&#8221; said Orioles teammate Adam Jones, an All-Star himself. &#8220;It&#8217;s just an improvement in the game. These young dudes are phenoms, and he&#8217;s put his name up there.

04/11/2016 1:17 PM - Camila wrote:
Sorry, I'm busy at the moment kroger pharmacy coupons new prescriptions 2013 "While efforts to block the bonuses are welcome news, actions speak louder than words," said Sen. Orrin Hatch, R-Utah, the top Republican on the Senate Finance Committee. "In my view, the IRS should not be paying out bonuses especially now when it's under multiple congressional investigations for targeting conservative groups."

04/11/2016 11:21 AM - Roman wrote:
I'd like to pay this cheque in, please why are american prescription drugs so expensive The indictments are the result of an 18-month investigation by the FBI,the Attorney General's Office, the U.S. Air Force, Arizona NationalGuard and the Air National Guard, the release from Horne said.

04/11/2016 9:54 AM - Pierre wrote:
Who would I report to? can i buy needles at a pharmacy Those drawbacks won??????t stop me from returning. With high style, chef Lyew??????s skill and generosity are creating something new in this changing part of Brooklyn. And that??????s something to celebrate ?????? preferably in a booth at Milk River.

04/11/2016 9:54 AM - Benton wrote:
Have you got a telephone directory? what happens if you mail prescription drugs It has happened repeatedly in modern China, where the 1989 Tiananmen crackdown remains a largely forbidden topic, and where even the half-century-old historical realities of the "Great Leap Forward" ?????? Mao Zedong's disastrous policies that led to widespread famine and the deaths of tens of millions in the late 1950s and early 1960s ?????? have come into the open only recently.

04/11/2016 9:53 AM - Columbus wrote:
Photography generic drugs in quebec Residents say they complained about the smell months ago but were told by city officials that skunks weren't being killed inside the building. Later, they were told only a few skunks were killed there by lethal injection.

04/11/2016 8:55 AM - Emma wrote:
The line's engaged discount drug store atherton But the market for remote controlled vehicles is evolving from the sometimes multi-tonne craft that patrol the skies over Afghanistan or Yemen, carrying out reconnaissance and targeted strikes, to tiny robots that police and even film companies can use.

04/11/2016 8:55 AM - Vaughn wrote:
On another call singapore pharmacy prescription &#8220;And I kept saying to my wife: breathe, breathe, don&#8217;t stop breathing. One, two, three, one, two, three&#8230; and it went on like that until we got to the hospital. Then for five hours I had no idea where she was. The only thing I could think was that she was being operated on.&#8221;

04/11/2016 8:55 AM - Hipolito wrote:
What's the last date I can post this to to arrive in time for Christmas? generics pharmacy lucena hiring This week, President Obama denounced Republicans in Congress who were trying, he said, to destroy Obamacare by mucking up its implementation. You've got to admire the president. A man of many gifts &ndash; intellectual, rhetorical &ndash; but none of his gifts matches that of passing blame.????

04/11/2016 6:45 AM - Vicente wrote:
I live in London teenage overdose on prescription drugs The source, who asked not to be identified, said officials refused to divulge details of the plans because they do not want to suggest to investors and Republican Congress members that the U.S. government can muddle through if the debt limit is not raised. Officials insisted there was no way to avoid an eventual default if the debt limit is not raised.

04/06/2016 2:35 AM - editor photo wrote:
c7aeWn Right here is the right webpage for anybody who wishes to understand this topic.

12/28/2014 1:44 AM - David wrote:
So, I've been playing with Java and RXTX.I was able to get my new sotrwafe to transmit out of the USB-serial converter last night. It seems easy enough to handle serial communications. One of my worries was integrating RXTX into my application, but that seemed to go smoothly enough once I figured out how to assign paths etc.The class seems to duplicate javax.comm, so any regular serial call will also just plain work. Pretty neat. This means existing reference-material on javax.comm will probably apply to RXTX.I hope java handles the data as cleanly and transparently as C++ did. One concern relates to buffering, etc.RXTX does have support for Linux (was specifically designed to support this first!), Mac OS X, and Windows. You have to use the appropriate .DLL or libxxxx.so file depending on platform.I'll be interested to know how truly portable my stuff is, although admittedly there might not be much demand for it. I think portability is a noble goal though for open source sotrwafe.I've considered Real Basic for this task, mainly for its Rapid Application, but the costs are too prohibitive. I've used RB before, and it is pretty decent.

09/15/2014 5:16 PM - AA wrote:
The websites are not available anymore! I need to upgrade a java application, which has been originally using RXTX, but now with windows 8 and 64 bit system it cannot write through the port, although it can recognize it as a read port. Does any one have any idea how to fix it?we are using a USB-serial converter.

07/01/2014 6:10 AM - Jason wrote:
good article

06/09/2014 2:57 AM - Pharma908 wrote:
Very nice site!

05/31/2014 2:36 PM - Johnk441 wrote:
Hi! Someone in my Myspace group shared this website with us so I came to look it over. I'm definitely loving the information. I'm bookmarking and will be tweeting this to my followers! Great blog and terrific design and style. gafcaddeaaka

03/31/2013 3:31 PM - Jub16 wrote:
I don't know rxtx. ..I want to use in my project. .tell me from where to get started for beginners.

10/10/2012 11:38 AM - amjad wrote:
hi ,i use the javax.comm packet and run correctly, the question is how make my file to be .jar file, i use the old way like i write the mianfest.txt file and also don't work

10/08/2012 10:22 PM - Conny wrote:
Smart thinking - a cleevr way of looking at it.

07/14/2012 10:19 AM - Tom wrote:
<b>Nice article</b>

06/19/2012 4:24 PM - Camilo Duque wrote:
Hi, excellent content. I have a simple question: I'm using a laptop without rs232 serial port, instead I'm programming with rxtx through a USB port, so I need to know if the internal manage of communication is made by the kernel or rxtx driver or JVM? and I wonder if the real transmission occurs in RS232 or in USB protocol? Thanks a lot and congrats... Camilo

02/09/2012 11:16 AM - Alex wrote:
You saved me....

11/22/2011 11:17 PM - Nelson wrote:
Yap Nice job

11/19/2011 2:23 PM - Sam Ong wrote:
I have a Nomad Trimble with Windows Mobile. I am trying to connect it through the serial port. Can I use Linux on it as well?

11/10/2011 5:51 AM - nuwan wrote:
let me know how to download javax.comm api suitable for linux

09/15/2011 2:53 PM - greg wrote:
I get it now. You can't put any html in this comment system or it rejects the email without an error. The link to the comm code does not have a download. Seems that Wade needs to edit the page so that it reflects this? Maybe a link to where the code is now?

09/15/2011 2:50 PM - greg wrote:
Is this comment system broke too? I am trying to find the javax.comm api code. The link provided does not have a download. Does anyone know where I can get this download? The page was updated 9 days ago and I figure that oracle broke it.

06/11/2011 3:06 PM - Z.K. wrote:
Just curious, but if you are using Linux why not download the Linux version of the Java Comm API.

01/03/2011 11:42 PM - karan nage wrote:
i got problem at the time of implementation javax.comm for parallel port error is javax.comm class path were not found if any body hava solution plz post me lioninfotechhr@gmail.com contact no 9637624887

01/01/2011 8:13 AM - mitra wrote:
ops, I did the instruction but still same error like before while im sure about classpath, error: Exception in thread "main" java.lang.NoClassDefFoundError: net/tinyos/sf/SerialForwarder Caused by: java.lang.ClassNotFoundException: net.tinyos.sf.SerialForwarder at java.net.URLClassLoader$1.run(URLClassLoader.java:202) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:190) at java.lang.ClassLoader.loadClass(ClassLoader.java:307) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:248) Could not find the main class: net.tinyos.sf.SerialForwarder. Program will exit. any help? thanks in advance.

12/13/2010 7:02 AM - bart wrote:
hi. i did almost the same in windows and it seems to work fine. the clue is: /bin/echo Driver=gnu.io.RXTXCommDriver > /usr/java/j2sdk1.4.0/jre/lib/javax.comm.properties... this file is in ProgramFiles/Java/jre6/lib.. Project configured with rxtx and javax.comm as UserLibraries and added to buildPath in eclipse works fine

10/01/2010 8:16 AM - Valerione wrote:
hello, I followed the guide! I tried to run a little code to test the proper operation, but gives me this error: xception in thread "main" java.lang.UnsatisfiedLinkError: com.sun.comm.SunrayInfo.isSessionActive()Z at com.sun.comm.SunrayInfo.isSessionActive(Native Method) at com.sun.comm.Portmapping.registerCommPorts(Portmapping.java:155) at com.sun.comm.Portmapping.refreshPortDatabase(Portmapping.java:100) at javax.comm.CommPortIdentifier.<clinit>(CommPortIdentifier.java:138) at Coordinator.Main.main(Main.java:15) Java Result: 1

10/31/2009 2:00 PM - SchneiderIS wrote:
Pardon the blond moment. The permissions to write to the "lib" folder were needed. Then the file could be created.

10/31/2009 1:50 PM - SchneiderIS wrote:
In running your instructions I have run into a snag with the very last step for the Sun comm driver. When I try running: sudo /bin/echo Driver=gnu.io.RXTXCommDriver > /usr/lib/jvm/java-6-sun/jre/lib/javax.comm.properties I get the following error: bash: /usr/lib/jvm/java-6-sun/jre/lib/javax.comm.properties: Permission denied Looking in the "lib" folder there is no "javax.comm.properties" and when I search the drive for the file it does not exist. I have the latest download from Sun which is version 3 for comm and my java version is as follows: java version "1.6.0_16" Java(TM) SE Runtime Environment (build 1.6.0_16-b01) Java HotSpot(TM) Client VM (build 14.2-b01, mixed mode, sharing) Do you have any suggestions as to what needs to be changed for this final command to register the driver?

05/10/2009 8:01 PM - Rzhbkqcf wrote:
Excellent work, Nice Design

11/19/2008 4:38 AM - ng_agi wrote:
it would be great if you have something similar for windows. there are a couple of words in wiki about rxtx win32 installation under eclipse, but i am still fighting with my installation...

11/18/2008 9:02 AM - MRI wrote:
the www.rxtx.org site wiki, and most of the links no longer lead to active sites. Is there a place to get the source for rxtx. I tried accessing the cvs site and that as well no longer functions. Advice?

08/21/2008 3:10 AM - Rajan wrote:
Well it works on linux. I need it to make it work on MAC OS(10.4). Will try to email you with some details, if you could provide any advise and help, would be appreciated.

08/07/2008 8:52 AM - WW wrote:
Point well taken, I've listened, and I've changed the site's text color :)

08/07/2008 2:54 AM - Claus wrote:
This website is hard to read, due to lightgray text on white background. Please, change this.

Post a Comment:

Your Name:
Your Comment:

Copyright 2002-2016 Wade Wassenberg
Last Modified: March 24, 2004. 
If you have questions, comments, or if you find any part of this document to be inaccurate or incorrect, please submit your feedback to webmaster@wass.homelinux.net.