0
我正在使用Simado GDT11調制解調器和Prolific USB轉串口驅動程序。新的連接出現在我的設備管理器>端口列表中。但是,我無法使用smslib發送消息。無法使用smslib發送消息
我正在使用smslib示例中指定的基本類,但總是有一些錯誤,指出沒有來自設備的響應。由於使用USB端口,我添加了輪詢參數,但無濟於事。 Commtest Utility能夠連接到相同的端口,所以我不認爲端口號是一個問題。
堆棧跟蹤:
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.TimeoutException: No response from device.
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)
代碼:
public class SendMessage {
public void doIt() throws Exception
{
SerialModemGateway gateway = new SerialModemGateway("modem.com4", "COM4", 115200, "Simado", "GDT11");
try {
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());
gateway.setInbound(false);
gateway.setOutbound(true);
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("+919560734413");
Service.getInstance().setOutboundMessageNotification(outboundNotification);
Service.getInstance().addGateway(gateway);
Service.getInstance().S.SERIAL_NOFLUSH = true;
Service.getInstance().S.SERIAL_POLLING = true;
Service.getInstance().S.SERIAL_POLLING_INTERVAL = 200;
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("+918095065000", "Hello from SMSLib!");
Service.getInstance().sendMessage(msg);
System.out.println(msg);
} finally {
gateway.stopGateway();
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();
}
}
}