Throw SerialPortInvalidPortException if descriptor search fails

This commit is contained in:
hedgecrw85 2021-04-14 08:45:10 -05:00
parent 43e302ec14
commit c8192cf87d
1 changed files with 5 additions and 0 deletions

View File

@ -327,10 +327,15 @@ public final class SerialPort
portDescriptor = (new File(portDescriptor)).getCanonicalPath();
else if (!((new File(portDescriptor)).exists()))
{
// Attempt to locate the correct port descriptor
if (portDescriptor.contains("/"))
portDescriptor = "/dev/" + portDescriptor.substring(portDescriptor.lastIndexOf('/')+1);
else
portDescriptor = "/dev/" + portDescriptor;
// Check if the updated port descriptor exists
if (!((new File(portDescriptor)).exists()))
throw new IOException();
}
}
catch (Exception e) { throw new SerialPortInvalidPortException("Unable to create a serial port object from the invalid port descriptor: " + portDescriptor, e); }