0

我正在使用 Simado GDT11 调制解调器和 Prolific USB 转串口驱动程序。新连接出现在我的设备管理器 > 端口列表中。但是,我无法使用 smslib 发送消息。

我正在使用 smslib 示例中指定的基本类,但总是有一些错误表明设备没有响应。由于使用了 USB 端口,我添加了轮询参数,但无济于事。Commtest Utility 能够连接到同一个端口,所以我认为端口号不是问题。

堆栈跟踪:

log4j:WARN No appenders could be found for logger (smslib).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
org.smslib.TimeoutException: No response from device.
  at org.smslib.modem.AModemDriver$CharQueue.get(AModemDriver.java:535)
  at org.smslib.modem.AModemDriver.getResponse(AModemDriver.java:338)
  at org.smslib.modem.AModemDriver.getResponse(AModemDriver.java:313)
  at org.smslib.modem.athandler.ATHandler.getSimStatus(ATHandler.java:145)
  at org.smslib.modem.AModemDriver.connect(AModemDriver.java:132)
  at org.smslib.modem.ModemGateway.startGateway(ModemGateway.java:189)
  at org.smslib.Service$1Starter.run(Service.java:277)

代码:

public class SendMessage {

public void doIt() throws Exception
{
    SerialModemGateway gateway = new SerialModemGateway("modem.com4", "COM4", 115200, "Simado", "GDT11");
    try {
        OutboundNotification outboundNotification = new OutboundNotification();
        System.out.println("Example: Send message from a serial gsm modem.");
        System.out.println(Library.getLibraryDescription());
        System.out.println("Version: " + Library.getLibraryVersion());
        gateway.setInbound(false);
        gateway.setOutbound(true);
        gateway.setSimPin("0000");
        // Explicit SMSC address set is required for some modems.
        // Below is for VODAFONE GREECE - be sure to set your own!
        gateway.setSmscNumber("+919560734413");
        Service.getInstance().setOutboundMessageNotification(outboundNotification);
        Service.getInstance().addGateway(gateway);
        Service.getInstance().S.SERIAL_NOFLUSH = true;
        Service.getInstance().S.SERIAL_POLLING = true;
        Service.getInstance().S.SERIAL_POLLING_INTERVAL = 200;
        Service.getInstance().startService();
        System.out.println();
        System.out.println("Modem Information:");
        System.out.println("  Manufacturer: " + gateway.getManufacturer());
        System.out.println("  Model: " + gateway.getModel());
        System.out.println("  Serial No: " + gateway.getSerialNo());
        System.out.println("  SIM IMSI: " + gateway.getImsi());
        System.out.println("  Signal Level: " + gateway.getSignalLevel() + " dBm");
        System.out.println("  Battery Level: " + gateway.getBatteryLevel() + "%");
        System.out.println();
        // Send a message synchronously.
        OutboundMessage msg = new OutboundMessage("+918095065000", "Hello from SMSLib!");
        Service.getInstance().sendMessage(msg);
        System.out.println(msg);
    } finally {
        gateway.stopGateway();
        Service.getInstance().stopService();
    }

}

public class OutboundNotification implements IOutboundMessageNotification
{
    public void process(AGateway gateway, OutboundMessage msg)
    {
        System.out.println("Outbound handler called from Gateway: " + gateway.getGatewayId());
        System.out.println(msg);
    }
}

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

1 回答 1

1

我解决了这个问题。代码是正确的。显然,使用正在漫游的 SIM 卡并不是最好的主意。我转移到本地 SIM 卡,消息已发送。

此外,我使用的是 USB 到 COM 端口仿真器(Prolific USB-Serial),因此调制解调器在运行代码时没有初始化。

AT + CMGF = 1为了解决这个问题,我在服务器启动时运行了初始化命令( )。

于 2013-09-25T07:52:18.130 回答