我在Android的应用程序上工作。我希望保存来自AT命令的响应。 例如,当我执行此命令时:
Runtime r = Runtime.getRuntime();
Process process = r.exec(new String[] {"su", "-c", "echo -e 'AT\r' > /dev/smd0"});
我想保存
的响应AT
OK
我可以通过adb接口执行此命令来显示此响应:
# cat /dev/smd0
我在论坛上发现我应该制作这段代码:
Runtime r = Runtime.getRuntime();
Process process = r.exec(new String[] {COMMAND TO EXECUTE });
BufferedReader in = new BufferedReader(
new InputStreamReader(process.getInputStream()));
String line = null;
while ((line = in.readLine()) != null) {
System.out.println(line);
}
} catch (IOException e) {
e.printStackTrace();
}
例如,当我用“ls”替换COMMAND TO EXECUTE时,它工作正常。但当我用“cat / dev / smd0”代替时,它会在LogCat Invalide上显示给我:cat / dev / smd0
答案 0 :(得分:0)
好消息,我认为我正是您正在寻找的工具:atinout。它将读取AT命令列表,并提供从调制解调器到stdout(或文件)的响应。例如:
$ echo AT | atinout - /dev/ttyACM0 -
AT
OK
$
甚至
$ atinout - /dev/ttyACM0 - <<EOF
> AT+CSCS="UTF-8"
> AT+CPBS="ME"
> AT+CPBW=,"0123456789",129,"B. Endian"
> AT+CPBW=,"8967452301",129,"L. Endian"
> EOF
OK
OK
OK
OK
$
输入AT命令应该是以'\ n'结尾的普通文本行,atinout将在发送到调制解调器时用'\ r'终止命令。