【问题标题】:Java for smslib: building error for sending message using smslibsmslib 的 Java:使用 smslib 发送消息的构建错误
【发布时间】:2013-10-09 17:08:11
【问题描述】:

我为我的项目安装了 lib smslib,用于在 lib smslib-v3.5.3 中发送消息示例。 我按照网站 smslib.org 上的所有说明进行 lib 设置。 但是我发现了错误。

 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.com9", "COM9",                 9600, "InterCEL", "");
    gateway.setInbound(true);
    gateway.setOutbound(true);
    gateway.setSimPin("0000");
    gateway.setSmscNumber("+84920210006");
    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("0987623500", "Hello");
    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)
    {
    }
}

public static void main(String args[])
{
    SendMessage app = new SendMessage();
    try
    {
        app.doIt();
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }
}

}

错误:

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 org.smslib
    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:277)

请帮帮我。 非常感谢

【问题讨论】:

    标签: java smslib


    【解决方案1】:

    自从我上次使用 JavaCOM 已经有好几年了,但这里是 ListPorts 测试应用程序。看看您是否可以在虚拟 com 端口中看到任何设备。我的 SMS 发送+接收应用程序使用 smslib-3.4.0.jar 版本和 rxtx 库。

    我一直在 Linux 和 Windows 中使用 RXTX .jar+.dll/.so 文件。发现一些设备+操作系统无法正常使用 JavaCOM 标准 dll 库。
    http://rxtx.qbang.org/wiki/index.php/Download

    要使用的文件
    ListPorts.bat
    lib/myapp.jar(或使用 ./classes 类路径)
    lib/librxtxSerial.so
    lib/logging.properties
    lib/RXTXcomm.jar
    lib/rxtxSerial.dll(32 位,从未使用过 64 位库)

    lib/logging.properties

    ############################################################
    #   Default Logging Configuration File
    #
    # You can use a different file by specifying a filename
    # with the java.util.logging.config.file system property.  
    # For example java -Djava.util.logging.config.file=myfile
    ############################################################
    
    ############################################################
    #   Global properties
    ############################################################
    
    # "handlers" specifies a comma separated list of log Handler 
    # classes.  These handlers will be installed during VM startup.
    # Note that these classes must be on the system classpath.
    # By default we only configure a ConsoleHandler, which will only
    # show messages at the INFO and above levels.
    handlers= java.util.logging.ConsoleHandler
    ##handlers= java.util.logging.FileHandler, java.util.logging.ConsoleHandler
    
    # Default global logging level.
    # This specifies which kinds of events are logged across
    # all loggers.  For any given facility this global level
    # can be overriden by a facility specific level
    # Note that the ConsoleHandler also has a separate level
    # setting to limit messages printed to the console.
    .level= ALL
    
    ############################################################
    # Handler specific properties.
    # Describes specific configuration info for Handlers.
    ############################################################
    
    # default file output is in user's home directory.
    ##java.util.logging.FileHandler.pattern = %h/java%u.log
    java.util.logging.FileHandler.pattern = logjava.log
    java.util.logging.FileHandler.limit = 50000
    java.util.logging.FileHandler.count = 1
    ##java.util.logging.FileHandler.formatter = java.util.logging.XMLFormatter
    java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter
    
    # Limit the message that are printed on the console to INFO and above.
    java.util.logging.ConsoleHandler.level = ALL
    java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
    
    
    ############################################################
    # Facility specific properties.
    # Provides extra control for each logger.
    # INFO, FINER, FINEST, ALL
    ############################################################
    
    # For example, set the com.xyz.foo logger to only log SEVERE
    # messages:
    org.smslib.level = ALL
    #org.ajwcc.level = ALL
    

    ListPorts.bat

    set cp=./lib/myapp.jar;./lib/RXTXcomm.jar
    set lib=./lib
    java.exe -cp %cp%  -Djava.library.path=%lib%  -Djava.util.logging.config.file=%lib%/logging.properties  com.myapp.ListPorts
    pause
    

    src/com/myapp/ListPorts.java

    package com.myapp.ListPorts
    
    //import javax.comm.*; // You my try using this, it might work as well
    import gnu.io.*;  // RXTX com replacement
    import java.util.Enumeration;
    
    public class ListPorts {
    
        @SuppressWarnings("unchecked")
        public static void main(String args[]) throws Exception {
            // List portNames
            Enumeration<CommPortIdentifier> ports = CommPortIdentifier.getPortIdentifiers();
            while (ports.hasMoreElements()) {
                CommPortIdentifier portId = ports.nextElement();
                String s = getPortInfo(portId);
                System.out.println(s);
            }
    
            // test open-close methods on each port
            ports = CommPortIdentifier.getPortIdentifiers();
            while (ports.hasMoreElements()) {
                CommPortIdentifier portId = (CommPortIdentifier)ports.nextElement();
                CommPort port = null;
                try {
                    System.out.print("open " + portId.getName());
                    port = portId.open(ListPorts.class.getName(), 2000);
                    port.close();
                    System.out.println("...closed");                
                } catch (Exception ex) {
                    ex.printStackTrace();
                    if (port != null)
                        try { port.close(); } catch (Exception e) { }
                }
            }
        }
    
        private static String getPortInfo(CommPortIdentifier portid) {
            StringBuilder sb = new StringBuilder();
            sb.append(portid.getName());
            sb.append(", ");
            sb.append("portType: ");
            if (portid.getPortType() == CommPortIdentifier.PORT_SERIAL)
                sb.append("serial");
            else if (portid.getPortType() == CommPortIdentifier.PORT_PARALLEL)
                sb.append("parallel");
            else
                sb.append("unknown");
            return sb.toString();
        }
    
    }
    

    【讨论】:

    • 请根据 SO 协议接受答案,如果它对您的解决方案有任何好处。如果您找到了自己的解决方案,请让每个人都知道。发表您自己的答案,描述解决方案并接受它。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多