CommPortIdentifier: getPortIdentifiers() : CommPortIdentifier « javax.comm « Java by API






CommPortIdentifier: getPortIdentifiers()

import java.util.Enumeration;

import javax.comm.CommPortIdentifier;

public class MainClass {
  public static void main(String[] ap) {
    Enumeration pList = CommPortIdentifier.getPortIdentifiers();
    while (pList.hasMoreElements()) {
      CommPortIdentifier cpi = (CommPortIdentifier) pList.nextElement();
      System.out.print("Port " + cpi.getName() + " ");
      if (cpi.getPortType() == CommPortIdentifier.PORT_SERIAL) {
        System.out.println("is a Serial Port: " + cpi);
      } else if (cpi.getPortType() == CommPortIdentifier.PORT_PARALLEL) {
        System.out.println("is a Parallel Port: " + cpi);
      } else {
        System.out.println("is an Unknown Port: " + cpi);
      }
    }
  }
}

           
       








Related examples in the same category

1.CommPortIdentifier.PORT_PARALLEL
2.CommPortIdentifier.PORT_SERIAL
3.CommPortIdentifier: getName()
4.CommPortIdentifier: getPortType()