Skip to content

Better device detection on Linux, Unix #97

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Aug 1, 2021
Merged
17 changes: 10 additions & 7 deletions src/main/java/jssc/SerialPortList.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class SerialPortList {
break;
}
case SerialNativeInterface.OS_MAC_OS_X: {
PORTNAMES_REGEXP = Pattern.compile("tty.(serial|usbserial|usbmodem).*");
PORTNAMES_REGEXP = Pattern.compile("(tty|cu)\\..*");
PORTNAMES_PATH = "/dev/";
break;
}
Expand Down Expand Up @@ -330,12 +330,15 @@ private static String[] getUnixBasedPortNames(String searchPath, Pattern pattern
String fileName = file.getName();
if(!file.isDirectory() && !file.isFile() && pattern.matcher(fileName).find()){
String portName = searchPath + fileName;
long portHandle = serialInterface.openPort(portName, false);//Open port without TIOCEXCL
if(portHandle < 0 && portHandle != SerialNativeInterface.ERR_PORT_BUSY){
continue;
}
else if(portHandle != SerialNativeInterface.ERR_PORT_BUSY) {
serialInterface.closePort(portHandle);
// For linux ttyS0..31 serial ports check existence by opening each of them
if (fileName.startsWith("ttyS")) {
long portHandle = serialInterface.openPort(portName, false);//Open port without TIOCEXCL
if(portHandle < 0 && portHandle != SerialNativeInterface.ERR_PORT_BUSY){
continue;
}
else if(portHandle != SerialNativeInterface.ERR_PORT_BUSY) {
serialInterface.closePort(portHandle);
}
}
portsTree.add(portName);
}
Expand Down
Binary file not shown.