Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2164780
  • 博文数量: 556
  • 博客积分: 11457
  • 博客等级: 上将
  • 技术积分: 5973
  • 用 户 组: 普通用户
  • 注册时间: 2011-02-24 22:33
文章分类

全部博文(556)

文章存档

2013年(22)

2012年(74)

2011年(460)

分类: Java

2012-06-27 09:43:23

转载自:http://blog.sina.com.cn/s/blog_667528fd0100yuva.html

点击(此处)折叠或打开

  1. //查看本机上所有的串口
  2. import java.util.Enumeration;
  3. import javax.comm.CommPortIdentifier;
  4. public class ViewPorts {
  5. public void listPorts(){
  6. Enumeration enumeration=CommPortIdentifier.getPortIdentifiers();
  7. CommPortIdentifier portId;
  8. while(enumeration.hasMoreElements()){
  9. portId=(CommPortIdentifier)enumeration.nextElement();
  10. if(portId.getPortType()==CommPortIdentifier.PORT_SERIAL){
  11. System.out.println("port name :"+portId.getName());
  12. }
  13. }
  14. }
  15. public static void main(String[] args) {
  16. ViewPorts vPorts=new ViewPorts();
  17. vPorts.listPorts();
  18. }
  19. }

阅读(6006) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~