org.smslib.GatewayException:通信库异常:java.lang.RuntimeException:javax.comm.NoSuchPortException

org.smslib.GatewayException: Comm library exception: java.lang.RuntimeException: javax.comm.NoSuchPortException

我正在尝试使用 smslib api 发送消息,老实说,我对此知之甚少,所以我下载了一个示例项目并将库按照说明放在相应的位置。我的class发送消息是:

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.com4", "COM4", 9600, "", "");
            gateway.setInbound(true);
            gateway.setOutbound(true);
            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();
            OutboundMessage msg = new OutboundMessage("contact_num", "Hello from SMSLib!");
            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();
            }
    }

}

在执行行

                Service.getInstance().startService();

我得到一个例外:

org.smslib.GatewayException: Comm library exception: java.lang.RuntimeException: javax.comm.NoSuchPortException 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.ServiceStarter.run(Service.java:277)

嗯,这是必须发生的,因为我没有 GSM 调制解调器,所以我有几个问题。

  1. Can i turn my android phone into gsm modem.

  2. What does modem.com4 in SerialModemGateway("modem.com4", "COM4", 9600, "", ""); mean .

我搜索了很多关于如何将我的 phone 变成 gsm 调制解调器的方法,但没有成功。

对于问题#1:是的,我认为你可以做到。

对于问题#2(获取 COM 端口):OS 您使用的是哪个?对于 Windows -

  • 只需安装手机驱动程序,然后将手机连接到 PC。 (一般手机包盘里都有驱动。)
  • 然后从 windows 控制面板打开 "Phone and Modem"。
  • 然后单击 "Modems" 选项卡。现在您可以看到所有调制解调器及其 COM 编号。
  • 在您的应用程序中使用手机的 COM 端口。

如果您在"Phone and Modem"中看不到您的手机名称为调制解调器,则意味着您不能将您的手机用作GSM调制解调器。