Installing RXTX for Serial Communication with Java
Java supports communication to serial ports, but not with its default installation. It requires an installation of an external library. Currently, two options exist for achieving serial communication:
Unfortunately, the current version of JavaComm does not support Windows, and only supports Solaris SPARC, Solaris x86, and Linux x86. Since I use none of those operating systems, this article will only discuss how to install RXTX in Windows.
UPDATE: 12 Sept 2011 – Thanks to a comment from Kurt Zoglmann, there are instructions on how to do this with a Mac! I never tried this myself because I don’t have a Mac, but the procedures stated there look good to me (see comments).
A 32 and 64 bit version of the library exists. For the 32 bit version the download on the RXTX download page will work (version 2.1-7 at the moment), but for 64 bit, that download won’t. 64 bit users need the version from Cloudhopper’s RXTX Page. The actual installation process does not differ between the two, only the downloaded files do.
To install the libraries (instructions from JControl):
- Copy rxtxSerial.dll to %JAVA_HOME%\bin, (%JAVA_HOME% is the folder where JRE is installed on your system; e.g. c:\Program Files\Java\j2re1.4.1_01)
- Copy RXTXcomm.jar to %JAVA_HOME%\lib\ext
Once installed, the IDE will need to know where to look for these installed files. Even though the files exist in the JRE directory, each project needs to know about these files. More information on this website.
In order to start coding with this library, import gnu.io.*. For more information about Java Serial Programming, look here.