简体   繁体   中英

How to use Eclipse Indigo with Java communication API

I am working with Java communication API in Eclipse. This is my sample program to get all available ports for communication but the program exits because CommPortIdentifier.getPortIdentifiers() doesn't return anything. Enumeration enu_ports is null and program exits.

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
  • Add javax.comm.properties file in eclipse project
  • Added com.jar to the build path my system is 32 bit and os is windows 7

If any step is incorrect please provide steps to use Eclipse Indigo with Java communication 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. What serial library are you using? It doesn't seem to be RXTX. Did you try alternative libraries, like PureJavacomm , or NrJavaSerial ? Does that resolve your issue?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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