2012-06-28 50 views
1

我想知道是否有人知道我为什么不能使用E226 3g调制解调器发送短信。我配置了示例类,我设置了调制解调器型号,PIN和Smsc编号。SMSLib不使用E226 3G调制解调器发送短信

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.com1", "COM4", 9600, "Huawei", "E226"); 
     gateway.setInbound(true); 
     gateway.setOutbound(true); 
     gateway.setSimPin("1010"); 
     // Explicit SMSC address set is required for some modems. 
     // Below is for VODAFONE GREECE - be sure to set your own! 
     gateway.setSmscNumber("+555181136200"); 
     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("+556199655944", "Hello from SMSLib!"); 
     Service.getInstance().sendMessage(msg); 
     System.out.println(msg); 
     // Or, send out a WAP SI message. 
     //OutboundWapSIMessage wapMsg = new OutboundWapSIMessage("306974000000", new URL("http://www.smslib.org/"), "Visit SMSLib now!"); 
     //Service.getInstance().sendMessage(wapMsg); 
     //System.out.println(wapMsg); 
     // You can also queue some asynchronous messages to see how the callbacks 
     // are called... 
     //msg = new OutboundMessage("309999999999", "Wrong number!"); 
     //srv.queueMessage(msg, gateway.getGatewayId()); 
     //msg = new OutboundMessage("308888888888", "Wrong number!"); 
     //srv.queueMessage(msg, gateway.getGatewayId()); 
     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.2 
0  2012-06-28 19:08:32,652 [main] INFO org.smslib.Service - 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 
3  2012-06-28 19:08:32,655 [main] INFO org.smslib.Service - Version: 3.5.2 
3  2012-06-28 19:08:32,655 [main] INFO org.smslib.Service - JRE Version: 1.7.0_05 
5  2012-06-28 19:08:32,657 [main] INFO org.smslib.Service - JRE Impl Version: 23.1-b03 
Exception in thread "Thread-3" java.lang.ExceptionInInitializerError 
5  2012-06-28 19:08:32,657 [main] INFO org.smslib.Service - O/S: Windows 7/amd64/6.1 
8  2012-06-28 19:08:32,660 [main] DEBUG org.smslib.threading.AServiceThread - Initialized. 
8  2012-06-28 19:08:32,660 [NotifyQueueManager] DEBUG org.smslib.threading.AServiceThread - Running... 
8  2012-06-28 19:08:32,660 [NotifyQueueManager] DEBUG org.smslib.notify.NotifyQueueManager$NotificationQueueManager - NotifyQueueManager running... 
9  2012-06-28 19:08:32,661 [main] INFO org.smslib.queues.DefaultQueueManager - Queue directory not defined. Queued messages will not be saved to filesystem. 
9  2012-06-28 19:08:32,661 [main] DEBUG org.smslib.threading.AServiceThread - Initialized. 
10  2012-06-28 19:08:32,662 [DelayQueueManager] DEBUG org.smslib.threading.AServiceThread - Running... 
10  2012-06-28 19:08:32,662 [DelayQueueManager] DEBUG org.smslib.queues.AbstractQueueManager$DelayQueueManager - DelayQueueManager running... 
10  2012-06-28 19:08:32,662 [main] DEBUG org.smslib.threading.AServiceThread - Initialized. 
    at org.smslib.modem.SerialModemDriver.connectPort(SerialModemDriver.java:69) 
    at org.smslib.modem.AModemDriver.connect(AModemDriver.java:114) 
10  2012-06-28 19:08:32,662 [WatchDog] DEBUG org.smslib.threading.AServiceThread - Running... 
    at org.smslib.modem.ModemGateway.startGateway(ModemGateway.java:189) 
11  2012-06-28 19:08:32,663 [Thread-3] INFO org.smslib.modem.ModemGateway - GTW: modem.com1: Starting gateway, using Huawei E226 AT Handler. 
    at org.smslib.Service$1Starter.run(Service.java:276) 
Caused by: java.lang.RuntimeException: CommPortIdentifier class not found 
11  2012-06-28 19:08:32,663 [Thread-3] INFO org.smslib.modem.SerialModemDriver - GTW: modem.com1: Opening: COM4 @9600 
    at org.smslib.helper.CommPortIdentifier.<clinit>(CommPortIdentifier.java:76) 
    ... 4 more 
15010 2012-06-28 19:08:47,662 [WatchDog] DEBUG org.smslib.threading.AServiceThread - Running... 
30011 2012-06-28 19:09:02,663 [WatchDog] DEBUG org.smslib.threading.AServiceThread - Running... 
45012 2012-06-28 19:09:17,664 [WatchDog] DEBUG org.smslib.threading.AServiceThread - Running... 
60012 2012-06-28 19:09:32,664 [WatchDog] DEBUG org.smslib.threading.AServiceThread - Running... 
75013 2012-06-28 19:09:47,665 [WatchDog] DEBUG org.smslib.threading.AServiceThread - Running... 
90014 2012-06-28 19:10:02,666 [WatchDog] DEBUG org.smslib.threading.AServiceThread - Running... 

这就是我得到了好几个小时。任何想法为什么不起作用?

回答

2

您缺少javax.comm。 Windows上的javax.comm的情况有点乱,smslib installation instructions建议使用rxtx,并指向Cloudhopper's page以获得Windows版本。获取该库,将其作为依赖项添加到您的项目中,并且应该全部设置好。

+0

我试过javacomm,但它不支持Win 7 64位,从cloudhopper页面的rxtx库有一个64位版本,效果很好。谢谢 – dextervip

+0

我有同样的问题,但在我的情况下,我已经做了所有这些步骤,所以,如果你知道另一个可能导致这个问题,请与我分享。 –

+1

@MuhammedRefaat请为您的问题创建一个新问题,不要将其作为评论加入其他问题。阅读[如何提问](http://stackoverflow.com/help/how-to-ask)发帖,了解如何创建一个好问题,毫无疑问,问题会很快得到解答。祝你好运! – fvu

3
Caused by: java.lang.RuntimeException: CommPortIdentifier class not found 

您错过了一个库,无论哪一个包含CommPortIdentifier。找出您需要的库并将其包含在类路径中。

+0

如果我包含所有的库并且仍然存在相同的问题,那么您有什么建议? –

0

您正在寻找通讯库。有两个库可以解决这个问题。

这里是代码片段会抛出这个错误:

try 
     { 
      classCommPortIdentifier = Class.forName("javax.comm.CommPortIdentifier"); 
     } 
     catch (ClassNotFoundException e1) 
     { 
      try 
      { 
       classCommPortIdentifier = Class.forName("gnu.io.CommPortIdentifier"); 
      } 
      catch (ClassNotFoundException e2) 
      { 
       throw new RuntimeException("CommPortIdentifier class not found"); 
      } 
     } 

因此,确保无论是gnu.io.CommPortIdentifierjavax.comm.CommPortIdentifier在你的类path.Also确保您添加本地rxtxSerial.dll为{JRE }/bin中/

gnu.io.CommPortIdentifier是从具有新包装 convension RXTX库。

最近发生了软件包名称更改,因此在使用RxTx库时会感到困惑。请得到上面的代码中的一些想法,把事情说清楚你

这里是什么,是在site提到:

RXTX 2.1是对RXTX主要开发分支。使用的命名空间是gnu.io.。除非您有任何具体原因,否则这是推荐的下载。如果您需要与javax.comm。*兼容,请下载RXTX 2.0,但请注意,此分支没有提供太多开发工作,因此您将错过主分支所获得的所有修复程序。*

+0

我有同样的提到的问题,但我做了所有必要的步骤和问题仍然存在,即使我尝试你的代码段并正确运行没有捕捉任何东西,会使用建议我另一种解决方案吗? –

+0

你有没有例外?那么请张贴它。 –

+0

不,我没有,它正常运行 –

相关问题