Skip to content
gcreate edited this page Jan 29, 2015 · 1 revision

Using console Send string command to serial port device and receive result from serial port device

package testcase;

import serialportutil.AbstractSerialCommand;
import serialportutil.CommandBatch;
import serialportutil.SerialPortConf;

/**
 * Simple console sample<BR>
 * System console as input and output
 * 
 */
public class SimpleConsole extends AbstractSerialCommand {
    @Override
    protected void setup() {
        // Setup serial
        setSerialPortConf(new SerialPortConf("COM15", 115200, 8, 1, 0));

        // Set output with time stamp
        setSerialPortTimePrefix(true);

        // System out as output
        addOutputStream(System.out);
    }

    @Override
    protected void processCommand() throws Exception {
        // Add console input support
        addConsoleInputSupport();
    }

    public static void main(String[] args) {
        CommandBatch.addClazz(SimpleConsole.class);
        CommandBatch.go();
    }
}

Output

Start>>class testcase.SimpleConsole
Connecting to COM15 [speed:115200] [databit:8] [stopbit:1] [paritybit:0]
Connected!
ls
ls
2014-05-29 13:50:46 app
2014-05-29 13:50:46 app-asec
2014-05-29 13:50:46 app-lib
2014-05-29 13:50:46 app-private
2014-05-29 13:50:55 shell@root:/data # ps
ps
2014-05-29 13:50:56 USER     PID   PPID  VSIZE  RSS     WCHAN    PC         NAME
2014-05-29 13:50:57 shell     759   1     968    508   c002c9c0 b6f8e378 S /system/bin/sh
2014-05-29 13:50:57 root      783   1     328808 43940 ffffffff b6f2468c S xxxxx
2014-05-29 13:50:57 root      853   763   940    452   c00b89fc b6f2bd34 S yyyyy
2014-05-29 13:50:57 shell@root:/data # 
2014-05-29 13:50:57 shell@root:/data # 
Clone this wiki locally