请教一个问题,为什么CommPortIdentifier.getPortIdentifiers()方法取出的值为空呢??   
  代码如下   
    
    
  import   java.util.Enumeration;   
    
  import   javax.comm.CommPortIdentifier;   
    
  /*   
    *   Created   on   2006-4-24   
    *   
    *   TODO   To   change   the   template   for   this   generated   file   go   to   
    *   Window   -   Preferences   -   Java   -   Code   Style   -   Code   Templates   
    */   
    
  /**   
    *   @author   Administrator   
    *   
    *   TODO   To   change   the   template   for   this   generated   type   comment   go   to   
    *   Window   -   Preferences   -   Java   -   Code   Style   -   Code   Templates   
    */   
  public   class   aa   {   
    
  public   static   void   main(String[]   args)   {   
  Enumeration   en   =   CommPortIdentifier.getPortIdentifiers();   
    
  CommPortIdentifier   portId;   
    
    
  while(en.hasMoreElements())   
  {   
  portId   =   (CommPortIdentifier)   en.nextElement();   
  /*如果端口类型是串口,则打印出其端口信息*/   
  if(portId.getPortType()   ==   CommPortIdentifier.PORT_SERIAL)   
  {   
  System.out.print(portId.getName());}   
  }   
    
    
  }   
  }   
      小弟在线等。
 
  小弟原本是做网站开发。换了个工作,第一天就让我写串口通讯。  今天第一天上班啊!帮忙啊!   我在线等

解决方案 »

  1.   

    用javax.comm最常见的就是dll配置错误。
    引用以下别人的文章:
    “    将下载的文件解压缩后,在\javacomm20-win32\commapi目录下有必需的三个文件comm.jar,javax.comm. properties和win32comm.dll。将文件comm.jar拷贝到%JAVA_HOME%\jre\lib\ext;文件 javax.comm. properties拷贝到%JAVA_HOME%\jre\lib; 文件win32comm.dll拷贝到%JAVA_HOME%\bin。注意%JAVA_HOME%是jdk的路径,而非jre。”
      

  2.   

    javax.comm这个项目已经停止维护了,换用RXTX包会比较好一点,而且配置方便,你这个问题我碰到过,是因为配置的问题,最好是换用RXTX包,换了这个以后代码也不需要修改,因为他是按照javax.comm的标准做的。
    另外在做串口通讯的项目,先准备一个测试的执行程序,网上有很多这样的程序,搜索“串口测试”,有一大堆,或者使用Windows自带的工具,“超级终端”,在附件->通讯中可以找到它,祝你好运!