FileDocCategorySizeDatePackage
NamedPortLister.javaAPI DocExample760Sun Mar 28 19:09:36 BST 1999None

NamedPortLister.java

import javax.comm.*;


public class NamedPortLister {

  public static void main(String[] args) {

    // list serial (COM) ports
    try {
      int portNumber = 1;
      while (true) {
        CommPortIdentifier.getPortIdentifier("COM" + portNumber);
        System.out.println("COM" + portNumber);
        portNumber++;
      }
    }
    catch (NoSuchPortException e) {
      // break out of loop
    }

    // list parallel (LPT) ports
    try {
      int portNumber = 1;
      while (true) {
        CommPortIdentifier.getPortIdentifier("LPT" + portNumber);
        System.out.println("LPT" + portNumber);
        portNumber++;
      }
    }
    catch (NoSuchPortException e) {
      // break out of loop
    }

  }

}