我使用 SMSlib 库从 USB 3G 调制解调器 ZTE MF180 发送短信。我尝试使用 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();
我收到第一条短信,然后出现异常:
org.smslib.GatewayException: Comm library exception: java.lang.RuntimeException: gnu.io.PortInUseException: org.smslib 好像 Service.getInstance().stopService() 方法不起作用。但我不知道该怎么办。