Skip to main content

i am using package smslib for sending and receiving sms by a modem, i want help regarding the parameters of serial modem gateway

1 reply [Last post]
naruto16
Offline
Joined: 2013-02-27
Points: 0

//code for sending messages
// i have imported smslib

package examples.modem;

import org.smslib.AGateway;
import org.smslib.IOutboundMessageNotification;
import org.smslib.Library;
import org.smslib.OutboundMessage;
import org.smslib.Service;
import org.smslib.modem.SerialModemGateway;

public class SendMessage

{

public void doIt() throws Exception
{
Service srv;
OutboundMessage msg;
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());
srv=new Service();
SerialModemGateway gateway = new SerialModemGateway("modem.com1", "COM23", 57600, "Nokia", "2730");
gateway.setInbound(true);
gateway.setOutbound(true);
gateway.setSimPin("0000");
srv.setOutboundMessageNotification(outboundNotification);
srv.addGateway(gateway);
srv.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.
msg = new OutboundMessage("+306948494037", "Hello from SMSLib!");
srv.sendMessage(msg);
System.out.println(msg);
// Or, send out a WAP SI message.
//OutboundWapSIMessage wapMsg = new OutboundWapSIMessage("+306948494037", new URL("https://mail.google.com/"), "Visit GMail now!");
//srv.sendMessage(wapMsg);
//System.out.println(wapMsg);
// You can also queue some asynchronous messages to see how the callbacks
// are called...
//msg = new OutboundMessage("+309999999999", "Wrong number!");
//srv.queueMessage(msg, gateway.getGatewayId());
//msg = new OutboundMessage("+308888888888", "Wrong number!");
//srv.queueMessage(msg, gateway.getGatewayId());
System.out.println("Now Sleeping - Hit to terminate.");
System.in.read();
srv.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();
}
}
}

//it is giving error:
/*Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The constructor Service() is not visible

at examples.modem.SendMessage.doIt(SendMessage.java:105)
at examples.modem.SendMessage.main(SendMessage.java:155)

*/

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
apoorvada
Offline
Joined: 2013-12-11
Points: 0

org.smslib.modem.SerialModemGateway.SerialModemGateway(String id, String comPort, int baudRate, String manufacturer, String model)

Constructor for a serially connected gsm modem or phone.

Parameters:
id - Your own ID for addressing this gateway.
comPort -The comm port to which this modem is connected. For example, COM1
baudRate -The baud rate of the serial connection.
manufacturer -The manufacturer, for example "Nokia".
model - The model, for example "6130"

Note: comport is mandatory (in windows it starts from 0 ie if your port is COM7 that you see in the device manager then you need to add COM8 in your code) and mention the baudrate visible in the device manager , manufacturer and model are not mandatory I suppose.Hope this helps .