请老大指点
解决方案 »
- Java打印表格
- 如何用java获取文件的信息呀。求助!
- 如何用Java得到图片文件的尺寸?
- 怎么配置数据库驱动
- 为什么这个程序创建的GUI右边总是有一大块空白
- 一个帖图的程序,调试通过,用appletviewer就是白纸一张。。。 谢谢高人。。。。
- qq群1269842,大家学习交流的好地方:)
- 菜单的事件处理!
- 怎样在javascript中获得当前页面里的applet中发生的事件,比如鼠标单击。在脚本中给applet设置onclick函数我试过了,根本不能触发。
- 我想学JAVA,我C++自认还可以,哪本书可以介绍给我?我希望它偏向实际应用的至少要让我知道JAV能干什么?
- 这句代码中的Object.class确切意思是什么,感觉很模糊。
- 如何用java监听Modem读取来电显示号码!!
AT+CLIP=1\r三 写一个线程,不断的读取数据,当有来电的时候,串口会自动返回如下形式的字符串:
+CLIP: "01012345678",129四 你只需要判断如果字符串以“+CLIP”开头,读取双引号中间的字符串即可。祝你好运~!
给你一个例子:
import javax.comm.*;
.... System.setSecurityManager(null);
CommDriver commDriver;
try {
commDriver = (CommDriver) Class.forName("com.sun.comm.Win32Driver").
newInstance();
commDriver.initialize();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} while (true) {
try {
comm = CommPortIdentifier.getPortIdentifier("COM" + port);
serialPort = (SerialPort) comm.open("Serial Communication",
2000);
is = serialPort.getInputStream();
os = serialPort.getOutputStream();
read = new BufferedReader(new InputStreamReader(is));
serialPort.setSerialPortParams(portSpeeed,
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
System.out.println("串口打开成功。");
break ;
} catch (Exception e) {
System.out.println("串口初始化失败。正在重试...\n");
e.printStackTrace();
try {
Thread.sleep(2000);
} catch (Exception ee) {}
System.exit(1);
}
}
status = this.STATUS_SERIALREAD;
command("AT+CLIP=1\r"); //设置为工作模式
...//写指令函数
public void command(String msg) {
msg = msg.toUpperCase();
try {
for (int i = 0; i < msg.length(); i++) {
os.write(msg.charAt(i));
}
} catch (Exception e) {
e.printStackTrace();
}
}
//读串口
//这个就从is读取即可,自己去实现吧。不能再多写了,再多写你就没的写了,呵呵。