0

我正在尝试使用 SMSLib 从我的电脑向手机发送短信。我正在使用我的诺基亚 5130 GSM 手机发送消息,但它无法正常工作。这是我正在使用的代码。

package sms;
import org.smslib.AGateway;
import org.smslib.IOutboundMessageNotification;
import org.smslib.Library;
import org.smslib.Message.MessageEncodings;
import org.smslib.OutboundMessage;
import org.smslib.Service;
import org.smslib.modem.SerialModemGateway;

public class SendMessage
{
public void doIt() throws Exception {
 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());
 SerialModemGateway gateway = new SerialModemGateway("modem.com12", "COM12", 115200, "Nokia", "Nokia 5130 XPressMusic USB Modem");


gateway.setInbound(true);
gateway.setOutbound(true);
gateway.setSimPin("0000");

gateway.setSmscNumber("+919886005444");
Service.getInstance().setOutboundMessageNotification(outboundNotification);
Service.getInstance().addGateway(gateway);
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("+917829903913", "Sample msg");
msg.setEncoding(MessageEncodings.ENC7BIT);
msg.setSrcPort(0);
msg.setDstPort(66500);
Service.getInstance().sendMessage(msg);

System.out.println(msg);

System.out.println("Now Sleeping - Hit <enter> to terminate.");
System.in.read();
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();
}
}
}

这是我收到的错误消息。请帮忙,因为我对这些了解不多。

run:
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.
This software is distributed under the terms of the Apache v2.0 License.
Web Site: http://smslib.org
Version: 3.5.1
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.GatewayException: Comm library exception: java.lang.RuntimeException: javax.comm.PortInUseException: Port currently owned by Unknown Windows Application
    at org.smslib.modem.SerialModemDriver.connectPort(SerialModemDriver.java:102)
    at org.smslib.modem.AModemDriver.connect(AModemDriver.java:114)
    at org.smslib.modem.ModemGateway.startGateway(ModemGateway.java:189)
    at org.smslib.Service$1Starter.run(Service.java:276)
 BUILD SUCCESSFUL (total time: 6 seconds)
4

3 回答 3

1

有一个与您的手机相关的应用程序(如诺基亚套件)可以在 PC 上运行,并在将手机连接到 PC 时与您的手机建立连接,请确保关闭所有此类应用程序并使您的连接只是物理连接。

于 2013-06-20T08:51:03.243 回答
1

确保没有其他应用程序正在侦听COM12javax.comm.PortInUseException:发生是因为您的代码尝试注册COM12不可用。

将所有必要的 jars 和 dll 文件复制到正确的位置后,这应该可以工作。您还需要一个 32 位的 JDK,因此如果您没有其他 JDK,您可能需要下载 32 位的 JDKjava.lang.UnsatisfiedLinkError:

我运行了这段代码,它可以工作。还要记住将 setSmscNumber 设置为您的 SIM 提供商,看起来您仍然拥有默认值(示例一)

干杯铅

于 2012-08-17T16:07:38.253 回答
0

安装 32 位 java 版本后,它对我有用。还要确保使用正确的端口。com11 在我的情况下。

在此处输入图像描述

于 2016-07-01T01:04:01.807 回答