Skip to content

Commit

Permalink
Merge pull request #2824 from nicolatimeus/fix_backport-comm-connecti…
Browse files Browse the repository at this point in the history
…on-close-port

Backport of #2822 to release-4.1.0
  • Loading branch information
MMaiero authored Apr 30, 2020
2 parents 62fdb64 + 6cb5b20 commit eeb3bf7
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion kura/distrib/config/kura.build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ org.eclipse.kura.broker.artemis.xml.version=1.0.300
org.eclipse.kura.core.version=1.0.501
org.eclipse.kura.core.certificates.version=1.0.500
org.eclipse.kura.core.cloud.version=1.1.400
org.eclipse.kura.core.comm.version=1.0.500
org.eclipse.kura.core.comm.version=1.0.501
org.eclipse.kura.core.configuration.version=2.0.200
org.eclipse.kura.core.crypto.version=1.0.500
org.eclipse.kura.deployment.agent.version=1.0.500
Expand Down
2 changes: 1 addition & 1 deletion kura/org.eclipse.kura.core.comm/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: org.eclipse.kura.core.comm
Bundle-SymbolicName: org.eclipse.kura.core.comm;singleton:=true
Bundle-Version: 1.0.501.qualifier
Bundle-Version: 1.0.501
Bundle-Vendor: Eclipse Kura
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Service-Component: OSGI-INF/*.xml
Expand Down
2 changes: 1 addition & 1 deletion kura/org.eclipse.kura.core.comm/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</parent>

<artifactId>org.eclipse.kura.core.comm</artifactId>
<version>1.0.501-SNAPSHOT</version>
<version>1.0.501</version>
<packaging>eclipse-plugin</packaging>

<properties>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2011, 2016 Eurotech and/or its affiliates and others
* Copyright (c) 2011, 2020 Eurotech and/or its affiliates and others
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
Expand Down Expand Up @@ -29,7 +29,6 @@
import javax.comm.NoSuchPortException;
import javax.comm.PortInUseException;
import javax.comm.SerialPort;
import javax.comm.UnsupportedCommOperationException;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand Down Expand Up @@ -88,9 +87,14 @@ public CommConnectionImpl(CommURI commUri, int mode, boolean timeouts)

final CommPort commPort = commPortIdentifier.open(this.getClass().getName(), openTimeout);

if (commPort instanceof SerialPort) {
this.serialPort = (SerialPort) commPort;
try {
if (commPort == null) {
throw new NoSuchPortException("CommPortIdentifier.open() returned a null port");
}

try {
if (commPort instanceof SerialPort) {
this.serialPort = (SerialPort) commPort;

this.serialPort.setSerialPortParams(baudRate, dataBits, stopBits, parity);
this.serialPort.setFlowControlMode(flowControl);
if (receiveTimeout > 0) {
Expand All @@ -99,12 +103,13 @@ public CommConnectionImpl(CommURI commUri, int mode, boolean timeouts)
throw new IOException("Serial receive timeout not supported by driver");
}
}
} catch (UnsupportedCommOperationException e) {
logger.error("Failed to configure COM port", e);
throw new IOException(e);
} else {
throw new IOException("Unsupported Port Type");
}
} else {
throw new IOException("Unsupported Port Type");
} catch (final Exception e) {
logger.error("Failed to configure COM port", e);
commPort.close();
throw new IOException(e);
}
}

Expand Down

0 comments on commit eeb3bf7

Please sign in to comment.