0

SMSlib ライブラリを使用して、USB 3G モデム ZTE MF180 から SMS を送信しています。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();

最初の SMS を取得してから例外に該当します。

org.smslib.GatewayException: Comm library exception: java.lang.RuntimeException: gnu.io.PortInUseException: org.smslib Service.getInstance().stopService() メソッドが機能しないようです。しかし、私は何をすべきかわかりません。

4

1 に答える 1

0

同じ COM ポートに新しい SerialModemGateway を作成しようとしていますが、これは実行できません。COM ポートを同時に開くことができるプロセス/サービスは 1 つだけです。

次のようにして、最初のものを停止してから別のものを作成してくださいgateway.stopGateway()

毎回 SerialModemGateway をセットアップして破棄し、サービスを停止/開始する必要はありませんが、新しいメッセージを作成し、開いている既存のゲートウェイとサービスを使用して送信するだけです。

于 2012-08-29T08:26:55.397 に答える