Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
gcreate edited this page Jan 29, 2015 · 1 revision

Send command to serial device using javascript,the string command wrote in java script file.

package testcase;

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

public class SimpleScript extends AbstractSerialCommand {
    @Override
    protected void setup() {
        // Setup serial
        setSerialPortConf(new SerialPortConf("COM15", 115200, 8, 1, 0));

        // Setup OutputStream
        addOutputStream(System.out);

        scriptFile = "./script/SimpleScript.js";
    }

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

}

./script/SimpleScript.js

SEND("ls\n", 1000);
SEND("ps\n", 1000, 2);

Output

Connecting to COM15 [speed:115200] [databit:8] [stopbit:1] [paritybit:0]
Connected!
ls
app
app-xxx
app-yyy
app-zzz
shell@root:/data # ps
USER     PID   PPID  VSIZE  RSS     WCHAN    PC         NAME
root      1     0     560    276   c00b89fc 0001fdd4 S /init
root      2     0     0      0     c00383a0 00000000 S thread
root      3     2     0      0     c003e3d0 00000000 S ksoft/0
root      7     2     0      0     c003e3d0 00000000 S test/0
shell@root:/data # Disconnected from COM15

Clone this wiki locally

Morty Proxy This is a proxified and sanitized view of the page, visit original site.