Как определить, какой COM-порт подключен к USB-GSM-модему с помощью Java

У меня есть java-программа для отправки смс с помощью модема usb gsm. Мне нужно найти com-порт, к которому подключен модем usb gsm. Я погуглил и нашел код ниже.

import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
import java.util.Formatter;

import org.apache.log4j.Logger;
import org.smslib.helper.CommPortIdentifier;

import com.cubepro.general.CommonConstants;

import com.cubepro.util.SendMessage;

public class CommPortTester {
   private static final String _NO_DEVICE_FOUND = "  no device found";

   private final static Formatter _formatter = new Formatter(System.out);

   private static Logger log = Logger.getLogger(CommPortTester.class);

   static CommPortIdentifier portId;

   static Enumeration<CommPortIdentifier> portList;

   static int bauds[] = { 9600, 14400, 19200, 28800, 33600, 38400, 56000,
                          57600, 115200 };

   public static final String MAINCLASS = "org.smslib.Service";

   public CommPortTester() throws Exception {
      Class.forName(MAINCLASS);
   }

   /**
    * Wrapper around {@link CommPortIdentifier#getPortIdentifiers()} to be
    * avoid unchecked warnings.
    */
   private static Enumeration<CommPortIdentifier> getCleanPortIdentifiers() {
      return CommPortIdentifier.getPortIdentifiers();
   }

   public String testAndQualifyPort() throws Exception {
      String status = CommonConstants.MODEM_STATUS_ERROR;
      SendMessage sendMessage = new SendMessage();

      log.debug("\nSearching for devices...");
      portList = getCleanPortIdentifiers();

      while (portList.hasMoreElements()) {
         portId = portList.nextElement();
         if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
            _formatter.format("%nFound port: %-5s%n", portId.getName());
            try {
               if(portId.getName()
               boolean comPortSuccess = sendMessage.doIt(portId.getName());
               if(comPortSuccess == true){
                  return portId.getName();
               }
            } catch (final Exception e) {
               log.debug(" Modem error occured -",e);
            }
         }
      }
      log.debug("\nTest complete.");
      return status;
   }

   public static void main(String[]args){
      try{
      CommPortTester tester = new CommPortTester(); 
      tester.testAndQualifyPort();
      }catch(Exception e){
         e.printStackTrace();
      }
   }
}

В этом коде они импортируют два класса: import com.cubepro.general.CommonConstants; импортировать com.cubepro.util.SendMessage;

Но где я могу найти эти com.cubepro?


person Lakindu    schedule 05.10.2014    source источник
comment
Где вы «нашли» класс Logger в org.apache.log4j? Ответьте на этот вопрос, и, возможно, вы найдете ответ на свой вопрос.   -  person Sridhar    schedule 05.10.2014
comment
Я импортирую файл jar org.apache.log4j   -  person Lakindu    schedule 05.10.2014
comment
Итак, вам нужен файл jar, содержащий классы, которые вы ищете. Либо ищите такую ​​банку, либо сами пишите эти два класса. Возможно, человек тот, кто написал CommPortTester, также написал CommonConstants и SendMessage, но не поделился ими с вами. Кстати, вы импортируете класс/пакет, а не файл jar.   -  person Sridhar    schedule 05.10.2014