Embedded Freaks..

November 3, 2008

Simple Hayes AT Command Parser

Filed under: java — Tags: — kunilkuda @ 1:33 pm

After a very long time, I finally have time to implement this idea: AT command parser. My first thought about AT command was how to separate the data from the OK/ERROR, and how to differentiate the URC from AT command.

So, here’s my idea (to be specific, the interface for the AT parser):


/**
* Send AT command to the serial port
*
* @param atCmd The AT command (ended with r or )
*/
void sendAtCmd(String atCmd) throws IOException;

/**
* Get the parser status
*
* @return true if parsing is done, false otherwise
*/
boolean isParsingDone();

/**
* Get the AT command's data
*
* @return Array of string consist of the AT command data
*/
String[] getAtCmdData();

/**
* Get the status of the executed AT command
*
* @return AtCmdStatus
*/
AtCmdStatus getAtCmdStatus();

The usage of the AT command parser will be something like this:


try {

    atParser.sendAtCmd("AT+CMGL=4r");

    // Wait until the parsing is done
    while (!atParser.isParsingDone()) {
        // Sleep for 1-s
        Thread.sleep(10);
    }

    if (atParser.getAtCmdStatus() == AtCmdStatus.OK) {
        for (String atCmdData : atParser.getAtCmdData()) {
            System.out.println("Data :" + atCmdData);
    }
    } else {
        System.out.println("AT Command Error");
    }
} catch (InterruptedException ex) {
} catch (IOException ex) {
    System.err.println(ex.getMessage());
    System.exit(1);
}

(more…)

Advertisements

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.

(more…)

August 29, 2008

RXTX Loopback Test Program(2)

Filed under: java — Tags: , — kunilkuda @ 5:56 pm

This second loopback program is to test RXTX’s serial event (data available event). Note that you need serial loopback to use this source code.
(more…)

Older Posts »