如何将EclipseIndigo与Java通信API结合使用

如何将EclipseIndigo与Java通信API结合使用,java,serial-port,Java,Serial Port,我正在Eclipse中使用Java通信API。这是我的示例程序,用于获取所有可用的通信端口,但该程序退出,因为CommPortIdentifier.getPortIdentifiers()不返回任何内容枚举enu_端口为空,程序退出 我已采取的步骤: 我已将smart Hopper连接到主机 将win32com.dll文件放入system32文件夹,并添加到eclipse项目中 在eclipse项目中添加javax.comm.properties文件 在构建路径中添加了com.jar。我的系统

我正在Eclipse中使用Java通信API。这是我的示例程序,用于获取所有可用的通信端口,但该程序退出,因为
CommPortIdentifier.getPortIdentifiers()
不返回任何内容<代码>枚举enu_端口为空,程序退出

我已采取的步骤:

  • 我已将smart Hopper连接到主机
  • 将win32com.dll文件放入system32文件夹,并添加到eclipse项目中
  • 在eclipse项目中添加javax.comm.properties文件
  • 在构建路径中添加了com.jar。我的系统是32位的,操作系统是windows 7
如果任何步骤不正确,请提供使用Eclipse Indigo和Java通信API的步骤

import java.util.Enumeration;

import javax.comm.CommPortIdentifier;

class GetAvailableComPorts {

    public static void getComPorts(){
        String     port_type;
        Enumeration  enu_ports  = CommPortIdentifier.getPortIdentifiers();

        while (enu_ports.hasMoreElements()) {
            CommPortIdentifier port_identifier = (CommPortIdentifier) enu_ports.nextElement();

            switch(port_identifier.getPortType()){
                case CommPortIdentifier.PORT_SERIAL:
                    port_type   =   "Serial";
                    break;
                case CommPortIdentifier.PORT_PARALLEL:
                    port_type   =   "Parallel";
                    break;

                default:
                    port_type   =   "Unknown";
                    break;
            }

            System.out.println("Port : "+port_identifier.getName() +" Port type : "+port_type);
        }
    }
    public static void main(String[] args) {
        getComPorts();
    }
}

这个问题肯定与Eclipse无关。你用的是什么序列库?它似乎不是RXTX。你有没有尝试过其他的库,比如,或者?这是否解决了您的问题?

原始的JavaComm API非常旧,不再受支持,您可能需要研究其他替代方案,如RXTX?除此之外:您是否向项目中添加了本机库(DLL)?有关如何执行此操作的详细信息,请参阅。。。