Sending AT Commands in Android Using atinout library

随声附和 提交于 2019-12-01 10:41:50

问题


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.

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);

So my main concerns are :

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

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

By the way :

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

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. I don't want someone to write the code for me, I just need the guidelines.

Thanks for your help.


回答1:


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.

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).

Step 2. Change the exec line to

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

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

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



来源:https://stackoverflow.com/questions/25058597/sending-at-commands-in-android-using-atinout-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!