zoukankan      html  css  js  c++  java
  • 金迪短信猫的使用

    步骤1.将短信猫插入到USB接口中,可以先不放sim卡,然后打开设备管理器,里面会有要安装的驱动的显示,为了安装驱动简单,可以下载驱动精灵来自动安装,按装完成后,

     安装完毕后,打开设备管理器。如图

      

    com1即为短信猫端口,如要修改端口号,则在属性,高级里修改端口号。

    步骤2:

    下载两个包:javacomm20-win32.zip和smslib-v3.5.1.zip

    配置系统环境变量 %JDK_HOME%,然后拷贝所需的文件至

    %JDK_HOME%\jre\bin\win32com.dll
    %JDK_HOME%\jre\lib\javax.comm.properties
    JAVA_HOME是jdk的路径,而非jre,

    还有特别要注意:用myeclipse8.5等的朋友要注意了你看看你用的ide是否是用自己自带的jdk的,可以将上面的文件拷贝到该ide自带的jdk相应的目录下

    3.新建工程

    先建一个CommTest 类来测试端口是否能找到,若没找到,则前面的配置还是有问题的,继续配置吧

    // JindiSMS v3.1 // 该程序主要用于GSM Modem 串口连接速率测试。

      1 import gnu.io.*;
    2
    3 import javax.comm.*;
    4
    5 import java.util.*;
    6
    7 import java.io.*;
    8
    9 public class CommTest {
    10
    11   static CommPortIdentifier portId;
    12
    13   static Enumeration portList;
    14
    15   static int bauds[] = { 9600, 19200, 57600, 115200 };
    16
    17
    18
    19   public static void main(String[] args) {
    20
    21     portList = CommPortIdentifier.getPortIdentifiers();
    22
    23     System.out.println("金笛短信设备端口连接测试...");
    24
    25     while (portList.hasMoreElements()) {
    26
    27       portId = (CommPortIdentifier) portList.nextElement();
    28
    29       if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
    30
    31         System.out.println("找到串口: " + portId.getName());
    32
    33         for (int i = 0; i < bauds.length; i++) {
    34
    35         System.out.print(" Trying at " + bauds[i] + "...");
    36
    37          try
    38
    39         {
    40
    41           SerialPort serialPort;
    42
    43            InputStream inStream;
    44
    45            OutputStream outStream;
    46
    47            int c;
    48
    49            String response;
    50
    51            serialPort = (SerialPort) portId.open("SMSLibCommTester", 1971);
    52
    53            serialPort.setFlowControlMode(SerialPort.FLOWCONTROL_RTSCTS_IN);
    54
    55            serialPort.setSerialPortParams(bauds[i], SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
    56
    57            inStream = serialPort.getInputStream();
    58
    59            outStream = serialPort.getOutputStream();
    60
    61            serialPort.enableReceiveTimeout(1000);
    62
    63            c = inStream.read();
    64
    65 while (c != -1)
    66
    67 c = inStream.read();
    68
    69 outStream.write('A');
    70
    71 outStream.write('T');
    72
    73 outStream.write('\r');
    74
    75 try
    76
    77 {
    78
    79 Thread.sleep(1000);
    80
    81 }
    82
    83 catch (Exception e)
    84
    85 {
    86
    87 }
    88
    89 response = "";
    90
    91 c = inStream.read();
    92
    93 while (c != -1)
    94
    95 {
    96
    97 response += (char) c;
    98
    99 c = inStream.read();
    100
    101 }
    102
    103 f (response.indexOf("OK") >= 0)
    104
    105 {
    106
    107 try
    108
    109 {
    110
    111 System.out.print(" 获取设备信息...");
    112
    113 outStream.write('A');
    114
    115 outStream.write('T');
    116
    117 outStream.write('+');
    118
    119 outStream.write('C');
    120
    121 outStream.write('G');
    122
    123 outStream.write('M');
    124
    125 outStream.write('M');
    126
    127 outStream.write('\r');
    128
    129 response = "";
    130
    131 c = inStream.read();
    132
    133 while (c != -1) {
    134
    135 response += (char) c;
    136
    137 c = inStream.read();
    138
    139 }
    140
    141 System.out.println(" 发现设备: " + response.replaceAll("\\s+OK\\s+", "").replaceAll("\n", "").replaceAll("\r", ""));
    142
    143 } catch (Exception e)
    144
    145 {
    146
    147 System.out.println(" 没有发现设备!");
    148
    149 }
    150
    151 }
    152
    153 else System.out.println(" 没有发现设备!");
    154
    155 serialPort.close();
    156
    157 } catch (Exception e)
    158
    159 {
    160
    161 System.out.println(" 没有发现设备!");
    162
    163 } } } } } }

    找到端口后就可以来测试发接短信了

    1.发短信

    // JindiSMS v3.1 // 该程序主要用于GSM Modem短信发送示例。 为节省您的开发时间,请配合金笛短信设备以达到最佳效果。

     1 import cn.sendsms.*;
    2
    3 import java.util.*; import java.io.*; import java.net.*;
    4
    5 public class SendMessage { public void doIt() throws Exception { Service srv; OutboundMessage msg; // SerialModemGateway gateway=null; OutboundNotification outboundNotification = new OutboundNotification();
    6
    7 System.out.println("示例: 通过金笛串口短信猫发送短信."); System.out.println(Library.getLibraryDescription()); System.out.println("版本: " + Library.getLibraryVersion());
    8
    9 srv = new Service(); SerialModemGateway gateway = new SerialModemGateway("jindi", "COM3", 115200, "wavecom", "M1306B", srv.getLogger()); gateway.setInbound(true); gateway.setOutbound(true); gateway.setSimPin("0000"); gateway.setOutboundNotification(outboundNotification); srv.addGateway(gateway);
    10
    11 srv.startService(); System.out.println(); System.out.println("GSM Modem信息:"); System.out.println(" 厂家: " + gateway.getManufacturer()); System.out.println(" 型号: " + gateway.getModel()); System.out.println(" 序列号: " + gateway.getSerialNo()); System.out.println(" SIM IMSI: " + gateway.getImsi()); System.out.println(" 信号强度: " + gateway.getSignalLevel() + "%"); System.out.println(" 电池容量: " + gateway.getBatteryLevel() + "%"); System.out.println();
    12
    13 //15988765103 //发送短信(异步发送,待发送短信进入队列,发送时不做任何等待) msg = new OutboundMessage("15988765103", "Wrong number tl!"); msg.setPriority(msg.getPriority().HIGH); srv.queueMessage(msg, gateway.getGatewayId()); msg = new OutboundMessage("15067851967", "Wrong number xm!"); msg.setPriority(msg.getPriority().LOW); srv.queueMessage(msg, gateway.getGatewayId()); System.out.println("进入等待状态... - 按回车键退出."); System.in.read();
    14
    15 srv.stopService(); }
    16
    17 public class OutboundNotification implements IOutboundMessageNotification { public void process(String gatewayId, OutboundMessage msg) { System.out.println("发送状态: " + gatewayId); System.out.println(msg); } }
    18
    19 public static void main(String args[]) { SendMessage app = new SendMessage(); try { app.doIt(); } catch (Exception e) { e.printStackTrace(); } } }

    2.收短信

    // JindiSMS v3.1 // 该程序主要用于读取GSM Modem接收到的短信。

     1 import java.util.*; import cn.sendsms.*;
    2
    3 public class ReadMessages { private Service srv;
    4
    5 public void doIt() throws Exception { List msgList; InboundNotification inboundNotification = new InboundNotification(); CallNotification callNotification = new CallNotification(); try { System.out.println("示例: 从串口短信设备读取短信."); System.out.println(Library.getLibraryDescription()); System.out.println("版本: " + Library.getLibraryVersion()); srv = new Service(); // 创建串口GSM modem连接通道. SerialModemGateway gateway = new SerialModemGateway("jindi", "COM5", 115200, "wavecom", "M1206B", srv.getLogger()); //设置通道是否接收短信 gateway.setInbound(true); //设置通道是否可以发送短信 gateway.setOutbound(true); gateway.setSimPin("0000"); //设置短信到达后调用方法 gateway.setInboundNotification(inboundNotification); gateway.setCallNotification(callNotification); // 增加短信通道到服务对象 srv.addGateway(gateway); // 如果有多个设备,可以依次添加到服务对象。
    6
    7 // 启动服务! (连接到所有已定义的设备通道) srv.startService(); System.out.println(); System.out.println("GSM Modem 信息:"); System.out.println(" 厂家: " + gateway.getManufacturer()); System.out.println(" 型号: " + gateway.getModel()); System.out.println(" 序列号: " + gateway.getSerialNo()); System.out.println(" SIM IMSI: " + gateway.getImsi()); System.out.println(" 信号强度: " + gateway.getSignalLevel() + "%"); System.out.println(" 电池容量: " + gateway.getBatteryLevel() + "%"); System.out.println(); // 读取短信. msgList = new ArrayList(); srv.readMessages(msgList, MessageClasses.ALL); System.out.println(msgList.size()); for (int i = 0; i < msgList.size(); i++) System.out.println(msgList.get(i)); // 进入休眠状态. 如果有新短信进来,就会重新激活。 System.out.println("进入等待状态... - 按 <enter>回车键退出."); System.in.read(); } catch (Exception e) { e.printStackTrace(); } finally { srv.stopService(); } }
    8
    9 public class InboundNotification implements IInboundMessageNotification { public void process(String gatewayId, MessageTypes msgType, String memLoc, int memIndex) { List msgList; if (msgType == MessageTypes.INBOUND) { System.out.println(">>> 监测到设备收到新的短信: " + gatewayId + " : " + memLoc + " @ " + memIndex); try { // Read... msgList = new ArrayList(); srv.readMessages(msgList, MessageClasses.UNREAD, gatewayId); for (int i = 0; i < msgList.size(); i++) System.out.println(msgList.get(i)); // ...and reply. // for (int i = 0; i < msgList.size(); i ++) // srv.sendMessage(new OutboundMessage(msgList.get(i).getOriginator(), "Got it!"), gatewayId); } catch (Exception e) { System.out.println("有异常..."); e.printStackTrace(); } } else if (msgType == MessageTypes.STATUSREPORT) { System.out.println(">>> 监测到设备收到短信状态报告: " + gatewayId + " : " + memLoc + " @ " + memIndex); } } }
    10
    11 public class CallNotification implements ICallNotification { public void process(String gatewayId, String callerId) { System.out.println(">>> 监测到有电话打入: " + gatewayId + " : " + callerId); } }
    12
    13 public static void main(String args[]) { ReadMessages app = new ReadMessages(); try { app.doIt(); } catch (Exception e) { e.printStackTrace(); } } }
  • 相关阅读:
    COCO2018 目标检测
    最小生成树[摘录自严长生老师的网站]
    PANet训练自己的数据(VIA标注)
    图的遍历[摘录自严长生老师的网站]
    图的链式存储(邻接表)【摘录自严长生老师的网站】
    Android写入到mysql里的中文总是乱码?
    Mac 当xampp里mysql无法启动的解决办法
    【代码段】Android Studio使用DatePicker选择日期
    Android jdbc连接mysql报错解决方案 (Communications link failure)
    绝命毒师口语精析(4)
  • 原文地址:https://www.cnblogs.com/shenliang123/p/2225269.html
Copyright © 2011-2022 走看看