從List the ports:
import java.util.Enumeration;
import javax.comm.CommPortIdentifier;
/**
* 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 $
*/
public class CommPortLister {
/** Simple test program. */
public static void main(String[] ap) {
new CommPortLister().list();
}
/** Ask the Java Communications API * what ports it thinks it has. */
protected void list() {
// 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);
}
}
}
}
這段代碼是什麼,我一直在尋找,但該枚舉對象不與要素(getPortIdentifiers方法返回一個空枚舉)填充。有什麼想法嗎? – user3666782
嗯。在時尚之後在這裏工作。這檯筆記本電腦號稱有兩個並行端口...: $ java的CommPortLister 端口LPT1是一個並行端口:[email protected] 端口LPT2是一個並行端口:[email protected] 錯誤2打開註冊表項HARDWARE \ DEVICEMAP \ SERIALCOMM – DavidPostill
我使用了javaxcomm(http://en.sourceforge.jp/projects/sfnet_rcxtools/downloads/RCXTools/RCXTools%20v1.1/javaxcomm.zip/) – DavidPostill