Browse Source

Better windows compatibility

Thomas Buck 12 years ago
parent
commit
dde4545d26

+ 19
- 9
CubeControl/HelperUtility.java View File

40
 	static {
40
 	static {
41
 		// System.out.println("Loading Serial Library...");
41
 		// System.out.println("Loading Serial Library...");
42
 		loadFromJar();
42
 		loadFromJar();
43
+		// System.out.println("Loaded!");
43
 	}
44
 	}
44
 
45
 
45
 	/**
46
 	/**
53
 			loadLib(path, "Serial.dll");
54
 			loadLib(path, "Serial.dll");
54
 		} else if (os.indexOf("mac") > -1) {
55
 		} else if (os.indexOf("mac") > -1) {
55
 			loadLib(path, "libSerial.jnilib");
56
 			loadLib(path, "libSerial.jnilib");
57
+		} else {
58
+			loadLib(path, "libSerial.so");
56
 		}
59
 		}
57
 	}
60
 	}
58
 
61
 
73
 			inChannel.close();
76
 			inChannel.close();
74
 			outChannel.close();
77
 			outChannel.close();
75
 			System.load(fileOut.toString());
78
 			System.load(fileOut.toString());
79
+			System.out.println("Loaded Serial Library from " + fileOut.toString());
76
 		} catch (Exception e) {
80
 		} catch (Exception e) {
77
 			System.out.println("Failed to load Serial Library:");
81
 			System.out.println("Failed to load Serial Library:");
78
 			e.printStackTrace();
82
 			e.printStackTrace();
83
+			System.exit(1);
79
 		}
84
 		}
80
 	}
85
 	}
81
 
86
 
107
 	 */
112
 	 */
108
 	public static String getPorts() {
113
 	public static String getPorts() {
109
 		String os = System.getProperty("os.name").toLowerCase();
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
 	private static native String getThePorts(String search);
132
 	private static native String getThePorts(String search);

+ 15
- 0
CubeControl/libSerial/makefile View File

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

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

125
 		j++; // \0
125
 		j++; // \0
126
 		files[i] = (char *)malloc(j * sizeof(char));
126
 		files[i] = (char *)malloc(j * sizeof(char));
127
 		for (k = 0; k < j; k++) {
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
 INJAR += Serial.dll
8
 INJAR += Serial.dll
9
 PLATFORM = Win
9
 PLATFORM = Win
10
 else
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
 RM = rm -f
19
 RM = rm -f
12
 UNAME := $(shell uname -s)
20
 UNAME := $(shell uname -s)
13
 ifeq ($(UNAME),Darwin)
21
 ifeq ($(UNAME),Darwin)
20
 HEADERPATH = /usr/lib/jvm/java-6-openjdk/include
28
 HEADERPATH = /usr/lib/jvm/java-6-openjdk/include
21
 endif
29
 endif
22
 endif
30
 endif
31
+endif
23
 
32
 
24
 # All java files to be compiled
33
 # All java files to be compiled
25
 # List so it works as target
34
 # List so it works as target
46
 ifdef SystemRoot
55
 ifdef SystemRoot
47
 libSerial: Serial.dll
56
 libSerial: Serial.dll
48
 else
57
 else
58
+ifdef SYSTEMROOT
59
+libSerial: Serial.dll
60
+else
49
 ifeq ($(UNAME),Darwin)
61
 ifeq ($(UNAME),Darwin)
50
 libSerial: libSerial.jnilib
62
 libSerial: libSerial.jnilib
51
 else
63
 else
52
 libSerial: libSerial.so
64
 libSerial: libSerial.so
53
 endif
65
 endif
54
 endif
66
 endif
67
+endif
55
 
68
 
56
 Serial.dll: libSerial/serialHelper.c libSerial/winSerial.c
69
 Serial.dll: libSerial/serialHelper.c libSerial/winSerial.c
57
 	make -C libSerial
70
 	make -C libSerial
74
 ifdef SystemRoot
87
 ifdef SystemRoot
75
 	$(RM) *.dll
88
 	$(RM) *.dll
76
 else
89
 else
90
+ifdef SYSTEMROOT
91
+	$(RM) *.dll
92
+else
77
 	$(RM) *.jnilib
93
 	$(RM) *.jnilib
78
 endif
94
 endif
95
+endif

Loading…
Cancel
Save