鄙人对串口一窍不通,查了资料,下了commapi,把别人的例子ctrl+c,ctrl+v后,死活没响应,郁闷~~,求高人指点
代码附上: import java.util.*;
import java.io.*;
import javax.comm.*;public class listenraw { public static void main(String argv[]) {
new listenraw().listPortChoices();
}
//此方法为从网上‘剽窃’而来
void listPortChoices() {
CommPortIdentifier portId;
Enumeration en = CommPortIdentifier.getPortIdentifiers();
// iterate through the ports.
while (en.hasMoreElements()) { //就是这句的执行结果为false,不解,我这机子不可能没串口啊
portId = (CommPortIdentifier) en.nextElement();
if (!(portId.getPortType() == CommPortIdentifier.PORT_SERIAL) ){
System.out.println(portId.getName());
}
}
}
}
代码附上: import java.util.*;
import java.io.*;
import javax.comm.*;public class listenraw { public static void main(String argv[]) {
new listenraw().listPortChoices();
}
//此方法为从网上‘剽窃’而来
void listPortChoices() {
CommPortIdentifier portId;
Enumeration en = CommPortIdentifier.getPortIdentifiers();
// iterate through the ports.
while (en.hasMoreElements()) { //就是这句的执行结果为false,不解,我这机子不可能没串口啊
portId = (CommPortIdentifier) en.nextElement();
if (!(portId.getPortType() == CommPortIdentifier.PORT_SERIAL) ){
System.out.println(portId.getName());
}
}
}
}
UP
http://www.programmerstudy.com/programme/java/20084/97.html
qq 78720264谢芹
email [email protected]