Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/348.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
再次发送sms时At命令显示忙碌(java) import javax.comm.*; 导入java.io.*; 导入java.util.*; 公共类短信{ 公共同步静态字符串main1(字符串arr){ char cntrlZ=(char)26; InputStream输入=null; OutputStream输出=null; SerialPort SerialPort=null; 试一试{ CommPortIdentifier portId=CommPortIdentifier.getPortIdentifier(“COM3”); serialPort=(serialPort)portId.open(“simpleradapp1”,2000); //System.out.println(“sdiosdfsf”); 字符串f=null;int n; input=serialPort.getInputStream(); output=serialPort.getOutputStream(); 线程读取线程; serialPort.notifyOnDataAvailable(true); 试一试{ serialPort.setSerialPortParams(9600,serialPort.DATABITS_8, SerialPort.STOPBITS_1, 串行端口。奇偶校验(无); }捕获(不支持的操作异常){} output.write((((“ATZ\r\natH\r\n+CMGW:0\r\n+CMGW:1\r\n”).getBytes(); output.flush();Thread.sleep(200); output.write((“ath0\r\n”).getBytes(); output.flush();Thread.sleep(200); output.write(((“AT+CMGF=1\r\n”).getBytes(); output.flush();Thread.sleep(200); output.write(((“AT+CMGS=\“09629993650\”\r\n+CMGW:20\r\n”).getBytes(); output.write(((“helloopsss445545inoyouthere?”).getBytes()); output.write((“\032”).getBytes(); output.flush(); 《睡眠》(2000年); 字节[]读缓冲区=新字节[120]; 试一试{ while(input.available()>0){ int numBytes=input.read(readBuffer); } input.close(); output.close(); serialPort.removeEventListener(); serialPort.sendBreak(1000); serialPort.getInputStream().close(); serialPort.getOutputStream().close(); 如果(serialPort!=null) System.out.print(“端口不为空!!!”; //serialPort.closeport(); 如果(serialPort!=null) System.out.print(“端口不为空!!!”; System.out.print(新字符串(readBuffer)); 返回(新字符串(readBuffer)); }捕获(IOE){} output.flush(); }捕获(无此端口例外){ System.out.println(“添加侦听器中的异常”+e); }捕获(PortinUseeException e){ System.out.println(“添加侦听器中的异常”+e); }捕获(IOE异常){ System.out.println(“添加侦听器中的异常”+e); } 捕捉(中断异常e){ System.out.println(“添加侦听器中的异常”+e); } 返回(“故障”); } 公共静态void main(字符串[]arg){ 字符ii[]=main1(“”.toCharArray(); 对于(int j=0;j_Java_Gsm_At Command - Fatal编程技术网

再次发送sms时At命令显示忙碌(java) import javax.comm.*; 导入java.io.*; 导入java.util.*; 公共类短信{ 公共同步静态字符串main1(字符串arr){ char cntrlZ=(char)26; InputStream输入=null; OutputStream输出=null; SerialPort SerialPort=null; 试一试{ CommPortIdentifier portId=CommPortIdentifier.getPortIdentifier(“COM3”); serialPort=(serialPort)portId.open(“simpleradapp1”,2000); //System.out.println(“sdiosdfsf”); 字符串f=null;int n; input=serialPort.getInputStream(); output=serialPort.getOutputStream(); 线程读取线程; serialPort.notifyOnDataAvailable(true); 试一试{ serialPort.setSerialPortParams(9600,serialPort.DATABITS_8, SerialPort.STOPBITS_1, 串行端口。奇偶校验(无); }捕获(不支持的操作异常){} output.write((((“ATZ\r\natH\r\n+CMGW:0\r\n+CMGW:1\r\n”).getBytes(); output.flush();Thread.sleep(200); output.write((“ath0\r\n”).getBytes(); output.flush();Thread.sleep(200); output.write(((“AT+CMGF=1\r\n”).getBytes(); output.flush();Thread.sleep(200); output.write(((“AT+CMGS=\“09629993650\”\r\n+CMGW:20\r\n”).getBytes(); output.write(((“helloopsss445545inoyouthere?”).getBytes()); output.write((“\032”).getBytes(); output.flush(); 《睡眠》(2000年); 字节[]读缓冲区=新字节[120]; 试一试{ while(input.available()>0){ int numBytes=input.read(readBuffer); } input.close(); output.close(); serialPort.removeEventListener(); serialPort.sendBreak(1000); serialPort.getInputStream().close(); serialPort.getOutputStream().close(); 如果(serialPort!=null) System.out.print(“端口不为空!!!”; //serialPort.closeport(); 如果(serialPort!=null) System.out.print(“端口不为空!!!”; System.out.print(新字符串(readBuffer)); 返回(新字符串(readBuffer)); }捕获(IOE){} output.flush(); }捕获(无此端口例外){ System.out.println(“添加侦听器中的异常”+e); }捕获(PortinUseeException e){ System.out.println(“添加侦听器中的异常”+e); }捕获(IOE异常){ System.out.println(“添加侦听器中的异常”+e); } 捕捉(中断异常e){ System.out.println(“添加侦听器中的异常”+e); } 返回(“故障”); } 公共静态void main(字符串[]arg){ 字符ii[]=main1(“”.toCharArray(); 对于(int j=0;j

再次发送sms时At命令显示忙碌(java) import javax.comm.*; 导入java.io.*; 导入java.util.*; 公共类短信{ 公共同步静态字符串main1(字符串arr){ char cntrlZ=(char)26; InputStream输入=null; OutputStream输出=null; SerialPort SerialPort=null; 试一试{ CommPortIdentifier portId=CommPortIdentifier.getPortIdentifier(“COM3”); serialPort=(serialPort)portId.open(“simpleradapp1”,2000); //System.out.println(“sdiosdfsf”); 字符串f=null;int n; input=serialPort.getInputStream(); output=serialPort.getOutputStream(); 线程读取线程; serialPort.notifyOnDataAvailable(true); 试一试{ serialPort.setSerialPortParams(9600,serialPort.DATABITS_8, SerialPort.STOPBITS_1, 串行端口。奇偶校验(无); }捕获(不支持的操作异常){} output.write((((“ATZ\r\natH\r\n+CMGW:0\r\n+CMGW:1\r\n”).getBytes(); output.flush();Thread.sleep(200); output.write((“ath0\r\n”).getBytes(); output.flush();Thread.sleep(200); output.write(((“AT+CMGF=1\r\n”).getBytes(); output.flush();Thread.sleep(200); output.write(((“AT+CMGS=\“09629993650\”\r\n+CMGW:20\r\n”).getBytes(); output.write(((“helloopsss445545inoyouthere?”).getBytes()); output.write((“\032”).getBytes(); output.flush(); 《睡眠》(2000年); 字节[]读缓冲区=新字节[120]; 试一试{ while(input.available()>0){ int numBytes=input.read(readBuffer); } input.close(); output.close(); serialPort.removeEventListener(); serialPort.sendBreak(1000); serialPort.getInputStream().close(); serialPort.getOutputStream().close(); 如果(serialPort!=null) System.out.print(“端口不为空!!!”; //serialPort.closeport(); 如果(serialPort!=null) System.out.print(“端口不为空!!!”; System.out.print(新字符串(readBuffer)); 返回(新字符串(readBuffer)); }捕获(IOE){} output.flush(); }捕获(无此端口例外){ System.out.println(“添加侦听器中的异常”+e); }捕获(PortinUseeException e){ System.out.println(“添加侦听器中的异常”+e); }捕获(IOE异常){ System.out.println(“添加侦听器中的异常”+e); } 捕捉(中断异常e){ System.out.println(“添加侦听器中的异常”+e); } 返回(“故障”); } 公共静态void main(字符串[]arg){ 字符ii[]=main1(“”.toCharArray(); 对于(int j=0;j,java,gsm,at-command,Java,Gsm,At Command,你必须永远不要像那样使用睡眠;你必须读取和解析调制解调器给出的响应。像那样睡眠只比完全不等待好一点点(我在本文中提到了这一点)。有关如何读取和解析你得到的响应,请参阅本文 顺便说一句,AT命令应该只以\r而不是\r\n终止(除非您已经更改了S3,并且不应该这样做),有关该命令和AT命令的更多详细信息,请参阅(例如,如果您尚未阅读该规范,强烈建议您这样做).我应该认为没有人知道这个答案吗???已经快30个小时了,但没有人回答:(现在大约42个小时没有回答!!!!!!!!!!!!!有人能帮我回答这个

你必须永远不要像那样使用睡眠;你必须读取和解析调制解调器给出的响应。像那样睡眠只比完全不等待好一点点(我在本文中提到了这一点)。有关如何读取和解析你得到的响应,请参阅本文


顺便说一句,AT命令应该只以
\r
而不是
\r\n
终止(除非您已经更改了S3,并且不应该这样做),有关该命令和AT命令的更多详细信息,请参阅(例如,如果您尚未阅读该规范,强烈建议您这样做).

我应该认为没有人知道这个答案吗???已经快30个小时了,但没有人回答:(现在大约42个小时没有回答!!!!!!!!!!!!!有人能帮我回答这个问题吗
import javax.comm.*;
import java.io.*;
import java.util.*;


public class Sms {
public synchronized static String main1(String arr) {
 char cntrlZ=(char)26;
InputStream input = null;
OutputStream output = null;
SerialPort serialPort = null;
try {
CommPortIdentifier portId = CommPortIdentifier.getPortIdentifier("COM3");


serialPort = (SerialPort) portId.open("SimpleReadApp1", 2000);
//System.out.println("sdiosdfdsf");
String f=null;int n;
input = serialPort.getInputStream();
output = serialPort.getOutputStream();


Thread readThread;
serialPort.notifyOnDataAvailable(true);

try {
serialPort.setSerialPortParams(9600, SerialPort.DATABITS_8, 
SerialPort.STOPBITS_1, 
SerialPort.PARITY_NONE);
} catch (UnsupportedCommOperationException e) {}

output.write(("ATZ\r\natH\r\n+CMGW: 0\r\n+CMGW: 1\r\n").getBytes());
output.flush();Thread.sleep(200);
output.write(("ath0\r\n").getBytes());
output.flush();Thread.sleep(200);
output.write(("AT+CMGF=1\r\n").getBytes());
output.flush();Thread.sleep(200);
output.write(("AT+CMGS=\"09629993650\"\r\n+CMGW: 20\r\n").getBytes());

output.write(("hellooopssss445 545inoo you there?").getBytes());
output.write(("\032").getBytes());
output.flush();


Thread.sleep(2000);
byte[] readBuffer = new byte[120];

try {
while (input.available() > 0) {
int numBytes = input.read(readBuffer);
}

 input.close();
 output.close();
 serialPort.removeEventListener();
serialPort.sendBreak(1000);
serialPort.getInputStream().close();
serialPort.getOutputStream().close();
if (serialPort!=null)
System.out.print("Port is not null!!!");
//serialPort.closeport();
if (serialPort!=null)
System.out.print("Port is not null!!!");
System.out.print(new String(readBuffer));


return(new String(readBuffer));
} catch (IOException e) {}
 output.flush();

} catch (NoSuchPortException e) {
System.out.println("Exception in Adding Listener" + e);
} catch (PortInUseException e) {
System.out.println("Exception in Adding Listener" + e);
} catch (IOException e) {
System.out.println("Exception in Adding Listener" + e);
}
catch (InterruptedException e) {
System.out.println("Exception in Adding Listener" + e);
}
return ("fault");
}



public static void main(String[] arg) {


char ii[]=main1("").toCharArray();
for(int j=0;j<ii.length;j++)
{
if((ii[j]=='O')&&(ii[j+1]=='K'))
System.out.println("GOT");
}
}

}