1

编辑:

我在 Java 中开发 SMS 应用程序以读取 SMS 。我将 AT 命令发送到 GSM 模式以发送 SMS,消息发送成功,但我没有从调制解调器得到任何响应。如果我通过超级终端发送 AT 命令,我得到响应。确切的问题是什么?

            InputStream inputStream;
            OutputStream out;


            this.inputStream = serialPort.getInputStream();
            this.out = serialPort.getOutputStream();
            out.write(("AT"+"\r").getBytes());
            try {
                Thread.sleep(1500);
            } catch (InterruptedException ex) {
                Logger.getLogger(MainClass.class.getName()).log(Level.SEVERE, null, ex);
            }
            out.write(("AT+CMGF=1"+"\r").getBytes());
            try {
                Thread.sleep(1500);
            } catch (InterruptedException ex) {
                Logger.getLogger(MainClass.class.getName()).log(Level.SEVERE, null, ex);
            }
            out.write(("AT+CMGS=\""+"+91xxxxxxxxxx"+"\""+"\r").getBytes());
            try {
                Thread.sleep(1500);
            } catch (InterruptedException ex) {
                Logger.getLogger(MainClass.class.getName()).log(Level.SEVERE, null, ex);
            }
            out.write(("TEST "+cntrlZ).getBytes());
            try {
                Thread.sleep(1500);
            } catch (InterruptedException ex) {
                Logger.getLogger(MainClass.class.getName()).log(Level.SEVERE, null, ex);
            }


 //Im using SerialPortEventListener to  read the input from modem
int a = inputStream.available();
System.out.println(inputStream.available() + "  BYTES AVAILABLE ");
inputStream.read(readBuffer, 0, a);

我也尝试在发送每个 AT 命令后阅读,但我没有得到任何来自调制解调器的响应。

4

2 回答 2

2

RXTX 中出现的问题

为串口设置流量控制后,它工作正常。

serialPort.setFlowControlMode(SerialPort.FLOWCONTROL_RTSCTS_IN |    SerialPort.FLOWCONTROL_RTSCTS_OUT);
于 2012-01-02T05:03:09.830 回答
0

请确保您已安装 SMSlib 所需的所有库,并且您的调制解调器在受支持的调制解调器列表中。不需要支持调制解调器,但可以立即消除兼容性问题。

此外,您应该验证您的调制解调器是否连接正确。您可以通过AT 命令直接对其执行一些操作。

于 2011-12-20T10:12:27.190 回答