【问题标题】:Sending SMS using Java and AT Commands使用 Java 和 AT 命令发送 SMS
【发布时间】:2012-03-10 17:24:16
【问题描述】:

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

谁能帮帮我?我将如何用 Java 编写这个:

数字 = +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();    
    }
}

谢谢。

【问题讨论】:

  • 定义“用Java编写”,你是指String还是流?还是完全不同的东西?另外,请向我们展示您已经尝试过的内容。
  • 我在哪里添加它以及如何告诉它执行 AT 命令?任何帮助将不胜感激。

标签: java at-command


【解决方案1】:

试试这样的:

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;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-06
    • 1970-01-01
    相关资源
    最近更新 更多