日期:2014-05-20  浏览次数:20677 次

java串口问题,显示不出来
鄙人对串口一窍不通,查了资料,下了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());
  }
  }  
  }
}




------解决方案--------------------
这个方法是测试你本机有几个可以用的串口.看了下代码没错!说明你的电脑没有可用的串口
------解决方案--------------------
不会吧,公司给弄得联想的品牌机,怎么可能会没有呢
------解决方案--------------------
关注一下~
------解决方案--------------------
这方面不懂哦。。。。学习ING
UP
------解决方案--------------------
高手哦,真看不懂,想问一下,获取串口用在什么地方啊,指点一下啊,!!!!!!!谢谢
------解决方案--------------------
下面有介绍,还有需要的动态库及类库下载
http://www.programmerstudy.com/programme/java/20084/97.html