0

Im using SMSlib library to send sms from USB 3G Modem ZTE MF180. I tried to use SendMessage.java class to test my modem, so I duplicated sms sending code - so in theory I was expecting to get 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();

I get the first SMS and then falls exception:

org.smslib.GatewayException: Comm library exception: java.lang.RuntimeException: gnu.io.PortInUseException: org.smslib It seems, like Service.getInstance().stopService() method doesn't works. But I dont know what to do.

Nicholas Albion
  • 3,096
  • 7
  • 33
  • 56
  • I'm confused by "Service.getInstance(). setOutboundMessageNotification()" what if you were sending messages from different threads? I suppose you would only do that setup once and keep the service running... – Nicholas Albion Aug 29 '12 at 08:28

1 Answers1

0

Your're trying to create a new SerialModemGateway to the same COM port, which isn't doable - only one process/service can have a com port open at the same time.

Make sure you stop the first one before creating another by doing gateway.stopGateway()

Though you don't really need to set up and tear down the SerialModemGateway and stop/start the service every time, just create a new message and send it using the existing gateway and service you have opened.

nos
  • 223,662
  • 58
  • 417
  • 506
  • How can I update gateway settings, Incase if I modified the Gateway settings like port or manufacturer? – mreaevnia Jan 06 '15 at 17:37