我正在使用Simado GDT11调制解调器和Prolific USB转串口驱动程序。新连接将显示在我的设备管理器中>端口列表。但是,我无法使用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();
}
}
}
答案 0 :(得分:1)
我解决了这个问题。代码是正确的。显然,使用漫游的SIM卡并不是最好的选择。我转移到本地SIM卡,邮件已发送。
此外,我正在使用USB到COM端口仿真器(Prolific USB-Serial),因为调制解调器在运行代码时没有初始化。
为了解决这个问题,我在服务器启动时运行了初始化命令(AT + CMGF = 1
)。