我在java中开发短信应用阅读短信。我发送AT命令到GSM模式发送短信,消息发送成功,但我没有从调制解调器获得任何响应。如果我通过Hyperterminal发送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命令后也尝试读取,但是我没有得到任何来自调制解调器的响应。
答案 0 :(得分:2)
设置串口的流量控制后,工作正常。
serialPort.setFlowControlMode(SerialPort.FLOWCONTROL_RTSCTS_IN | SerialPort.FLOWCONTROL_RTSCTS_OUT);
答案 1 :(得分:0)
请确保您installed all libraries required by SMSlib并且您的调制解调器已在supported modems list。支持调制解调器不是必需的,但可以立即消除兼容性问题。
此外,您应该验证您的调制解调器是否正确连接。您可以通过AT commands直接对其执行某些操作。