我正在使用SMSlib库从USB 3G Modem 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();
我收到了第一条短信,然后出现异常:
org.smslib.GatewayException:Comm库异常:java.lang.RuntimeException:gnu.io.PortInUseException:org.smslib 看起来像Service.getInstance()。stopService()方法不起作用。但我不知道该怎么做。
答案 0 :(得分:0)
您正在尝试创建一个新的SerialModemGateway到同一个COM端口,这是不可行的 - 只有一个进程/服务可以同时打开一个com端口。
确保在执行gateway.stopGateway()
虽然您并不是真的需要设置和拆除SerialModemGateway并且每次都停止/启动服务,只需创建一条新消息并使用您已打开的现有网关和服务发送它。