<tfoot id='jfBZL'></tfoot>

<small id='jfBZL'></small><noframes id='jfBZL'>

      <legend id='jfBZL'><style id='jfBZL'><dir id='jfBZL'><q id='jfBZL'></q></dir></style></legend>

        <bdo id='jfBZL'></bdo><ul id='jfBZL'></ul>

    1. <i id='jfBZL'><tr id='jfBZL'><dt id='jfBZL'><q id='jfBZL'><span id='jfBZL'><b id='jfBZL'><form id='jfBZL'><ins id='jfBZL'></ins><ul id='jfBZL'></ul><sub id='jfBZL'></sub></form><legend id='jfBZL'></legend><bdo id='jfBZL'><pre id='jfBZL'><center id='jfBZL'></center></pre></bdo></b><th id='jfBZL'></th></span></q></dt></tr></i><div id='jfBZL'><tfoot id='jfBZL'></tfoot><dl id='jfBZL'><fieldset id='jfBZL'></fieldset></dl></div>

        在ubuntu上用java进行串口识别

        时间:2024-08-24
      1. <i id='nmODf'><tr id='nmODf'><dt id='nmODf'><q id='nmODf'><span id='nmODf'><b id='nmODf'><form id='nmODf'><ins id='nmODf'></ins><ul id='nmODf'></ul><sub id='nmODf'></sub></form><legend id='nmODf'></legend><bdo id='nmODf'><pre id='nmODf'><center id='nmODf'></center></pre></bdo></b><th id='nmODf'></th></span></q></dt></tr></i><div id='nmODf'><tfoot id='nmODf'></tfoot><dl id='nmODf'><fieldset id='nmODf'></fieldset></dl></div>

        <small id='nmODf'></small><noframes id='nmODf'>

              <tbody id='nmODf'></tbody>
            • <bdo id='nmODf'></bdo><ul id='nmODf'></ul>
              <legend id='nmODf'><style id='nmODf'><dir id='nmODf'><q id='nmODf'></q></dir></style></legend>

                <tfoot id='nmODf'></tfoot>
                • 本文介绍了在ubuntu上用java进行串口识别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试使用 Java 连接 ubuntu 上的串行应用程序
                  在搜索和阅读资源后,我在库中添加了 comm.jar 和 RXTXcomm.jar.
                  我使用以下代码来识别comports.在我的系统中有三个端口,但在 ports.hasMoreElements() 方法中显示为 false.
                  请查看代码并帮助我.

                  I'm trying to connect a serial application on ubuntu with Java
                  After searching and reading resources,I add comm.jar and RXTXcomm.jar in the library.
                  I use the following code to identify the comports. In my system there are three ports but it is showing false in ports.hasMoreElements() method.
                  Kindly look into the code and help me.

                  String wantedPortName = "/dev/ttya";
                  ///dev/ttyS0  /dev/ttyS1   
                  Enumeration portIdentifiers = CommPortIdentifier.getPortIdentifiers();
                  CommPortIdentifier portId = null;  // will be set if port found
                  while (portIdentifiers.hasMoreElements())
                  {
                      CommPortIdentifier pid = (CommPortIdentifier) portIdentifiers.nextElement();
                      if(pid.getPortType() == CommPortIdentifier.PORT_SERIAL &&
                        pid.getName().equals(wantedPortName)) 
                    {
                      portId = pid;
                      break;
                    }
                  }
                  if(portId == null)
                  {
                       System.err.println("Could not find serial port " + wantedPortName);
                       System.exit(1);
                  }    
                  

                  推荐答案

                  就我而言,我使用的是 Ubuntu,我的笔记本没有任何串行或并行端口.

                  In my case, I'm using Ubuntu, and my notebook does not have any serial or paralel ports.

                  所以,你必须模拟这种端口:

                  So, you have to simulate this kind of port:

                  apt-get install socat
                  

                  运行它:

                  socat -d -d pty,raw,echo=0, pty,raw,echo=0
                  

                  根据输出,注意创建的设备":

                  According to output, pay attention to "devices" created:

                  2014/02/05 01:04:32 socat[7411] N PTY is /dev/pts/2
                  2014/02/05 01:04:32 socat[7411] N PTY is /dev/pts/3
                  2014/02/05 01:04:32 socat[7411] N starting data transfer loop with FDs [3,3] and [5,5]
                  

                  停止 socat [CTRL]+[C] 并将其符号链接到 RXTX 将识别为设备的位置,由于tty"前缀:

                  Stop socat [CTRL]+[C] and symlink it to a location that RXTX will recognise as a device, due to "tty" prefix:

                  sudo ln -s /dev/pts/2 /dev/ttyUSB02
                  sudo ln -s /dev/pts/3 /dev/ttyUSB03
                  

                  现在,再次运行 socat

                  Now, run socat again

                  socat -d -d pty,raw,echo=0 pty,raw,echo=0
                  

                  现在,使用以下代码,您将看到 2 个虚拟端口:

                  Now, using following code, you will see 2 virtual ports:

                          Enumeration portList = CommPortIdentifier.getPortIdentifiers();//this line was false
                          System.out.println(portList.hasMoreElements());
                  
                          while(portList.hasMoreElements()){
                              System.out.println("Has more elements");
                               CommPortIdentifier portId = (CommPortIdentifier) portList.nextElement();
                                 if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
                                      System.out.println(portId.getName());
                                 }
                                 else{
                                       System.out.println(portId.getName());
                                 }
                          }
                  

                  system.out:

                  system.out:

                  true
                  Has more elements
                  /dev/ttyUSB03
                  Has more elements
                  /dev/ttyUSB02
                  

                  这篇关于在ubuntu上用java进行串口识别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:通过串行通信 java 发送数据包 下一篇:使用 Java 自动检测连接到 USB GSM 调制解调器的 Com 端口

                  相关文章

                  <i id='yZp61'><tr id='yZp61'><dt id='yZp61'><q id='yZp61'><span id='yZp61'><b id='yZp61'><form id='yZp61'><ins id='yZp61'></ins><ul id='yZp61'></ul><sub id='yZp61'></sub></form><legend id='yZp61'></legend><bdo id='yZp61'><pre id='yZp61'><center id='yZp61'></center></pre></bdo></b><th id='yZp61'></th></span></q></dt></tr></i><div id='yZp61'><tfoot id='yZp61'></tfoot><dl id='yZp61'><fieldset id='yZp61'></fieldset></dl></div>

                  • <bdo id='yZp61'></bdo><ul id='yZp61'></ul>

                    1. <small id='yZp61'></small><noframes id='yZp61'>

                      <tfoot id='yZp61'></tfoot>
                      <legend id='yZp61'><style id='yZp61'><dir id='yZp61'><q id='yZp61'></q></dir></style></legend>