0

i am trying to use SMSLib to send sms to mobiles from my pc. I am using my Nokia 5130 GSM phone to send messages, but its not working. Heres the code i am using.

package sms;
import org.smslib.AGateway;
import org.smslib.IOutboundMessageNotification;
import org.smslib.Library;
import org.smslib.Message.MessageEncodings;
import org.smslib.OutboundMessage;
import org.smslib.Service;
import org.smslib.modem.SerialModemGateway;

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.com12", "COM12", 115200, "Nokia", "Nokia 5130 XPressMusic USB Modem");


gateway.setInbound(true);
gateway.setOutbound(true);
gateway.setSimPin("0000");

gateway.setSmscNumber("+919886005444");
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();
// Send a message synchronously.
OutboundMessage msg = new OutboundMessage("+917829903913", "Sample msg");
msg.setEncoding(MessageEncodings.ENC7BIT);
msg.setSrcPort(0);
msg.setDstPort(66500);
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();
}
}
}

And here is the error message i am getting. Please help as i don't have much knowledge on these.

run:
Example: Send message from a serial gsm modem.
SMSLib: A Java API library for sending and receiving SMS via a GSM modem or other supported   gateways.
This software is distributed under the terms of the Apache v2.0 License.
Web Site: http://smslib.org
Version: 3.5.1
log4j:WARN No appenders could be found for logger (smslib).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
org.smslib.GatewayException: Comm library exception: java.lang.RuntimeException: javax.comm.PortInUseException: Port currently owned by Unknown Windows Application
    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:276)
 BUILD SUCCESSFUL (total time: 6 seconds)
Bhaskar Sharma
  • 79
  • 2
  • 5
  • 14

3 Answers3

1

Make sure no other application is listening on COM12 . javax.comm.PortInUseException: occurred because your code tries to register COM12 which is not available.

After you have copied all the necessary jars amd dll files to the right location, this should work. You also need a 32 bit JDK so you might have to download JDK for a 32bit if you don't have one else you will get java.lang.UnsatisfiedLinkError:

I ran this code and it works. Also rememeber to set setSmscNumber to your SIM provider's looks like you still have the default one (example one)

Cheers PB

Babajide Prince
  • 552
  • 1
  • 10
  • 25
1

There is an application related to your phone(like Nokia Suite) that works on the PC and make a connection with your phone when connecting your phone to the PC, make sure you turn off all such applications and make your connection just a physical one.

Muhammed Refaat
  • 8,914
  • 14
  • 83
  • 118
0

It worked for me after I installed the 32 bit java version. Also make sure you use the correct port. com11 in my case.

enter image description here

Harlan Gray
  • 341
  • 6
  • 20