使用atinout库在Android中发送AT命令 [英] Sending AT Commands in Android Using atinout library

查看:130
本文介绍了使用atinout库在Android中发送AT命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如问题标题所建议的那样,我将在我的android应用程序中使用atinout库,以便能够将AT命令发送到设备的gsm调制解调器并获得响应.

As the question title suggest, I'm going to use atinout library in my android application to be able to send AT Commands to my device's gsm modem and get the response back.

我已经搜索过SO和其他博客,而我得到的最好的代码是这样的,它不会妨碍任何要写入输出的内容:

I've searched the SO and other blogs and the best code I got is something like this, which does not cauese anything to be written to output :

        Runtime r = Runtime.getRuntime();

        Process process = r.exec(new String[] {"su", "-c", "echo -n -e 'AT\r' > /dev/smd0"});

        BufferedReader in = new BufferedReader( new InputStreamReader(process.getInputStream()));

        String line = "";

        while ((line = in.readLine()) != null)
        {

           output+= line ;
        }



        tv.setText(output);

所以我主要关心的是:

1-如何将简单的AT指令(如AT Ok)发送到设备的gsm调制解调器并打印"回响应?

1- How to send a simple AT commmad (like AT Ok) to the device's gsm modem and "print" the response back ?

2-我不知道如何在android应用程序项目中使用atinout库,因为它是用C语言编写的.

2- I have no idea how to use the atinout library in an android application project, since it is written in C language.

顺便说一句:

我已经成功将我的Sony Xperia M Dual(C2005)手机植根并安装了SuperUser,因此可以满足此先决条件.

I have successfully rooted my Sony Xperia M Dual (C2005) phone and have SuperUser installed on it, so this prerequisite is met.

此外,我认为我需要有关Unix命令和串行通信的一些基础培训,我真的很喜欢学习任何需要的材料.

Also, I think I need some fundamental training on Unix commands and Serial communication and I really love to learn any needed material.

最后,我的期限很紧!因此,越简单,就越好!

Finally, I'm on a tight deadline ! So the more straightforward , the better!

P.S.我不想有人为我编写代码,我只需要准则.

感谢您的帮助.

推荐答案

步骤0.为Android编译 atinout 并安装它.为此,我没有经验,也无法提供任何帮助,除了需要使用适当的交叉编译器替换Makefile中的CC = gcc的一些常规准则之外.

Step 0. Compile atinout for android and install it. For this I have no experience and cannot give any help other than some general guidelines that you need to replace CC = gcc in the Makefile with an appropriate cross compiler.

步骤1.将要运行的所有AT命令写入文件input.txt(使用正常的\ n行尾,此处无需弄乱\ r).

Step 1. Write all the AT commands you want to run into a file input.txt (using normal '\n' line endings, there is no need to mess with '\r' here).

第2步.将exec行更改为

Step 2. Change the exec line to

Process process = r.exec(new String[] {"su", "-c",
                                      "atinout input.txt /dev/smd0 output.txt"});

等待过程完成执行(我认为是process.waitFor()).

Wait for the process to finish execution (process.waitFor() I think).

第3步.打开文件output.txt并从中读取输出,而不是process.getInputStream().

Step 3. Open the file output.txt and read the output from this instead of process.getInputStream().

这篇关于使用atinout库在Android中发送AT命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆