<?php
exec("mode com4: baud=115200 parity=n data=8 stop=1 to=off xon=off");
$handle = fopen("com4", "rw+b");
fwrite($handle, "lua /wo/a.lua\n");
while (($c = fgetc($handle)) !== false) {
echo $c;
}
fclose($handle);
import java.io.RandomAccessFile;
public class Serial {
public static void main(String[] args) throws Exception {
Runtime.getRuntime().exec("C:/Windows/System32/mode.com com4: baud=115200 parity=n data=8 stop=1 to=off xon=off");
RandomAccessFile f = new RandomAccessFile("com4", "rw");
f.writeBytes("lua /wo/a.lua\n");
int c;
while((c=f.read()) != -1){
System.out.print((char)c);
}
f.close();
}
}
比较遗憾的是,读取操作是阻塞的,程序读完串口返回的数据后并不会停止