gpt4 book ai didi

java - 无法使用 smslib 发送消息

转载 作者:行者123 更新时间:2023-12-01 14:04:50 28 4
gpt4 key购买 nike

我正在使用 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();
}
}
}

最佳答案

我解决了这个问题。代码是正确的。显然,使用漫游的 SIM 卡并不是最好的主意。我切换到本地 SIM 卡,消息已发送。

此外,我使用的是 USB 转 COM 端口模拟器 ( Prolific USB-Serial ),因此调制解调器在运行代码时未初始化。

为了解决这个问题,我在服务器启动时运行了初始化命令(AT + CMGF = 1)。

关于java - 无法使用 smslib 发送消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18985749/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com