简体   繁体   English

如何通过Java Communication API使用Eclipse Indigo

[英]How to use Eclipse Indigo with Java communication API

I am working with Java communication API in Eclipse. 我正在Eclipse中使用Java通信API。 This is my sample program to get all available ports for communication but the program exits because CommPortIdentifier.getPortIdentifiers() doesn't return anything. 这是我的示例程序,用于获取所有可用的端口进行通信,但由于CommPortIdentifier.getPortIdentifiers()不返回任何内容,因此该程序退出。 Enumeration enu_ports is null and program exits. Enumeration enu_ports为null,程序退出。

Steps I have done: 我已完成的步骤:

  • I have connected my smart hoper to the host. 我已经将聪明的希望寄托人与主持人联系了。
  • Put win32com.dll file system32 folder and also added in eclipse project 将win32com.dll文件放入system32文件夹,并同时在eclipse项目中添加
  • Add javax.comm.properties file in eclipse project 在Eclipse项目中添加javax.comm.properties文件
  • Added com.jar to the build path my system is 32 bit and os is windows 7 将com.jar添加到构建路径中,我的系统是32位,而os是Windows 7

If any step is incorrect please provide steps to use Eclipse Indigo with Java communication API. 如果任何步骤不正确,请提供将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();
    }
}

The problem most certainly isn't related to Eclipse. 问题肯定与Eclipse无关。 What serial library are you using? 您正在使用什么串行库? It doesn't seem to be RXTX. 似乎不是RXTX。 Did you try alternative libraries, like PureJavacomm , or NrJavaSerial ? 您是否尝试过其他库,例如PureJavacommNrJavaSerial Does that resolve your issue? 这样可以解决您的问题吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM