使用Java和AT命令发送SMS

时间:2012-03-10 17:24:16

标签: java at-command

我有一个TC65调制解调器,我无法从任何地方获得帮助。我想问一下如何使用Java执行AT命令。一旦程序被编写,它将被上传到调制解调器并可以独立运行。我想用Java编写一个使用AT命令发送短信的代码。

有人能帮帮我吗?我将如何用Java编写这个:

number = + xxxxxxxxxx

AT + CMGS =数字/输入

(消息)/输入

我要把这个程序上传到我的GSM调制解调器,以便它在上电时发送短信。

package example.helloworld;

import javax.microedition.midlet.*;

/**
 * MIDlet with some simple text output
 */

public class HelloWorld extends MIDlet {

    /**
    * Default constructor
    */
    public HelloWorld() {
        System.out.println("Welcome");
    }

    /**
    * This is the main application entry point. Here we simply give some
    * text output and close the application immediately again.
    */
    public void startApp() throws MIDletStateChangeException {
        System.out.println("startApp");
        System.out.println("\nHello World\n");

        destroyApp(true);
    }

    /**
    * Called when the application has to be temporary paused.
    */
    public void pauseApp() {
        System.out.println("pauseApp()");
    }

    /**
    * Called when the application is destroyed. Here we must clean
    * up everything not handled by the garbage collector.
    * In this case there is nothing to clean.
    */
    public void destroyApp(boolean cond) {
        System.out.println("destroyApp(" + cond + ")");

        notifyDestroyed();    
    }
}

谢谢。

1 个答案:

答案 0 :(得分:0)

尝试类似的东西:

public void startApp() throws MIDletStateChangeException {
    System.out.println("startApp");

    String MyMessage = "Hello";

    ATCommand atc = new ATCommand(false); 
    atc.send("at+cmgf=1\r");
    atc.send("at+cmgs=1234567\r");
    atc.send(MyMessage + "\032\r");    // 32 = CTRL-Z

    destroyApp(true);
}

注意,这是TC65的东西。不便携。

需要导入:

import com.siemens.icm.io.ATCommand;