Added "getPortNames(String searchPath)" method and maded a little changes in "getUnixBasedPortNames()" method
This commit is contained in:
parent
e8df64618d
commit
cd4f05d84c
|
@ -161,7 +161,7 @@ public class SerialPortList {
|
|||
public static String[] getPortNames() {
|
||||
//since 2.1.0 ->
|
||||
if(PORTNAMES_PATH != null){
|
||||
return getUnixBasedPortNames();
|
||||
return getUnixBasedPortNames(PORTNAMES_PATH);
|
||||
}
|
||||
//<- since 2.1.0
|
||||
String[] portNames = serialInterface.getSerialPortNames();
|
||||
|
@ -173,14 +173,40 @@ public class SerialPortList {
|
|||
return ports.toArray(new String[ports.size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get sorted array of serial ports in the system. In Windows this method equals <b>getPortNames()</b>
|
||||
*
|
||||
* @param searchPath Path for searching serial ports. The default search paths:<br>
|
||||
* Linux, MacOSX: <b>/dev/</b><br>
|
||||
* Solaris: <b>/dev/term/</b><br>
|
||||
* Windows: ingored
|
||||
*
|
||||
* @return String array. If there is no ports in the system String[]
|
||||
*
|
||||
* @since 2.3.0
|
||||
*/
|
||||
public static String[] getPortNames(String searchPath) {
|
||||
if(SerialNativeInterface.getOsType() == SerialNativeInterface.OS_WINDOWS){
|
||||
return getPortNames();
|
||||
}
|
||||
if(searchPath == null){
|
||||
searchPath = "";
|
||||
}
|
||||
if(!searchPath.equals("") && !searchPath.endsWith("/")){
|
||||
searchPath += "/";
|
||||
}
|
||||
System.out.println("Result search path: " + searchPath);
|
||||
return getUnixBasedPortNames(searchPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Universal method for getting port names of _nix based systems
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private static String[] getUnixBasedPortNames() {
|
||||
private static String[] getUnixBasedPortNames(String searchPath) {
|
||||
String[] returnArray = new String[]{};
|
||||
File dir = new File(PORTNAMES_PATH);
|
||||
File dir = new File(/*PORTNAMES_PATH*/searchPath);
|
||||
if(dir.exists() && dir.isDirectory()){
|
||||
File[] files = dir.listFiles();
|
||||
if(files.length > 0){
|
||||
|
@ -188,7 +214,7 @@ public class SerialPortList {
|
|||
for(File file : files){
|
||||
String fileName = file.getName();
|
||||
if(!file.isDirectory() && !file.isFile() && PORTNAMES_REGEXP.matcher(fileName).find()){
|
||||
String portName = PORTNAMES_PATH + fileName;
|
||||
String portName = /*PORTNAMES_PATH*/searchPath + fileName;
|
||||
if(SerialNativeInterface.getOsType() == SerialNativeInterface.OS_LINUX){
|
||||
int portHandle = serialInterface.openPort(portName, false);//Open port without TIOCEXCL
|
||||
if(portHandle < 0 && portHandle != -1){//If port handle == -1 it's mean that it's busy
|
||||
|
|
Loading…
Reference in New Issue