Thursday, June 28, 2012

Install javax.comm(or RXTX) in Eclipse



Hello Everyone...,
This post is about Configuring Eclipse IDE to work with javax.comm Api , so that we can read or write from Serial Port [RS232].


We can do this by using any one api :
  • Java Communication Api (javax.comm) or
  • RXTX ( gnu.io)
both are same RXTX is a 3rd party API the only difference is we need to use
import gnu.io.*;  instead of
javax.comm.*;  Rest everything is same.

Here I'm gonna use RXTX API.
You can Download it from here : http://rxtx.qbang.org/wiki/index.php/Download

Configuring both the api's require same steps., we just add the jar files to our Eclipse Project Build path.
[ IF YOU ARE NOT AWARE OF , HOW TO ADD JAR FILE TO ECLIPSE  PROJECT
SEE MY OTHER POST http://kishor15389.blogspot.in/2012/06/adding-jar-files-to-your-project-in.html ]

And the trick part is adding Native Libraries like DLL(on Windows ) or SO(on Linux).
So Lets get Started.

  1. First Download the RXTX api from above mentioned Link.
  2. Extract to any Location.
  3. Right Click on you Eclipse Project (in Package Explorer on Left Panel).
  4. Select "Build Path".
  5. Click "Configure Build Path" .( A new Window will Open)
  6. Select "Add External Jars" under "Libraries" tab.(It will open a File Chooser)
  7. Select "RXTXcomm.jar".[Now our Jar File is Added and we need to attach the Native Library File to our Jar File(RXTXcomm.jar).]
     
  8. Under "Libraries" Expand the JAR file "RXTXcomm.jar" (using '+' icon at start of RXTXcomm.jar name)
  9. Select the "Native Library Location"
  10. Click "Edit" (It will open new Window)
  11. Click "External Folder" button ( A File Chooser will open )
  12. Now browse to the downloaded RXTX api folder open the appropriate OS folder and select the folder where native library files are located. [ Example on Windows OS ..\rxtx-2.1-7-bins-r2\Windows\i368-mingw32\ is the location of DLL files. ]
  13. Click OK and everything is done.
Remember to change or use import gnu.io.*; instead of javax.comm.*; If you are using RXTX API.

You can see the following video, Demonstrated the all of the above steps.







PLANT A TREE
... " You have no idea how happy you'll feel, standing in its Shade when it grows up "....