我想使用 GSM 调制解调器发送短信,所以我使用 SMSlib API 来发送它。但我会收到如下错误。请帮我。我在 ubuntu 32 位 linux 上工作。
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
{
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.com1", "COM4", 115200, "Huawei", "");
SerialModemGateway gateway = new SerialModemGateway("modem.ttyUSB0", "/dev/ttyUSB0", 115200, "Huawei", "E620");
System.out.println("1");
gateway.setInbound(true);
System.out.println("2");
gateway.setOutbound(true);
System.out.println("3");
//gateway.setSimPin("0000");
// Explicit SMSC address set is required for some modems.
// Below is for VODAFONE GREECE - be sure to set your own!
gateway.setSmscNumber("+919417099997"); // +306942190000 for vodafone
Service.getInstance().setOutboundMessageNotification(outboundNotification);
System.out.println("4");
Service.getInstance().addGateway(gateway);
System.out.println("5");
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();
System.out.println("6");
// Send a message synchronously.
OutboundMessage msg = new OutboundMessage("9986479478", "Hello from SMSLib!"); //306974000000
System.out.println("7");
Service.getInstance().sendMessage(msg);
System.out.println("8");
System.out.println(msg);
// Or, send out a WAP SI message.
//OutboundWapSIMessage wapMsg = new OutboundWapSIMessage("306974000000", new URL("http://www.smslib.org/"), "Visit SMSLib now!");
//Service.getInstance().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 <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();
}
}
}
我得到的错误是
Native lib Version = RXTX-2.1-7
Java lib Version = RXTX-2.1-7
org.smslib.TimeoutException: No response from device.
Experimental: JNI_OnLoad called.
at org.smslib.modem.AModemDriver$CharQueue.get(AModemDriver.java:535)
at org.smslib.modem.AModemDriver.getResponse(AModemDriver.java:338)
at org.smslib.modem.AModemDriver.getResponse(AModemDriver.java:313)
at org.smslib.modem.athandler.ATHandler.getSimStatus(ATHandler.java:145)
at org.smslib.modem.AModemDriver.connect(AModemDriver.java:132)
at org.smslib.modem.ModemGateway.startGateway(ModemGateway.java:189)
at org.smslib.Service$1Starter.run(Service.java:277)
BUILD SUCCESSFUL (total time: 50 seconds)
所以请帮助我...提前谢谢大家。