使用SMSlib库发短信 出现No response from device错误~

分享
错误是这样的
0 [main] INFO smslib - SMSLib: A Java API library for sending and receiving SMS via a GSM modem or other supported gateways.
This software is distributed under the terms of the Apache v2.0 License.
Web Site: http://smslib.org
0 [main] INFO smslib - Version: 3.4.1
0 [main] INFO smslib - JRE Version: 1.6.0_11
0 [main] INFO smslib - JRE Impl Version: 11.0-b16
0 [main] INFO smslib - O/S: Windows XP / x86 / 5.1
==========
31 [Thread-0] INFO smslib - GTW: modem.com3: Starting gateway, using Generic AT Handler.
31 [Thread-0] INFO smslib - GTW: modem.com3: Opening: COM3 @9600
49266 [Thread-0] INFO smslib - GTW: modem.com3: Closing: COM3 @9600
org.smslib.TimeoutException: No response from device.
at org.smslib.modem.AModemDriver$CharQueue.get(AModemDriver.java:514)
at org.smslib.modem.AModemDriver.getResponse(AModemDriver.java:306)
at org.smslib.modem.athandler.ATHandler.getSimStatus(ATHandler.java:130)
at org.smslib.modem.AModemDriver.connect(AModemDriver.java:131)
at org.smslib.modem.ModemGateway.startGateway(ModemGateway.java:158)
at org.smslib.Service$1Starter.run(Service.java:239)
60047 [pool-1-thread-3] WARN smslib - WatchDog: Gateway: modem.com3 restarting.
60047 [pool-1-thread-3] INFO smslib - GTW: modem.com3: Stopping gateway...
60047 [pool-1-thread-3] INFO smslib - GTW: modem.com3: Closing: COM3 @9600
60047 [pool-1-thread-3] INFO smslib - GTW: modem.com3: Gateway stopped.
60047 [pool-1-thread-3] INFO smslib - GTW: modem.com3: Starting gateway, using Generic AT Handler.
60047 [pool-1-thread-3] INFO smslib - GTW: modem.com3: Opening: COM3 @9600



java代码

public class SendMessage 
{
    public void doIt() throws Exception
    {
        Service srv;
        OutboundMessage msg;
        OutboundNotification outboundNotification = new OutboundNotification();
        srv = new Service();
        SerialModemGateway gateway = new SerialModemGateway("modem.com3","COM3",9600,"11","22");
        
        gateway.setInbound(true);
        gateway.setOutbound(true);
        gateway.setSimPin("0000");
        gateway.setProtocol(Protocols.PDU);
        
        srv.setOutboundNotification(outboundNotification);
        srv.addGateway(gateway);
        
        System.out.println("==========");
        
        srv.startService();
        
        System.out.println("==========");
        
        
        msg = new OutboundMessage("1391******", "aaaa1234567");
        msg.setEncoding(MessageEncodings.ENCUCS2);//这句话是发中文短信必须的
        srv.sendMessage(msg);
        System.out.println("Now Sleeping - Hit <enter> to terminate.");
        System.in.read();
        srv.stopService();
    }

  public class OutboundNotification implements IOutboundMessageNotification {

 public void process(String gatewayId, OutboundMessage msg)
     {
         System.out.println("Outbound handler called from Gateway: " + gatewayId);
         System.out.println(msg);
     }

}

    public static void main(String args[])
    {
        SendMessage app = new SendMessage();
        try
        {
            app.doIt();
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }
}



短信设备二次开发 2022-04-08 1 0

admin

  • 注册时间 : 2022-03-30 04:08:47
  • 邮箱地址 : admin@tenghengkeji.com
  • 此页面用于展示用户的基本上资料信息

回帖 ( 1 )

  1. #1楼 admin
    2022-04-08 20:33:46
    0 0
    回复
    首先是确认你的串口可用可以AT,怎么确认呢?使用串《口调试器测试GSM MODEM》,确定没问题后排除下面问题:
    错误的产生无非就是这个配置有问题的,参数不对无法执行对应的指令无响应,最后抛出超时异常。
    SerialModemGateway gateway = new SerialModemGateway("modem.com3","COM3",9600,"11","22");
    第三参数波特率问题,这个主要针对刚了解GSM MODEM的朋友波特率有很多种的不仅是9600,还有115200等更快速率的。但常用就9600和115200,最好直接问设备厂家告知便可
    第四和第五参数问题,第四个一定要选对smslib支持品牌,常用写入Wavecom都有很多设备能通过,wavecom的指令几乎符合标准AT指令,所以用这个品牌的指令很多设备都通用。西门子就用西门子的Siemens。
    第五个参数不知道型号就留空值,这个型号里面一般是去读取这个型号的特殊指令,防止某些问题出现的时候可以对应处理问题。