📄 testgsmmodem.java~31~
字号:
package Test;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2003</p> * <p>Company: </p> * @author not attributable * @version 1.0 */import GSMModem.*;public class TestGSMModem { public TestGSMModem() { } public static void main(String[] argv) { GSMModem gsmmodem1 = new GSMModem(); //1)初始化信息 /* String device =System.getProperty("SMS.Device"); String baud =System.getProperty("SMS.Baud"); String sn =System.getProperty("SMS.Sn"); String mobile = System.getProperty("SMS.Mobile"); */ String device = "COM4"; String baud = "9600"; String sn = "OUIW-SCRA-KRUD-CADU"; String mobile = "13910597586"; if(device==null || baud==null ||sn==null ||mobile==null){ System.out.println("请正确的设定通讯串口、波特率、注册码、接收号码,否则无法正常测试!"); return; } gsmmodem1.setDevice(device); gsmmodem1.setBaudrate(baud); gsmmodem1.setSn(sn); //2) 测试信息 String text = "金仓短信标准接口(SDK2.x)让您在最短时间开发出短信应用,感谢您的选择!使用愉快!"; //短信内容 String text_eng = "KingBase SMS SDK2.x is wonderful for developing SMS Application software! Thank you for your choice,enjoy it!"; //短信内容 try { //3) 连接设备 System.out.println("GSMModemInit:connecting ... ..."); if (gsmmodem1.GSMModemInit() == false) { System.out.println( gsmmodem1.GSMModemGetErrorMsg()); return; } //4)测试AT指令 String result = gsmmodem1.GSMModemCommand("+CSCA?","+CSCA:"); if(result!=null){ System.out.println("AT+CSCA=? 结果: " + result); }else{ System.out.println("AT+CSCA=? 错误: " + gsmmodem1.GSMModemGetErrorMsg()); } result = gsmmodem1.GSMModemCommand("+CCID?","+CCID:"); if(result!=null){ System.out.println("AT+CCID=? 结果: " + result); }else{ System.out.println("AT+CCID=? 错误: " + gsmmodem1.GSMModemGetErrorMsg()); } result = gsmmodem1.GSMModemCommand("+CFUN=0",null); System.out.println("AT+CFUN=1 结果: " + result); System.out.println("AT+CFUN=1 错误: " + gsmmodem1.GSMModemGetErrorMsg()); //4)发送多条和接收多次短信举例 int Count = 0; //发送次数 while (Count > 0) { Count--; //4.1)判断是否连接设备,若没有连接的话,则重新连接 if (!gsmmodem1.GSMModemIsConn()) { if (!gsmmodem1.GSMModemInit()) { System.out.println(gsmmodem1.GSMModemGetErrorMsg()); continue; } } //4.2)发送短信 //发送中文短信 System.out.println("GSMModemSMSsend:Send sms through modem, ........."); if (gsmmodem1.GSMModemSMSsend(null, gsmmodem1.ENCodeing_GB2312, text, mobile, false)) System.out.println("GSMModemSMSsend: Success! Sending chinese simple sms!"); else System.out.println(gsmmodem1.GSMModemGetErrorMsg()); //发送英文短信 if (gsmmodem1.GSMModemSMSsend(null, gsmmodem1.ENCodeing_US, text_eng, mobile, false)) System.out.println("GSMModemSMSsend: Success! sending english sms!"); else System.out.println(gsmmodem1.GSMModemGetErrorMsg()); //4.3) 取信并删除SIM卡中的所有短信 System.out.println("GSMModemSMSReadAll:Recieve ......................"); java.util.Vector allmsg = gsmmodem1.GSMModemSMSReadAll(gsmmodem1.ReadSMS_ALL_READ_ONLY); //4.4)输出每条短信息具体内容 for(int i=0; i<allmsg.size();i++){ GSMMessage gsmmsg1 = (GSMMessage) allmsg.elementAt(i); System.out.println("\n短信#" + i + ":----------------------------------------"); System.out.println("\t短信类型=" + gsmmsg1.getType()); System.out.println("\t存储位置=" + gsmmsg1.getStoreName()); System.out.println("\t发送时间=" + gsmmsg1.getSendTime()); System.out.println("\t电话号码=" + gsmmsg1.getNumber()); System.out.println("\t短信编码=" + gsmmsg1.getEncoding()); System.out.println("\t短信长度=" + gsmmsg1.getLength()); System.out.println("\t短信内容=" + gsmmsg1.getContent()); System.out.println("短信#" + i + ":----------------------------------------"); } //4.5)延迟半秒中,每发送一条短信延迟500ms try { java.lang.Thread.sleep(500); } catch (Exception t) { ; } } //end while //5) 断开连接 gsmmodem1.GSMModemRelease(); System.out.println("-------------Test GSMModem over!!!---------------------"); } catch (Exception e) { e.printStackTrace(); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -