0

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();
    }
}
MPelletier
  • 16,256
  • 15
  • 86
  • 137

1 Answers1

1

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?

jawi
  • 360
  • 1
  • 7
  • The original JavaComm API is rather old and no longer supported, you might want to investigate alternatives, like RXTX? – jawi Feb 01 '13 at 13:52
  • Aside that: did you add the native library (the DLL) to your project? See http://stackoverflow.com/questions/957700/how-to-set-the-java-library-path-from-eclipse for details on how to do that... – jawi Feb 01 '13 at 13:54