求助。。。java短信开发程序找不到串口信息
如题,在做一个小程序要用到收发短信。。。网上买的易做图。用java开发。。。设备事先用VB程序测试过可以收发短信。。。
现在用java程序做,找不到计算机串口信息。
关于环境变量和配置,都按网上找得资料配置好的。不能确定完全正确。
import java.util.Enumeration;
import javax.comm.CommPortIdentifier;
public class Test1 {
public static void main(String[] args){
System.out.println("start");
CommPortIdentifier portId;
Enumeration en = org.smslib.helper.CommPortIdentifier.getPortIdentifiers();
while(en.hasMoreElements()){
System.out.println("enter");
portId = (CommPortIdentifier)en.nextElement();
if(portId.getPortType()==CommPortIdentifier.PORT_SERIAL){
System.out.println(portId.getName());
}
}
}
}
这是查看计算机串口信息的代码,没有任何返回值。
import org.smslib.IOutboundMessageNotification;
import org.smslib.OutboundMessage;
import org.smslib.Service;
import org.smslib.Message.MessageEncodings;
import org.smslib.modem.SerialModemGateway;
/**
* 短信发送测试类
*
* @author mazq
*
*/
public class SMSUtil {
public class OutboundNotification implements IOutboundMessageNotification {
public void process(String gatewayId, OutboundMessage msg) {
System.out.println("enter------------");
System.out.println("Outbound handler called from Gateway: "
+ gatewayId);
System.out.println(msg);
}
}
public void sendSMS(String mobilePhones, String content) {
System.out.println(mobilePhones + "--" + content);
Service srv;
OutboundMessage msg;
OutboundNotification outboundNotification = new OutboundNotification();
srv = new Service();
SerialModemGateway gateway = new SerialModemGateway("modem.com1",
"COM1", 115200, "wavecom", "9600");
gateway.setInbound(true);
gateway.setOutbound(true);
gateway.setSimPin("0000");
gateway.setOutboundNotification(outboundNotification);
srv.addGateway(gateway);
System.out.println("初始化成功,准备开启服务");
try {
srv.startService();
System.out.println("服务启动成功");
String[] phones = mobilePhones.split(",");
for (int i = 0; i < phones.length; i++) {
msg = new OutboundMessage(phones[i], content);// 手机号码,和短信内容
msg.setEncoding(MessageEncodings.ENCUCS2);// 这句话是发中文短信必须的
srv.sendMessage(msg);
System.out.println(phones[i] + " == " + content);
}
srv.stopService();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
SMSUtil util = new SMSUtil();
util.sendSMS("135********", "测试短信");
}
}
这个是发送短信的程序。。。运行报错
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)
这是报错信息。。。
CSDN上的各位大牛们,帮帮忙吧。。。困扰好几天了。。。。 --------------------编程问答-------------------- 怎么都没人看这个帖子啊 --------------------编程问答-------------------- 来个人来看看啊。。。 --------------------编程问答-------------------- 解决了。。。JDK用的myeclipse默认的版本,要使用自己安装的版本。。。
可惜不能结贴啊。。。
补充:Java , Java EE