javasmslib

org.smslib.GatewayException: Comm library exception: java.lang.RuntimeException: javax.comm.NoSuchPortException


I am trying to send messages using smslib api and to be honest i have very little info about it so i download a sample project and put the libs in respective places as told . My class to send messages is :

public class SendMessage{
    public void doIt() throws Exception
    {
            OutboundNotification outboundNotification = new OutboundNotification();
            System.out.println("Example: Send message from a serial gsm modem.");
            System.out.println(Library.getLibraryDescription());
            System.out.println("Version: " + Library.getLibraryVersion());
            SerialModemGateway gateway = new SerialModemGateway("modem.com4", "COM4", 9600, "", "");
            gateway.setInbound(true);
            gateway.setOutbound(true);
            Service.getInstance().setOutboundMessageNotification(outboundNotification);
            Service.getInstance().addGateway(gateway);
            Service.getInstance().startService();
            System.out.println();
            System.out.println("Modem Information:");
            System.out.println("  Manufacturer: " + gateway.getManufacturer());
            System.out.println("  Model: " + gateway.getModel());
            System.out.println("  Serial No: " + gateway.getSerialNo());
            System.out.println("  SIM IMSI: " + gateway.getImsi());
            System.out.println("  Signal Level: " + gateway.getSignalLevel() + " dBm");
            System.out.println("  Battery Level: " + gateway.getBatteryLevel() + "%");
            System.out.println();
            OutboundMessage msg = new OutboundMessage("contact_num", "Hello from SMSLib!");
            Service.getInstance().sendMessage(msg);
            System.out.println(msg);
            System.out.println("Now Sleeping - Hit <enter> to terminate.");
            System.in.read();
            Service.getInstance().stopService();
    }

    public class OutboundNotification implements IOutboundMessageNotification
    {
            public void process(AGateway gateway, OutboundMessage msg)
            {
                    System.out.println("Outbound handler called from Gateway: " + gateway.getGatewayId());
                    System.out.println(msg);
            }
    }

    public static void main(String args[])
    {
            SendMessage app = new SendMessage();
            try
            {
                    app.doIt();
            }
            catch (Exception e)
            {
                    e.printStackTrace();
            }
    }

}

on executing the line

                Service.getInstance().startService();

I get an exception :

org.smslib.GatewayException: Comm library exception: java.lang.RuntimeException: javax.comm.NoSuchPortException at org.smslib.modem.SerialModemDriver.connectPort(SerialModemDriver.java:102) at org.smslib.modem.AModemDriver.connect(AModemDriver.java:114) at org.smslib.modem.ModemGateway.startGateway(ModemGateway.java:189) at org.smslib.Service$1Starter.run(Service.java:277)

Well this had to occur because i don't have a GSM Modem so i have a few questions.

  1. Can i turn my android phone into gsm modem.

  2. What does modem.com4 in SerialModemGateway("modem.com4", "COM4", 9600, "", ""); mean .

I searched a lot on how to turn my phone into a gsm modem but no luck.


Solution

  • for Question#1 : Yes, I think you can do it.

    for Question#2 (To get the COM port): Which OS you are using ? for Windows -

    If you can not see your cellphones name as a modem in "Phone and Modem", it mean that you can not use your cellphone as a GSM modem.