Skip to content

Commit ba8417b

Browse files
tresfGMKennedy
andauthored
Better device detection on Linux, Unix (#97)
Updated SerialDeviceList java to improve disconnect behavior for MacOS Updated Linux device detection Co-authored-by: dmitry-cherkas Co-authored-by: GKenn <[email protected]>
1 parent bea6c29 commit ba8417b

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

src/main/java/jssc/SerialPortList.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public class SerialPortList {
5353
break;
5454
}
5555
case SerialNativeInterface.OS_MAC_OS_X: {
56-
PORTNAMES_REGEXP = Pattern.compile("tty.(serial|usbserial|usbmodem).*");
56+
PORTNAMES_REGEXP = Pattern.compile("(tty|cu)\\..*");
5757
PORTNAMES_PATH = "/dev/";
5858
break;
5959
}
@@ -330,12 +330,15 @@ private static String[] getUnixBasedPortNames(String searchPath, Pattern pattern
330330
String fileName = file.getName();
331331
if(!file.isDirectory() && !file.isFile() && pattern.matcher(fileName).find()){
332332
String portName = searchPath + fileName;
333-
long portHandle = serialInterface.openPort(portName, false);//Open port without TIOCEXCL
334-
if(portHandle < 0 && portHandle != SerialNativeInterface.ERR_PORT_BUSY){
335-
continue;
336-
}
337-
else if(portHandle != SerialNativeInterface.ERR_PORT_BUSY) {
338-
serialInterface.closePort(portHandle);
333+
// For linux ttyS0..31 serial ports check existence by opening each of them
334+
if (fileName.startsWith("ttyS")) {
335+
long portHandle = serialInterface.openPort(portName, false);//Open port without TIOCEXCL
336+
if(portHandle < 0 && portHandle != SerialNativeInterface.ERR_PORT_BUSY){
337+
continue;
338+
}
339+
else if(portHandle != SerialNativeInterface.ERR_PORT_BUSY) {
340+
serialInterface.closePort(portHandle);
341+
}
339342
}
340343
portsTree.add(portName);
341344
}
Binary file not shown.

0 commit comments

Comments
 (0)