Sunday 22 April 2012

Serial Port Manipulation in Java

What we have today? Serial Port Manipulation in Java. Java seems to be popular for its high level user applications and Web application. But most of us, hobbyists use C for almost all our jobs to deal with hardwares.

   What do Java have for us. To be honest, Java is not good enough for ES programming or Driver development, because it is not meant to be. We have been struggling for getting precise delay for running a Servo motor by pulsing DTS and RTS. ( have a look at Serial Port Manipulation in C) Unfortunately the PC doesn't have the capability to provide precision.

   We then tried to use Tx and Rx terminals. That was just an experiment, where we really learnt quite a few things.The code that follows will count up to three. It can be tested by connecting two leds b/w DTS & GND  and RTS & GND respectively.

Hardware Section:


Refer to Serial Port Manipulation in C for RS232 pin-out....


We used an USB-Serial(DB9) converter as the interface.













RS232 male-female






Simple GUI to control the binary counter




Output in LED diplay




Coding:

We have used RXTXcomm library to access the Serial port. We need to add 3 jar files (core.jar,   RXTXcomm.jar and serial.jar ) to the build path as shown in the image below:





// CommExp Class -> the class that implements necessary methods for accessing SerialPort



// BinaryCounterFrame => This class is a frame with 2 buttons for inreasing and decreasing the count. Here an instance of CommExp class is created and the methods of the class are accessed through it.
     


The code could be better with counting logic, but we are presenting what Java can do for Port interfacing not Counting logic. If you are looking for basics of Port Manipulation, have look at Serial Port Manipulation in C.

Here's a low quality video we made:




1 comments:

Post a Comment

தங்களது கருத்துக்களை இங்கே வெளியிடவும்...

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More