[knx] FT12: List available serial ports if port cannot be opened (#12942)

Fixes a regression introduced by upgrading Calimero library to 2.5.

Signed-off-by: Holger Friedrich <mail@holger-friedrich.de>
This commit is contained in:
Holger Friedrich 2022-06-19 14:50:35 +02:00 committed by GitHub
parent b5489057b6
commit 822c27c181
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 1 deletions

View File

@ -36,6 +36,8 @@ import tuwien.auto.calimero.link.medium.TPSettings;
@NonNullByDefault
public class SerialClient extends AbstractKNXClient {
private static final String CALIMERO_ERROR_CANNOT_OPEN_PORT = "failed to open serial port";
private final Logger logger = LoggerFactory.getLogger(SerialClient.class);
private final String serialPort;
@ -69,7 +71,8 @@ public class SerialClient extends AbstractKNXClient {
e);
} catch (KNXException e) {
final String msg = e.getMessage();
if ((msg != null) && (msg.startsWith("can not open serial port"))) {
// TODO add a test for this string match; error message might change in later version of Calimero library
if ((msg != null) && (msg.startsWith(CALIMERO_ERROR_CANNOT_OPEN_PORT))) {
StringBuilder sb = new StringBuilder("Available ports are:\n");
Enumeration<?> portList = CommPortIdentifier.getPortIdentifiers();
while (portList.hasMoreElements()) {