这个是SMS Cat设备:
![点击查看原始大小图片](http://dl.iteye.com/upload/attachment/0075/9986/ae31d131-dc06-30b3-a457-b4b66f51e932.png)
需要插入SIM卡,所以是需要付短信费的。
插好USB和电源后,会安装好驱动,可以在设备管理可以查看到端口号
![](http://dl.iteye.com/upload/attachment/0075/9992/fb42a77b-03c2-3779-ad85-b553e062edcd.png)
也有一种软件可以测试端口是否可连接:secureCRT
![](http://dl.iteye.com/upload/attachment/0076/0009/1542d309-d90f-38ba-8758-1a92cbc90b00.png)
新建好connection后,输入AT测试,如果OK就OK。
![](http://dl.iteye.com/upload/attachment/0076/0013/6ad76c59-63a9-331b-90ad-257a6a847282.png)
好了,端口确定没问题了。
接着,在你的JDK的bin路径下放一个win32com.dll
![](http://dl.iteye.com/upload/attachment/0075/9990/4fa501d5-4462-3aa3-8fc7-aa6571d9f84d.png)
在JDK的lib中放一个comm.jar和javax.comm.properties
![](http://dl.iteye.com/upload/attachment/0076/0033/d8f64f5c-5028-3801-9884-4283b7a3205e.png)
需要的文件都在附件SMSCat.rar中。
OK,所有都准备完了,现在开始代码测试。
demo测试需要用到的jar
![](http://dl.iteye.com/upload/attachment/0076/0025/d7cbda17-00e5-356d-827a-2abe78ae6c1d.png)
sms.properties#sms properties
- Message.comId=modem.com19
- Message.com=COM19
- Message.baudRate=9600
- Message.manufacturer=wavecom
- Message.model=
- Message.simPin=0000
注意:这里的端口COM19必须和你上面的端口对应。
SMSService.java
OutboundNotification.java
- package com.royal.SMSCat;
-
- import org.smslib.AGateway;
- import org.smslib.IOutboundMessageNotification;
- import org.smslib.OutboundMessage;
-
-
-
-
- public class OutboundNotification implements IOutboundMessageNotification {
-
- public void process(AGateway gateway, OutboundMessage msg) {
- System.out.println("Outbound handler called from Gateway: " + gateway.getGatewayId());
- }
- }
SMSCatClient.java
- package com.royal.SMSCat;
-
- public class SMSCatClient {
-
-
-
-
-
-
- public static void main(String[] args) {
- String path = "D:\\sms.properties";
- SMSService.getInstance().startService(path);
- SMSService.getInstance().sendMessage("13800138000", "测试 Test!");
-
- SMSService.getInstance().stopService();
- }
-
- }
测试结果自己找个手机号测吧
![点击查看原始大小图片](http://dl.iteye.com/upload/attachment/0076/0047/bd6898ae-139f-368b-a337-144908cb7412.png)
看见了吗?控制台中的服务(红色标识)还在跑着,也就是端口还在占用着;服务没断,可以不用重新初始化。