代码如下:// SendMessage.java - Sample application.
//
// This application shows you the basic procedure for sending messages.
// You will find how to send synchronous and asynchronous messages.
//
// For asynchronous dispatch, the example application sets a callback
// notification, to see what's happened with messages.
import org.smslib.IOutboundMessageNotification;
import org.smslib.Library;
import org.smslib.OutboundMessage;
import org.smslib.Service;
import org.smslib.Message.MessageEncodings;
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", "COM1", 9600, "wavecom", "1111");
gateway.setInbound(true);
gateway.setOutbound(true);
gateway.setSimPin("0000");
//gateway.setOutboundNotification(outboundNotification);
srv.addGateway(gateway);
srv.startService();
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() + "%");
System.out.println(" Battery Level: " + gateway.getBatteryLevel() + "%");
System.out.println();
// Send a message synchronously.
msg = new OutboundMessage("15210121770", "这个是用java发的中文短信!");//手机号码,和短信内容
msg.setEncoding(MessageEncodings.ENCUCS2);//这句话是发中文短信必须的
srv.sendMessage(msg);
System.out.println(msg);
System.out.println("Now Sleeping - Hit <enter> to terminate.");
System.in.read();
srv.stopService();
}public class OutboundNotification implements IOutboundMessageNotification
{
public void process(String gatewayId, OutboundMessage msg)
{
System.out.println("Outbound handler called from Gateway: " + gatewayId);
System.out.println(msg);
}
}public static void main(String args[])
{
SendMessage app = new SendMessage();
try
{
app.doIt();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}报错信息如下:
Example: Send message from a serial gsm modem.
SMSLib: A Java API library for sending and receiving SMS via a GSM modem
or other supported gateways.
Web Site: http://smslib.org
This software is distributed under the terms of the Apache v2.0 License.
Version: 3.3.0-b2
org.smslib.GatewayException: Comm library exception: java.lang.reflect.InvocationTargetException
JDK_HOME的环境配置已经配好。但还是出现上面的错误,请大家帮忙!
解决方案 »
- java读取excel中日期格式问题!!!
- 求一个ajax json jsp样例
- 关于ajax中文乱码的问题,头疼啊 !get方式返回的是乱码,post方式正确
- struts导出excel问题,请教各位,先谢谢了!!!!!!!!!
- Servlet配置问题
- java中导入Excel文件问题
- hibernate+struts一个非常奇怪的出错,想了半天也不知什么原因
- 关于流媒体测试方案,谁能帮忙!!JMF是否可以做这类测试,希望讨论
- 一个关于JAVA I/O中的 dataInputStream 的问题
- 高手进来,通过XPath对xml文件进行修改!
- 《求助》迷茫,求大师指点迷津<大家进来指点一下>
- rmi接口是实现
现在是程序没有问题了,也能够打开端口了。但是出现了下面的问题。org.smslib.TimeoutException: No response from device.
at org.smslib.modem.AModemDriver$CharQueue.get(AModemDriver.java:503)
at org.smslib.modem.AModemDriver.getResponse(AModemDriver.java:295)
at org.smslib.modem.athandler.ATHandler.getSimStatus(ATHandler.java:132)
at org.smslib.modem.AModemDriver.connect(AModemDriver.java:129)
at org.smslib.modem.ModemGateway.startGateway(ModemGateway.java:185)
at org.smslib.Service$1Starter.run(Service.java:257)
at org.smslib.modem.SerialModemDriver.connectPort(SerialModemDriver.java:93)
at org.smslib.modem.AModemDriver.connect(AModemDriver.java:106)
at org.smslib.modem.ModemGateway.startGateway(ModemGateway.java:111)
at org.smslib.Service$1Starter.run(Service.java:227)
org.smslib.GatewayException: Comm library exception: java.lang.reflect.InvocationTargetException
at org.smslib.modem.SerialModemDriver.connectPort(SerialModemDriver.java:93)
at org.smslib.modem.AModemDriver.connect(AModemDriver.java:106)
at org.smslib.modem.ModemGateway.startGateway(ModemGateway.java:111)
at org.smslib.Service$1Starter.run(Service.java:227)
环境也配置好了。