<tfoot id='tH6Sb'></tfoot>
      <i id='tH6Sb'><tr id='tH6Sb'><dt id='tH6Sb'><q id='tH6Sb'><span id='tH6Sb'><b id='tH6Sb'><form id='tH6Sb'><ins id='tH6Sb'></ins><ul id='tH6Sb'></ul><sub id='tH6Sb'></sub></form><legend id='tH6Sb'></legend><bdo id='tH6Sb'><pre id='tH6Sb'><center id='tH6Sb'></center></pre></bdo></b><th id='tH6Sb'></th></span></q></dt></tr></i><div id='tH6Sb'><tfoot id='tH6Sb'></tfoot><dl id='tH6Sb'><fieldset id='tH6Sb'></fieldset></dl></div>

    1. <legend id='tH6Sb'><style id='tH6Sb'><dir id='tH6Sb'><q id='tH6Sb'></q></dir></style></legend>

          <bdo id='tH6Sb'></bdo><ul id='tH6Sb'></ul>
      1. <small id='tH6Sb'></small><noframes id='tH6Sb'>

      2. 使用 Java 自动检测连接到 USB GSM 调制解调器的 Com 端口

        时间:2024-08-24

            <i id='xCVNH'><tr id='xCVNH'><dt id='xCVNH'><q id='xCVNH'><span id='xCVNH'><b id='xCVNH'><form id='xCVNH'><ins id='xCVNH'></ins><ul id='xCVNH'></ul><sub id='xCVNH'></sub></form><legend id='xCVNH'></legend><bdo id='xCVNH'><pre id='xCVNH'><center id='xCVNH'></center></pre></bdo></b><th id='xCVNH'></th></span></q></dt></tr></i><div id='xCVNH'><tfoot id='xCVNH'></tfoot><dl id='xCVNH'><fieldset id='xCVNH'></fieldset></dl></div>

            <legend id='xCVNH'><style id='xCVNH'><dir id='xCVNH'><q id='xCVNH'></q></dir></style></legend>
              <bdo id='xCVNH'></bdo><ul id='xCVNH'></ul>
            • <small id='xCVNH'></small><noframes id='xCVNH'>

            • <tfoot id='xCVNH'></tfoot>

                    <tbody id='xCVNH'></tbody>

                  本文介绍了使用 Java 自动检测连接到 USB GSM 调制解调器的 Com 端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我编写了一个 Java 应用程序,它可以从 USB GSM 调制解调器读取和发送 SMS 消息.我正在使用 SMSLib(它使用 JavaCommAPI),它在 Windows 上运行.我需要传入调制解调器似乎已连接到的 COM PORT.

                  I wrote a Java application that reads and sends SMS messages from a USB GSM modem. I'm using SMSLib (which uses JavaCommAPI), and it runs on Windows. I need to pass in the COM PORT, that the modem appears to be connected to.

                  到目前为止,我一直在使用 Windows 设备管理器手动查找 COM PORT,并将其写入属性文件.我想知道是否有办法检测调制解调器以编程方式连接到哪个 COM PORT?

                  So far, I've been looking up the COM PORT manually using the Windows Device Manager, and write it into a properties file. I'm wondering if there's a way to detect which COM PORT, the modem is connected to programmatically?

                  1. 省去每次查找的麻烦
                  2. 如果我有时拔掉/重新插入它,端口号会发生变化

                  谢谢!!

                  推荐答案

                  package com.cubepro.util;
                  
                  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("
                  Searching 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("
                  Test complete.");
                        return status;
                     }
                  
                     public static void main(String[]args){
                        try{
                        CommPortTester tester = new CommPortTester(); 
                        tester.testAndQualifyPort();
                        }catch(Exception e){
                           e.printStackTrace();
                        }
                     }
                  }
                  

                  这篇关于使用 Java 自动检测连接到 USB GSM 调制解调器的 Com 端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:在ubuntu上用java进行串口识别 下一篇:使用Java &amp; 的串口通信Eclipse 中的 RXTX

                  相关文章

                  <small id='YEfTH'></small><noframes id='YEfTH'>

                    • <bdo id='YEfTH'></bdo><ul id='YEfTH'></ul>

                  1. <tfoot id='YEfTH'></tfoot>
                    <legend id='YEfTH'><style id='YEfTH'><dir id='YEfTH'><q id='YEfTH'></q></dir></style></legend>

                  2. <i id='YEfTH'><tr id='YEfTH'><dt id='YEfTH'><q id='YEfTH'><span id='YEfTH'><b id='YEfTH'><form id='YEfTH'><ins id='YEfTH'></ins><ul id='YEfTH'></ul><sub id='YEfTH'></sub></form><legend id='YEfTH'></legend><bdo id='YEfTH'><pre id='YEfTH'><center id='YEfTH'></center></pre></bdo></b><th id='YEfTH'></th></span></q></dt></tr></i><div id='YEfTH'><tfoot id='YEfTH'></tfoot><dl id='YEfTH'><fieldset id='YEfTH'></fieldset></dl></div>