Windows64 bit machine RXTX open configuration package installation and environmental

Java API for serial programming package
common serial port for Java packages:

  • comm2.0.jar (Windows environment)
  • comm3.0.jar (Linux / Solaris environment)
  • Open source API such as Rxtx a jar
    I started to read a few articles, using comm2.0.jar, then the test after an error, an error content is that it does not support 64-bit systems. And comm2.0.jar too old, still use Rxtx. Otherwise there is a solution is to re-install 32-bit jdk. Rxtx open source package Quguan network to download: http://rxtx.qbang.org/wiki/index.php/Download#x64_Binaries

Under careful not wrong, it is still above 2.1 does not support 64-bit systems ......

Software environment to build
download, unzip, find RXTXcomm.jar, and find rxtxSerial.dll under win64 according to their own systems.

Jdk find their root directory, such as my jdk root directory is "E: \ ProgramFiles \ Java \ jdk1.8.0_60", followed by the use of "% JAVA_HOME%" instead.

Under Copy rxtxSerial.dll to "% JAVA_HOME% \ jre \ bin "
copy RXTXcomm.jar to "% JAVA_HOME% \ jre \ lib \ ext" and under "% JAVA_HOME% \ lib"
as if it should also set the environment variable
on this computer right click -> properties -> advanced system settings -> lower right corner of the environment variable, double-click the system variables CLASSPATH, add about a new jar, can be determined.

Code testing
done with the following piece of code it tests. Code to achieve is to find an available port and return. You can control the device manager.

package com.pc.serialport;

import java.util.ArrayList;
import java.util.Enumeration;

import gnu.io.CommPortIdentifier;

public class FindPort {
public static void main(String[] args)
{
for(String tmp:findPort()){
System.out.println(tmp);
}
System.exit(0);
}
public static final ArrayList findPort() {

        @SuppressWarnings("unchecked")
        //获得当前可用串口
        Enumeration<CommPortIdentifier> portList = CommPortIdentifier.getPortIdentifiers();//获得所有串口

        ArrayList<String> portNameList = new ArrayList<>();
        //串口名字添加到List并返回    
        while (portList.hasMoreElements()) {
            String portName = portList.nextElement().getName();
            portNameList.add(portName);
        }
        return portNameList;
    }

}

Original: https://blog.csdn.net/concisefreedom/article/details/67085946

Guess you like

Origin blog.csdn.net/qq_35577329/article/details/89000338