Java SMSLib。Service.getInstance().stopService()不';行不通
Im使用SMSlib库从USB 3G调制解调器中兴MF180发送短信。 我试图使用SendMessage.java类来测试我的调制解调器,所以我复制了短信发送代码——所以理论上我希望收到2条短信Java SMSLib。Service.getInstance().stopService()不';行不通,java,smslib,Java,Smslib,Im使用SMSlib库从USB 3G调制解调器中兴MF180发送短信。 我试图使用SendMessage.java类来测试我的调制解调器,所以我复制了短信发送代码——所以理论上我希望收到2条短信 OutboundNotification outboundNotification = new OutboundNotification(); SerialModemGateway gateway = new SerialModemGateway("modem.com1", "COM6", 11
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=新的OutboundNotification()
我收到了第一条短信,然后出现异常:
org.smslib.GatewayException:Comm库异常:java.lang.RuntimeException:gnu.io.portinuseeException:org.smslib
似乎Service.getInstance().stopService()方法不起作用。但是我不知道该怎么办。您正在尝试为同一COM端口创建新的SerialModemGateway,这是不可行的-只有一个进程/服务可以同时打开COM端口 通过执行
gateway.stopGateway()
虽然您实际上不需要每次都设置和拆除SerialModemGateway并停止/启动服务,但只需创建一条新消息并使用已打开的现有网关和服务发送它。我被“service.getInstance().setOutboundMessageNotification()”弄糊涂了,如果您从不同的线程发送消息怎么办?我想您只需要执行一次设置,并保持服务运行…如果我修改了网关设置(如端口或制造商),如何更新网关设置?
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();