diff --git a/src/java/jssc/SerialPortList.java b/src/java/jssc/SerialPortList.java
index 472bbd5..51546ba 100644
--- a/src/java/jssc/SerialPortList.java
+++ b/src/java/jssc/SerialPortList.java
@@ -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 getPortNames()
+ *
+ * @param searchPath Path for searching serial ports. The default search paths:
+ * Linux, MacOSX: /dev/
+ * Solaris: /dev/term/
+ * 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