FileDocCategorySizeDatePackage
CommPortLister.javaAPI DocExample1103Sun Feb 08 21:33:52 GMT 2004None

CommPortLister

public class CommPortLister extends Object
List the ports.
author
Ian F. Darwin, http://www.darwinsys.com/
version
$Id: CommPortLister.java,v 1.4 2004/02/09 03:33:51 ian Exp $

Fields Summary
Constructors Summary
Methods Summary
protected voidlist()
Ask the Java Communications API * what ports it thinks it has.

		// get list of ports available on this particular computer,
		// by calling static method in CommPortIdentifier.
		Enumeration pList = CommPortIdentifier.getPortIdentifiers();

		// Process the list.
		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);
			}
		}
	
public static voidmain(java.lang.String[] ap)
Simple test program.

		new CommPortLister().list();