2013-12-12 175 views
3

我想运行这个函数,我得到配置文本gnu.io.rxtx.properties窗口: gnu.io.rxtx.properties尚未检测到。Java串行端口配置gnu.io.rxtx.properties窗口

在此操作系统上没有检测端口的一致手段。在正确的端口枚举可能发生之前,有必要指出哪些端口在此系统上有效。请检查在此系统上有效的端口并选择保存。 当我点击保存在命令窗口中显示的文本:

C:\ Program Files文件\的Java \ jre7 \ LIB \ gnu.io.rxtx.SerialPorts

但程序仍然无法正常工作。

public void connect(String serial){ 
       this.serialPort = null; 
       try { 
         CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(serial); 
         if (portIdentifier.isCurrentlyOwned()) { 
           System.out.println("Port in use!"); 
         } else { 
           System.out.println(portIdentifier.getName()); 

           this.serialPort = (SerialPort) portIdentifier.open(
               "ListPortClass", 300); 
           int b = this.serialPort.getBaudRate(); 
           System.out.println(Integer.toString(b)); 
           this.serialPort.setSerialPortParams(115200, SerialPort.DATABITS_8, 
               SerialPort.STOPBITS_1, SerialPort.PARITY_NONE); 
          // serialPort.setInputBufferSize(65536); 
          // serialPort.setOutputBufferSize(4096); 

           System.out.println("Opened " + portIdentifier.getName()); 

           OutputStream mOutputToPort = this.serialPort.getOutputStream(); 
           InputStream mInputFromPort = this.serialPort.getInputStream(); 
           this.OutputToPort = mOutputToPort; 
           this.InputFromPort = mInputFromPort; 
           this.connected = true; 
         } 
       } catch (IOException ex) { 
         System.out.println("IOException : " + ex.getMessage()); 
       } catch (UnsupportedCommOperationException ex) { 
         System.out.println("UnsupportedCommOperationException : " + ex.getMessage()); 
       } catch (NoSuchPortException ex) { 
         System.out.println("NoSuchPortException : " + ex.getMessage()); 
       } catch (PortInUseException ex) { 
         System.out.println("PortInUseException : " + ex.getMessage());} 
     } 

回答

0

我在Linux上遇到过同样的错误,结果证明是权限问题。将用户帐户添加到“uucp”组(如http://rxtx.qbang.org中所述)后,请确保注销并再次登录系统。