1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-06 17:26:01 +02:00

Fix serial port naming on Windows to ensure get() method works.

Change-Id: Ida9b9568280b9530c8e7ff55b45e503889208dd1
(cherry picked from commit 34a3a01259)
This commit is contained in:
Doug Schaefer 2017-06-18 22:12:35 -04:00
parent bd6da0b03d
commit d6dccc8558

View file

@ -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. * Create a serial port that connect to the given serial device.
* *
@ -186,11 +194,7 @@ public class SerialPort {
* name for the serial device. * name for the serial device.
*/ */
public SerialPort(String portName) { public SerialPort(String portName) {
if (System.getProperty("os.name").startsWith("Windows") && !portName.startsWith("\\\\.\\")) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ this.portName = adjustPortName(portName);
this.portName = "\\\\.\\" + portName; //$NON-NLS-1$
} else {
this.portName = portName;
}
} }
private native long open0(String portName, int baudRate, int byteSize, int parity, int stopBits) throws IOException; 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) { public static SerialPort get(String portName) {
synchronized (openPorts) { synchronized (openPorts) {
LinkedList<WeakReference<SerialPort>> list = openPorts.get(portName); LinkedList<WeakReference<SerialPort>> list = openPorts.get(adjustPortName(portName));
if (list == null) { if (list == null) {
return null; return null;
} }