diff --git a/src/java/jssc/SerialPortList.java b/src/java/jssc/SerialPortList.java index f5fa667..f3a0d03 100644 --- a/src/java/jssc/SerialPortList.java +++ b/src/java/jssc/SerialPortList.java @@ -71,7 +71,7 @@ public class SerialPortList { } //since 2.1.0 -> Fully rewrited port name comparator - private static Comparator comparator = new Comparator() { + private static final Comparator PORTNAMES_COMPARATOR = new Comparator() { @Override public int compare(String valueA, String valueB) { @@ -157,43 +157,130 @@ public class SerialPortList { //<-since 2.1.0 /** - * Get sorted array of serial ports in the system + * Get sorted array of serial ports in the system using default settings:
+ * + * Search path
+ * Windows - ""(always ignored)
+ * Linux - "/dev/"
+ * Solaris - "/dev/term/"
+ * MacOSX - "/dev/"
+ * + * RegExp
+ * Windows - ""
+ * Linux - "(ttyS|ttyUSB|ttyACM|ttyAMA|rfcomm)[0-9]{1,3}"
+ * Solaris - "[0-9]*|[a-z]*"
+ * MacOSX - "tty.(serial|usbserial|usbmodem).*"
* * @return String array. If there is no ports in the system String[] * with zero length will be returned (since jSSC-0.8 in previous versions null will be returned) */ public static String[] getPortNames() { - return getPortNames(PORTNAMES_PATH, PORTNAMES_REGEXP, comparator); + return getPortNames(PORTNAMES_PATH, PORTNAMES_REGEXP, PORTNAMES_COMPARATOR); } /** - * Get sorted array of serial ports in the system, located by setted searchPath. - * In Windows this method equals getPortNames() + * Get sorted array of serial ports in the system located on searchPath * - * @param searchPath Path for searching serial ports. The default search paths:
+ * @param searchPath Path for searching serial ports (not null)
+ * The default search paths:
* Linux, MacOSX: /dev/
* Solaris: /dev/term/
- * Windows: ingored + * Windows: this parameter 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(); - } - return getUnixBasedPortNames(searchPath); - }*/ + public static String[] getPortNames(String searchPath) { + return getPortNames(searchPath, PORTNAMES_REGEXP, PORTNAMES_COMPARATOR); + } /** - * Get sorted array of serial ports in the system + * Get sorted array of serial ports in the system matched pattern * - * @param searchPath Path for searching serial ports. The default search paths:
+ * @param pattern RegExp pattern for matching port names (not null) + * + * @return String array. If there is no ports in the system String[] + * + * @since 2.3.0 + */ + public static String[] getPortNames(Pattern pattern) { + return getPortNames(PORTNAMES_PATH, pattern, PORTNAMES_COMPARATOR); + } + + /** + * Get sorted array of serial ports in the system matched pattern + * + * @param comparator Comparator for sotring port names (not null) + * + * @return String array. If there is no ports in the system String[] + * + * @since 2.3.0 + */ + public static String[] getPortNames(Comparator comparator) { + return getPortNames(PORTNAMES_PATH, PORTNAMES_REGEXP, comparator); + } + + /** + * Get sorted array of serial ports in the system located on searchPath, matched pattern + * + * @param searchPath Path for searching serial ports (not null)
+ * The default search paths:
* Linux, MacOSX: /dev/
* Solaris: /dev/term/
- * Windows: ingored + * Windows: this parameter ingored + * @param pattern RegExp pattern for matching port names (not null) * + * @return String array. If there is no ports in the system String[] + * + * @since 2.3.0 + */ + public static String[] getPortNames(String searchPath, Pattern pattern) { + return getPortNames(searchPath, pattern, PORTNAMES_COMPARATOR); + } + + /** + * Get sorted array of serial ports in the system located on searchPath and sorted by comparator + * + * @param searchPath Path for searching serial ports (not null)
+ * The default search paths:
+ * Linux, MacOSX: /dev/
+ * Solaris: /dev/term/
+ * Windows: this parameter ingored + * @param comparator Comparator for sotring port names (not null) + * + * @return String array. If there is no ports in the system String[] + * + * @since 2.3.0 + */ + public static String[] getPortNames(String searchPath, Comparator comparator) { + return getPortNames(searchPath, PORTNAMES_REGEXP, comparator); + } + + /** + * Get sorted array of serial ports in the system matched pattern and sorted by comparator + * + * @param pattern RegExp pattern for matching port names (not null) + * @param comparator Comparator for sotring port names (not null) + * + * @return String array. If there is no ports in the system String[] + * + * @since 2.3.0 + */ + public static String[] getPortNames(Pattern pattern, Comparator comparator) { + return getPortNames(PORTNAMES_PATH, pattern, comparator); + } + + /** + * Get sorted array of serial ports in the system located on searchPath, matched pattern and sorted by comparator + * + * @param searchPath Path for searching serial ports (not null)
+ * The default search paths:
+ * Linux, MacOSX: /dev/
+ * Solaris: /dev/term/
+ * Windows: this parameter ingored + * @param pattern RegExp pattern for matching port names (not null) + * @param comparator Comparator for sotring port names (not null) * * @return String array. If there is no ports in the system String[] *