1

我在 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 id 上显示给我:cat /dev/smd0

4

1 回答 1

1

好消息,我想我拥有您正在寻找的工具:atinout。它将读取 AT 命令列表并将调制解调器的响应提供给标准输出(或文件)。例子:

$ 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”结尾的命令。

于 2013-09-07T21:13:48.650 回答