SMSlib ライブラリを使用して、USB 3G モデム ZTE MF180 から SMS を送信しています。SendMessage.java クラスを使用してモデムをテストしようとしたため、SMS 送信コードを複製しました。つまり、理論的には 2 つの SMS を受信することを期待していました。
OutboundNotification outboundNotification = new OutboundNotification();
SerialModemGateway gateway = new SerialModemGateway("modem.com1", "COM6", 115200, "ZTE", "MF180");
gateway.setInbound(true);
gateway.setOutbound(true);
gateway.setSimPin("");
gateway.setSmscNumber("+79037011111");
Service.getInstance().setOutboundMessageNotification(outboundNotification);
Service.getInstance().addGateway(gateway);
Service.getInstance().startService();
OutboundMessage msg = new OutboundMessage("79213533296", "Hello world!");
Service.getInstance().sendMessage(msg);
Service.getInstance().removeGateway(gateway);
Service.getInstance().stopService();
OutboundNotification outboundNotification2 = new OutboundNotification();
SerialModemGateway gateway2 = new SerialModemGateway("modem.com1", "COM6", 115200, "ZTE", "MF180");
gateway2.setInbound(true);
gateway2.setOutbound(true);
gateway2.setSimPin("");
gateway2.setSmscNumber("+79037011111");
Service.getInstance().setOutboundMessageNotification(outboundNotification2);
Service.getInstance().addGateway(gateway2);
Service.getInstance().startService();
OutboundMessage msg2 = new OutboundMessage("79213533296", "Оповещение о событии ");
Service.getInstance().sendMessage(msg2);
Service.getInstance().stopService();
最初の SMS を取得してから例外に該当します。
org.smslib.GatewayException: Comm library exception: java.lang.RuntimeException: gnu.io.PortInUseException: org.smslib Service.getInstance().stopService() メソッドが機能しないようです。しかし、私は何をすべきかわかりません。