Java串口配置gnu.io.rxtx.properties窗口

时间:2013-12-12 21:26:44

标签: java serial-port

我正在尝试运行此函数,并且我使用文本配置gnu.io.rxtx.properties窗口: 尚未检测到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());}
        }

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:-1)

我遇到了同样的问题,我在搜索了其他方法后解决了这个问题。我使用的IDE是Eclipse,其他IDE的解决方案应该是类似的。

该错误是由于运行配置造成的,我们只需要将以前的RXTX.gun.io主类更改为您的程序的主类。

运行>运行配置>主类>搜索