Embedded Freaks..

October 8, 2008

RXTX Serial Port Helper

Filed under: java — Tags: , , — kunilkuda @ 2:06 pm

Well, the conclusion of the RXTX posts in this blog may have been written in this code sample. It will help you to establish serial port operations (connect / disconnect / add data available listener / get serial port’s OutputStream/InputStream).

I put this on the blog, because I keep moving around project to project. Hence, it always take a lot of time to find it from one of the project folders. At least, if I keep it online, google will help me to find it when I need it.


August 13, 2008

Reading from serial port (using rxtx)

Filed under: java — Tags: , , — kunilkuda @ 9:29 am

Once you’ve got the serial InputStream, reading would be easy. Here’s an example of code to read the serial port using InputStream:

 * Buffer to hold the reading
private byte[] readBuffer = new byte[400];

private void readSerial() {
    try {
        int availableBytes = inStream.available();
        if (availableBytes > 0) {
            // Read the serial port
            inStream.read(readBuffer, 0, availableBytes);

            // Print it out
                    new String(readBuffer, 0, availableBytes));
    } catch (IOException e) {

But the real problem comes from the place where you should place the code.

August 12, 2008

Serial port event in rxtx

Filed under: java — Tags: , , — kunilkuda @ 6:26 am

So, what do you expect from serial port event ? Most probably is the notification whether you’ve got new data in the buffer or not. But for some people (like me) who deals with real modem (I use GSM modem for server communication), we need RTS/CTS notification as well. Otherwise, we will flood the modem with data, since most PCs are faster than modem.

I’ve tested some of rxtx serial port events in Linux, and here’s some report that you might be interested.

Older Posts »