转载自:http://blog.sina.com.cn/s/blog_667528fd0100yuva.html
- //查看本机上所有的串口
- import java.util.Enumeration;
- import javax.comm.CommPortIdentifier;
- public class ViewPorts {
- public void listPorts(){
- Enumeration enumeration=CommPortIdentifier.getPortIdentifiers();
- CommPortIdentifier portId;
- while(enumeration.hasMoreElements()){
- portId=(CommPortIdentifier)enumeration.nextElement();
- if(portId.getPortType()==CommPortIdentifier.PORT_SERIAL){
- System.out.println("port name :"+portId.getName());
- }
- }
- }
- public static void main(String[] args) {
- ViewPorts vPorts=new ViewPorts();
- vPorts.listPorts();
- }
- }
阅读(6054) | 评论(0) | 转发(0) |