Skip to main content
summaryrefslogtreecommitdiffstats
path: root/native
diff options
context:
space:
mode:
authorDoug Schaefer2017-06-18 22:12:35 -0400
committerDoug Schaefer2017-06-19 10:21:25 -0400
commitd6dccc85582437a6632a349d3fda6463ad3ce8ca (patch)
tree6e3dd24cab5d6a336a76371580cf3191e3800802 /native
parentbd6da0b03dcdbb7989fa195469a2a44eb00f467b (diff)
downloadorg.eclipse.cdt-d6dccc85582437a6632a349d3fda6463ad3ce8ca.tar.gz
org.eclipse.cdt-d6dccc85582437a6632a349d3fda6463ad3ce8ca.tar.xz
org.eclipse.cdt-d6dccc85582437a6632a349d3fda6463ad3ce8ca.zip
Fix serial port naming on Windows to ensure get() method works.
Diffstat (limited to 'native')
-rw-r--r--native/org.eclipse.cdt.native.serial/src/org/eclipse/cdt/serial/SerialPort.java16
1 files changed, 10 insertions, 6 deletions
diff --git a/native/org.eclipse.cdt.native.serial/src/org/eclipse/cdt/serial/SerialPort.java b/native/org.eclipse.cdt.native.serial/src/org/eclipse/cdt/serial/SerialPort.java
index e6b6c89aac..9558c87b9b 100644
--- a/native/org.eclipse.cdt.native.serial/src/org/eclipse/cdt/serial/SerialPort.java
+++ b/native/org.eclipse.cdt.native.serial/src/org/eclipse/cdt/serial/SerialPort.java
@@ -179,6 +179,14 @@ public class SerialPort {
}
};
+ private static String adjustPortName(String portName) {
+ if (System.getProperty("os.name").startsWith("Windows") && !portName.startsWith("\\\\.\\")) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ return "\\\\.\\" + portName; //$NON-NLS-1$
+ } else {
+ return portName;
+ }
+ }
+
/**
* Create a serial port that connect to the given serial device.
*
@@ -186,11 +194,7 @@ public class SerialPort {
* name for the serial device.
*/
public SerialPort(String portName) {
- if (System.getProperty("os.name").startsWith("Windows") && !portName.startsWith("\\\\.\\")) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- this.portName = "\\\\.\\" + portName; //$NON-NLS-1$
- } else {
- this.portName = portName;
- }
+ this.portName = adjustPortName(portName);
}
private native long open0(String portName, int baudRate, int byteSize, int parity, int stopBits) throws IOException;
@@ -267,7 +271,7 @@ public class SerialPort {
*/
public static SerialPort get(String portName) {
synchronized (openPorts) {
- LinkedList<WeakReference<SerialPort>> list = openPorts.get(portName);
+ LinkedList<WeakReference<SerialPort>> list = openPorts.get(adjustPortName(portName));
if (list == null) {
return null;
}

Back to the top