Browse Source

Better windows compatibility

Thomas Buck 13 years ago
parent
commit
dde4545d26

+ 19
- 9
CubeControl/HelperUtility.java View File

@@ -40,6 +40,7 @@ public class HelperUtility {
40 40
 	static {
41 41
 		// System.out.println("Loading Serial Library...");
42 42
 		loadFromJar();
43
+		// System.out.println("Loaded!");
43 44
 	}
44 45
 
45 46
 	/**
@@ -53,6 +54,8 @@ public class HelperUtility {
53 54
 			loadLib(path, "Serial.dll");
54 55
 		} else if (os.indexOf("mac") > -1) {
55 56
 			loadLib(path, "libSerial.jnilib");
57
+		} else {
58
+			loadLib(path, "libSerial.so");
56 59
 		}
57 60
 	}
58 61
 
@@ -73,9 +76,11 @@ public class HelperUtility {
73 76
 			inChannel.close();
74 77
 			outChannel.close();
75 78
 			System.load(fileOut.toString());
79
+			System.out.println("Loaded Serial Library from " + fileOut.toString());
76 80
 		} catch (Exception e) {
77 81
 			System.out.println("Failed to load Serial Library:");
78 82
 			e.printStackTrace();
83
+			System.exit(1);
79 84
 		}
80 85
 	}
81 86
 
@@ -107,16 +112,21 @@ public class HelperUtility {
107 112
 	 */
108 113
 	public static String getPorts() {
109 114
 		String os = System.getProperty("os.name").toLowerCase();
110
-		if (os.indexOf("windows") > -1) {
111
-			return getThePorts("COM");
112
-		} else if (os.indexOf("linux") > -1) {
113
-			return getThePorts("tty");
114
-		} else if (os.indexOf("mac") > -1) {
115
-			return getThePorts("tty.");
115
+		try {
116
+			if (os.indexOf("windows") > -1) {
117
+				return getThePorts("COM");
118
+			} else if (os.indexOf("max") > -1) {
119
+				return getThePorts("tty.");
120
+			} else {
121
+				return getThePorts("tty");
122
+			}
123
+		} catch (Exception e) {
124
+			// Unsatisfied linker error:
125
+			// Serial.dll was probably not found
126
+			System.out.println("Exception: " + e.toString());
127
+		} finally {
128
+			return null;
116 129
 		}
117
-
118
-		// Not linux, windows or mac?
119
-		return getThePorts("wtf?");
120 130
 	}
121 131
 
122 132
 	private static native String getThePorts(String search);

+ 15
- 0
CubeControl/libSerial/makefile View File

@@ -4,6 +4,12 @@ ifdef SystemRoot
4 4
 HEADERPATH = C:/Program\ Files/Java/jdk1.6.0_29/include
5 5
 RM = del
6 6
 else
7
+ifdef SYSTEMROOT
8
+# Looks like Cygwin or Mingw shell
9
+HEADERPATH = C:\Programme\Java\jdk1.6.0_31\include
10
+HEADERPATH += -IC:\Programme\Java\jdk1.6.0_31\include\win32
11
+RM = rm -rf
12
+else
7 13
 RM = rm -f
8 14
 UNAME := $(shell uname -s)
9 15
 ifeq ($(UNAME),Darwin)
@@ -12,6 +18,7 @@ else
12 18
 HEADERPATH = /usr/lib/jvm/java-6-openjdk/include
13 19
 endif
14 20
 endif
21
+endif
15 22
 
16 23
 # --------------------------------------
17 24
 
@@ -30,12 +37,16 @@ HelperUtility.class: ../HelperUtility.java
30 37
 ifdef SystemRoot
31 38
 libSerial: Serial.dll
32 39
 else
40
+ifdef SYSTEMROOT
41
+libSerial: Serial.dll
42
+else
33 43
 ifeq ($(UNAME),Darwin)
34 44
 libSerial: libSerial.jnilib
35 45
 else
36 46
 libSerial: libSerial.so
37 47
 endif
38 48
 endif
49
+endif
39 50
 
40 51
 libSerial.jnilib: serialHelper.c unixSerial.c serialInterface.h
41 52
 	$(CC) -x c -I$(HEADERPATH) -c serialHelper.c -o serialHelper.o
@@ -57,9 +68,13 @@ clean:
57 68
 ifdef SystemRoot
58 69
 	$(RM) *.dll
59 70
 else
71
+ifdef SYSTEMROOT
72
+	$(RM) *.dll
73
+else
60 74
 ifeq ($(UNAME),Darwin)
61 75
 	$(RM) *.jnilib
62 76
 else
63 77
 	$(RM) *.so
64 78
 endif
65 79
 endif
80
+endif

+ 1
- 1
CubeControl/libSerial/winSerial.c View File

@@ -125,7 +125,7 @@ char** getSerialPorts(const char *search) {
125 125
 		j++; // \0
126 126
 		files[i] = (char *)malloc(j * sizeof(char));
127 127
 		for (k = 0; k < j; k++) {
128
-			files[i] = ports[start + k];
128
+			files[i][k] = ports[start + k];
129 129
 		}
130 130
 	}
131 131
 

+ 17
- 0
CubeControl/makefile View File

@@ -8,6 +8,14 @@ RM = del
8 8
 INJAR += Serial.dll
9 9
 PLATFORM = Win
10 10
 else
11
+ifdef SYSTEMROOT
12
+# Looks like cygwin or mingw shell
13
+HEADERPATH = C:\Programme\Java\jdk1.6.0_31\include
14
+HEADERPATH += -IC:\Programme\Java\jdk1.6.0_31\include\win32
15
+RM = rm -rf
16
+INJAR += Serial.dll
17
+PLATFORM = Win
18
+else
11 19
 RM = rm -f
12 20
 UNAME := $(shell uname -s)
13 21
 ifeq ($(UNAME),Darwin)
@@ -20,6 +28,7 @@ PLATFORM = Linux
20 28
 HEADERPATH = /usr/lib/jvm/java-6-openjdk/include
21 29
 endif
22 30
 endif
31
+endif
23 32
 
24 33
 # All java files to be compiled
25 34
 # List so it works as target
@@ -46,12 +55,16 @@ doc/index.html: $(JAVAFILES)
46 55
 ifdef SystemRoot
47 56
 libSerial: Serial.dll
48 57
 else
58
+ifdef SYSTEMROOT
59
+libSerial: Serial.dll
60
+else
49 61
 ifeq ($(UNAME),Darwin)
50 62
 libSerial: libSerial.jnilib
51 63
 else
52 64
 libSerial: libSerial.so
53 65
 endif
54 66
 endif
67
+endif
55 68
 
56 69
 Serial.dll: libSerial/serialHelper.c libSerial/winSerial.c
57 70
 	make -C libSerial
@@ -74,5 +87,9 @@ clean:
74 87
 ifdef SystemRoot
75 88
 	$(RM) *.dll
76 89
 else
90
+ifdef SYSTEMROOT
91
+	$(RM) *.dll
92
+else
77 93
 	$(RM) *.jnilib
78 94
 endif
95
+endif

Loading…
Cancel
Save