diff options
author | Doug Schaefer | 2015-03-04 19:04:16 +0000 |
---|---|---|
committer | Gerrit Code Review @ Eclipse.org | 2015-03-06 18:14:25 +0000 |
commit | 6bd7355e47e40bf8f8030b4533a0f2da0b1e2b58 (patch) | |
tree | a00fce12ae5d88058d020cf19b4b33c5cb7256c8 /core/org.eclipse.cdt.core.native/src | |
parent | 3ad1ac66cf08d1ee2a4c597af13474dcc1104ded (diff) | |
download | org.eclipse.cdt-6bd7355e47e40bf8f8030b4533a0f2da0b1e2b58.tar.gz org.eclipse.cdt-6bd7355e47e40bf8f8030b4533a0f2da0b1e2b58.tar.xz org.eclipse.cdt-6bd7355e47e40bf8f8030b4533a0f2da0b1e2b58.zip |
Bug 459971 Windows native for Serial Port.
Not checking the binaries in until I get closer to the end. Still some
API changes I want to make to do more buffering.
Done as a Visual Studio 2013 project. I also brough winreg into that
sln file as I though I had to make a change in it but didn't in the
end. But really should bring them all.
Change-Id: I6e7d472763381cdc0ae558d8cd63993bb0460457
Signed-off-by: Doug Schaefer <dschaefer@qnx.com>
Diffstat (limited to 'core/org.eclipse.cdt.core.native/src')
4 files changed, 26 insertions, 3 deletions
diff --git a/core/org.eclipse.cdt.core.native/src/org/eclipse/cdt/internal/core/natives/Messages.java b/core/org.eclipse.cdt.core.native/src/org/eclipse/cdt/internal/core/natives/Messages.java index cd406359b45..d783d90fffc 100644 --- a/core/org.eclipse.cdt.core.native/src/org/eclipse/cdt/internal/core/natives/Messages.java +++ b/core/org.eclipse.cdt.core.native/src/org/eclipse/cdt/internal/core/natives/Messages.java @@ -17,6 +17,7 @@ public class Messages extends NLS { public static String Util_exception_cannotSetTerminalSize; public static String Util_error_cannotRun; public static String Util_exception_closeError; + public static String SerialPort_PORT_IS_OPEN; static { // Initialize resource bundle. diff --git a/core/org.eclipse.cdt.core.native/src/org/eclipse/cdt/internal/core/natives/Messages.properties b/core/org.eclipse.cdt.core.native/src/org/eclipse/cdt/internal/core/natives/Messages.properties index e1ab7f1ac42..cc7a5f26a37 100644 --- a/core/org.eclipse.cdt.core.native/src/org/eclipse/cdt/internal/core/natives/Messages.properties +++ b/core/org.eclipse.cdt.core.native/src/org/eclipse/cdt/internal/core/natives/Messages.properties @@ -14,3 +14,4 @@ Util_exception_cannotCreatePty=Cannot create pty Util_exception_closeError=close error Util_exception_cannotSetTerminalSize=Setting terminal size is not supported Util_error_cannotRun=Cannot run program "{0}": {1} +SerialPort_PORT_IS_OPEN=Port is open diff --git a/core/org.eclipse.cdt.core.native/src/org/eclipse/cdt/utils/serial/BaudRate.java b/core/org.eclipse.cdt.core.native/src/org/eclipse/cdt/utils/serial/BaudRate.java index bb1236d087a..8c1342339fc 100644 --- a/core/org.eclipse.cdt.core.native/src/org/eclipse/cdt/utils/serial/BaudRate.java +++ b/core/org.eclipse.cdt.core.native/src/org/eclipse/cdt/utils/serial/BaudRate.java @@ -15,7 +15,6 @@ package org.eclipse.cdt.utils.serial; */ public enum BaudRate { - B0(0), B50(50), B75(75), B110(110), diff --git a/core/org.eclipse.cdt.core.native/src/org/eclipse/cdt/utils/serial/SerialPort.java b/core/org.eclipse.cdt.core.native/src/org/eclipse/cdt/utils/serial/SerialPort.java index fdc5c1030e1..7319a16798a 100644 --- a/core/org.eclipse.cdt.core.native/src/org/eclipse/cdt/utils/serial/SerialPort.java +++ b/core/org.eclipse.cdt.core.native/src/org/eclipse/cdt/utils/serial/SerialPort.java @@ -15,8 +15,12 @@ import java.io.FilenameFilter; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.util.ArrayList; +import java.util.List; import java.util.regex.Pattern; +import org.eclipse.cdt.internal.core.natives.Messages; +import org.eclipse.cdt.utils.WindowsRegistry; import org.eclipse.core.runtime.Platform; /** @@ -32,7 +36,8 @@ public class SerialPort { private StopBits stopBits = StopBits.S1; private long handle; - private static final String PORT_OPEN = "Port is open"; + private static final String SERIAL_KEY = "HARDWARE\\DEVICEMAP\\SERIALCOMM"; //$NON-NLS-1$ + private static final String PORT_OPEN = Messages.SerialPort_PORT_IS_OPEN; static { System.loadLibrary("serial"); //$NON-NLS-1$ @@ -71,6 +76,22 @@ public class SerialPort { names[i] = files[i].getAbsolutePath(); } return names; + } else if (Platform.getOS().equals(Platform.OS_WIN32)) { + WindowsRegistry reg = WindowsRegistry.getRegistry(); + if (reg != null) { + List<String> ports = new ArrayList<>(); + int i = 0; + String name = reg.getLocalMachineValueName(SERIAL_KEY, i); + while (name != null) { + String value = reg.getLocalMachineValue(SERIAL_KEY, name); + ports.add(value); + i++; + name = reg.getLocalMachineValueName(SERIAL_KEY, i); + } + return ports.toArray(new String[ports.size()]); + } else { + return new String[0]; + } } else { return new String[0]; } @@ -95,6 +116,7 @@ public class SerialPort { public void close() throws IOException { close0(handle); isOpen = false; + handle = 0; } private native void close0(long handle) throws IOException; @@ -136,7 +158,7 @@ public class SerialPort { return parity; } - public void setStopBit(StopBits stopBits) throws IOException { + public void setStopBits(StopBits stopBits) throws IOException { if (isOpen) { throw new IOException(PORT_OPEN); } |