Я использую библиотеку SMSlib для отправки смс с USB 3G модема ZTE MF180. Я попытался использовать класс SendMessage.java для проверки моего модема, поэтому я продублировал код отправки смс - так что теоретически я ожидал получить 2 смс.
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: Исключение библиотеки связи: java.lang.RuntimeException: gnu.io.PortInUseException: org.smslib Похоже, метод Service.getInstance().stopService() не работает. Но я не знаю, что делать.