首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SMSLib。Service.getInstance().stopService()不起作用

SMSLib。Service.getInstance().stopService()不起作用
EN

Stack Overflow用户
提问于 2012-08-29 16:00:38
回答 1查看 2.1K关注 0票数 0

我使用SMSlib库从USB3G调制解调器中兴通讯MF180发送短信。我尝试使用SendMessage.java类来测试我的调制解调器,所以我复制了短信发送代码-所以在理论上我希望收到2条短信。

代码语言:javascript
复制
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();

新的outboundNotification2 = OutboundNotification OutboundNotification();

代码语言:javascript
复制
    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:通信库异常: java.lang.RuntimeException: gnu.io.PortInUseException: org.smslib看起来像Service.getInstance().stopService()方法不起作用。但我不知道该怎么办。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-08-29 16:26:55

您正在尝试创建到同一COM端口的新SerialModemGateway,但这是不可行的-只有一个进程/服务可以同时打开com端口。

通过执行gateway.stopGateway(),确保在创建另一个之前停止第一个命令

虽然您不需要每次都设置和拆除SerialModemGateway并停止/启动服务,但只需创建一条新消息并使用已打开的现有网关和服务发送它即可。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12173301

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档