Java comm API 不显示任何端口

标签 java eclipse

我使用了 javax.comm 库,但它在 x64 系统上不起作用,所以我尝试了 rxtx。我已将 rxtxSerial 和 rxtxParallel dll 文件放入 C:\Program Files\Java\jre1.8.0_51\bin 中,并将 RXTXcomm jar 放入 C:\Program Files\Java\jre1.8.0_51\lib\ext 中,并放入 Eclipse 的 builde 路径中。这是我的代码,它绝对没有显示任何消息,因为他可能没有找到任何端口。一些帮助将不胜感激,因为我已经困惑这个问题一段时间了。我不知道这是否有任何关系,但在设备管理中我没有任何端口标题或任何相关内容。我使用的是 Windows 8.1 64 位。谢谢。

import java.util.Enumeration;    
import gnu.io.CommPort;
import gnu.io.CommPortIdentifier;
import gnu.io.PortInUseException;
public class JavaPOS {
    public static void main(String[] args){

        Enumeration port_list = CommPortIdentifier.getPortIdentifiers ();
          while (port_list.hasMoreElements ()) {                 // Get the list of ports
                  CommPortIdentifier port_id =
                          (CommPortIdentifier) port_list.nextElement ();

                  // Find each ports type and name
                  if (port_id.getPortType () == CommPortIdentifier.PORT_SERIAL)
                  {
                      System.out.println ("Serial port: " + port_id.getName ());
                  }
                  else if (port_id.getPortType () == CommPortIdentifier.PORT_PARALLEL)
                  {
                      System.out.println ("Parallel port: " + port_id.getName ());
                  } else
                      System.out.println ("Other port: " + port_id.getName ());

                  // Attempt to open it
                  try {
                      CommPort port = port_id.open ("PortListOpen",20);
                      System.out.println ("  Opened successfully");
                      port.close ();
                  }
                  catch  (PortInUseException pe)
                  {
                      System.out.println ("  Open failed");
                      String owner_name = port_id.getCurrentOwner ();
                      if (owner_name == null)
                          System.out.println ("  Port Owned by unidentified app");
                      else
                          // The owner name not returned correctly unless it is
                          // a Java program.
                          System.out.println ("  " + owner_name);
                  }
             }


    }
}

最佳答案

我通过安装这个找到了解决方案:http://www.ftdichip.com/Drivers/VCP.htm

关于Java comm API 不显示任何端口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31766013/

相关文章:

Java 正则表达式字符串 : Check if ip:port string contains a valid IPv4 or DNS address

java - Java 的 -Xms 和 -Xmx 选项的速度权衡

java - IN Thread-Safe如何写Map等线程读取

java - 无法在 Eclipse 上使用 Derby 插件

java - 使用 Gradle 运行 JUnit 时设置自定义安全管理器

java - Solr DataImportHandler - Oracle 日期 - 夏令时

linux - 如何阻止 Eclipse (EPIC Perl) 将 DOS CR/LF 添加到我的 Perl 脚本中?

java - Eclipse热键-快捷方式修改?我的意思是实际的热键命令,而不是键绑定(bind)

eclipse - 如何将 Armadillo 与 Eclipse 链接

java - 应该为 EE 开发人员安装 Eclipse IDE 还是为 Java 开发人员安装普通 IDE?