简单的字符串问题,欢迎参与! 你试一试send("hello+"ctrl"+"z");不过我没有试过! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 请看我的程序在超级终端下发送命令格式是AT+CMGS=“+8613939060564” 回车>发送的内容 ctrl-z键结束并发送import java.io.*;import javax.comm.*;import java.util.*;import java.awt.event.*;public class receiveCmd extends Thread implements SerialPortEventListener { SerialPort sPort=null; static BufferedReader in=null; public receiveCmd(SerialPort sPort) { this.sPort=sPort; } public void send(SerialPort sPort) { String cmd1="AT+CMGS=\"+8613939060564\"\r THIS IS TEST!"; //cmd1+=(char)(Integer.parseInt("1B",16));//用ESC表示结束并发送 cmd1+=(char)(Integer.parseInt("17",16))+"z";//用ctrl-z表示结束并发送 “这样表示不正确” String cmd2="AT+CMGL=\"REC UNREAD\""; String cmd3="AT+CMGL=\"ALL\""; PrintWriter pw=null; try{ pw=new PrintWriter(sPort.getOutputStream()); pw.println(cmd2); pw.flush(); pw.close(); System.out.println("command has been send"); } catch(IOException e){System.out.println("catch exception when send cmd to modemn"); System.out.println(e.getMessage());} } public void receive(SerialPort sPort) { BufferedReader br=null; String msg=null; SerialPortEvent sEvent=null; byte[] b=null; //SerialPortEventListener sListener=null; try{ in=new BufferedReader(new InputStreamReader(sPort.getInputStream())); sPort.addEventListener(this ); sPort.notifyOnDataAvailable(true); System.out.println("msg is receiveing..."); } catch(IOException e){System.out.println("catch exception when send cmd to modemn"); System.out.println(e.getMessage());} catch (TooManyListenersException e) {e.getMessage();} } public void run() {send(sPort); while(true) { // try{sleep(100);} //catch(InterruptedException e){System.out.println(e.getMessage());} receive(sPort); break; } } public synchronized void serialEvent(SerialPortEvent sEvent) { String msg; if(sEvent.getEventType()==sEvent.DATA_AVAILABLE) { System.out.println("Data from COM1 is coming..."); try{ while(true){msg=in.readLine(); System.out.println("msg from modemn is:"+msg); if(msg.equals("OK")) {in.close(); break;} }//while // System.exit(0); }catch(IOException e){System.out.println(e.getMessage());} }//if}} 你只需要连上CRL+Z的ASCII代码就可以了CRL+Z的代码我不记得了,你可以找个ASCII表对照找一下 我也这么认为,是直接加上CTRL的ASCII码和Z的ASCII码,还是要加上CRL+Z的ASCII代码? 当然是CRL+Z的ASCII代码了我记得好像是12,你查一下吧字符0的ASCII代码是30,CRL+Z的ASCII代码要比30小的多 我已经进行了测试,证明是ctrl的ASCII码加上Z的就可以了 java做一个显示Window文件的程序 structs标签问题 Spring声明式事务不能回滚, 高手帮忙! 请问如何调试jdk提供的源码? 关于游标的问题! 几个类,达人帮看一下,拜托了!解决问题忙上结帖给分 请大家帮我看一看问题出在那儿。!!!! 请问各位大哥大姐,如何在一幅图片的指定位置设定像素? 急,急,急,帮帮忙 在JTextField中,为什么在中文输入法状态下不能输入标点之类的字符? 一个小问题~~~关于截取字符串 为什么老是找不到类?
AT+CMGS=“+8613939060564” 回车
>发送的内容 ctrl-z键结束并发送import java.io.*;
import javax.comm.*;
import java.util.*;
import java.awt.event.*;
public class receiveCmd extends Thread implements SerialPortEventListener {
SerialPort sPort=null;
static BufferedReader in=null;
public receiveCmd(SerialPort sPort) {
this.sPort=sPort;
}
public void send(SerialPort sPort)
{
String cmd1="AT+CMGS=\"+8613939060564\"\r THIS IS TEST!";
//cmd1+=(char)(Integer.parseInt("1B",16));//用ESC表示结束并发送
cmd1+=(char)(Integer.parseInt("17",16))+"z";//用ctrl-z表示结束并发送 “这样表示不正确”
String cmd2="AT+CMGL=\"REC UNREAD\"";
String cmd3="AT+CMGL=\"ALL\"";
PrintWriter pw=null;
try{
pw=new PrintWriter(sPort.getOutputStream());
pw.println(cmd2);
pw.flush();
pw.close();
System.out.println("command has been send"); } catch(IOException e){System.out.println("catch exception when send cmd to modemn");
System.out.println(e.getMessage());} } public void receive(SerialPort sPort)
{
BufferedReader br=null;
String msg=null;
SerialPortEvent sEvent=null; byte[] b=null; //SerialPortEventListener sListener=null;
try{
in=new BufferedReader(new InputStreamReader(sPort.getInputStream()));
sPort.addEventListener(this );
sPort.notifyOnDataAvailable(true);
System.out.println("msg is receiveing...");
}
catch(IOException e){System.out.println("catch exception when send cmd to modemn");
System.out.println(e.getMessage());}
catch (TooManyListenersException e) {e.getMessage();}
}
public void run()
{send(sPort);
while(true) {
// try{sleep(100);}
//catch(InterruptedException e){System.out.println(e.getMessage());}
receive(sPort);
break;
}
} public synchronized void serialEvent(SerialPortEvent sEvent)
{
String msg;
if(sEvent.getEventType()==sEvent.DATA_AVAILABLE) { System.out.println("Data from COM1 is coming...");
try{
while(true){msg=in.readLine();
System.out.println("msg from modemn is:"+msg);
if(msg.equals("OK"))
{in.close();
break;}
}//while
// System.exit(0);
}catch(IOException e){System.out.println(e.getMessage());}
}//if
}
}
CRL+Z的代码我不记得了,你可以找个ASCII表对照找一下
我记得好像是12,你查一下吧
字符0的ASCII代码是30,CRL+Z的ASCII代码要比30小的多