Browse Source

Tried fixing serial library for windows...

unknown 12 years ago
parent
commit
b495b5e0cc

+ 23
- 27
CubeControl/Frame.java View File

@@ -270,32 +270,28 @@ public class Frame extends JFrame implements ListSelectionListener {
270 270
 
271 271
 		// ----- 3D Stuff -----
272 272
 		// --------------------
273
-		gConfig = SimpleUniverse.getPreferredConfiguration();
274
-		try {
275
-			cubeCanvas = new Canvas3D(gConfig);
276
-			ledView = new Led3D(cubeCanvas);
277
-			cubeCanvas.setBounds(18, 31, 275, 275); // 3d view
278
-			cubeCanvas.addMouseListener(new MouseListener() { // React to clicks in 3d view
279
-				public void mouseClicked(MouseEvent e) {
280
-					Point2d mousePos = convertMousePositionToWorld(e.getX(), e.getY()); 
281
-				}
282
-				public void mouseExited(MouseEvent e) {
283
-	
284
-				}
285
-				public void mouseEntered(MouseEvent e) {
286
-	
287
-				}
288
-				public void mouseReleased(MouseEvent e) {
289
-	
290
-				}
291
-				public void mousePressed(MouseEvent e) {
292
-	
293
-				}
294
-			});
295
-			cp.add(cubeCanvas);
296
-		} catch (Exception e) {
297
-			System.out.println("ERROR: No 3D available!");
298
-		}
273
+		/* gConfig = SimpleUniverse.getPreferredConfiguration();
274
+		cubeCanvas = new Canvas3D(gConfig);
275
+		ledView = new Led3D(cubeCanvas);
276
+		cubeCanvas.setBounds(18, 31, 275, 275); // 3d view
277
+		cubeCanvas.addMouseListener(new MouseListener() { // React to clicks in 3d view
278
+			public void mouseClicked(MouseEvent e) {
279
+				Point2d mousePos = convertMousePositionToWorld(e.getX(), e.getY()); 
280
+			}
281
+			public void mouseExited(MouseEvent e) {
282
+
283
+			}
284
+			public void mouseEntered(MouseEvent e) {
285
+
286
+			}
287
+			public void mouseReleased(MouseEvent e) {
288
+
289
+			}
290
+			public void mousePressed(MouseEvent e) {
291
+
292
+			}
293
+		});
294
+		cp.add(cubeCanvas); */
299 295
 		// --------------------
300 296
 
301 297
 		// Add Layer edit buttons
@@ -779,7 +775,7 @@ public class Frame extends JFrame implements ListSelectionListener {
779 775
 		cp.add(serialPanel);
780 776
 	
781 777
 		settingsPanel.setBounds(409, 100, 243, 65);
782
-		settingsPanel.setBorder(BorderFactory.createTitledBorder("Serial communication"));
778
+		settingsPanel.setBorder(BorderFactory.createTitledBorder("Frame duration"));
783 779
 		cp.add(settingsPanel);
784 780
 	
785 781
 		// Ende Komponenten

+ 28
- 32
CubeControl/HelperUtility.java View File

@@ -88,31 +88,16 @@ public class HelperUtility {
88 88
 			} catch (NullPointerException e) {
89 89
 				System.out.println("ERROR: Library name is null!");
90 90
 				return;
91
+			} catch (Exception e) {
92
+				System.out.println("ERROR: " + e.toString());
93
+				return;
91 94
 			}
92 95
 			System.out.println("Loaded Serial Library at \"" + path + "\"");
96
+			return;
93 97
 		} catch (Exception e) {
94 98
 			System.out.println("ERROR: Failed to load Serial Library:");
95 99
 			e.printStackTrace();
96
-		}
97
-	}
98
-
99
-	// http://thomaswabner.wordpress.com/2007/10/09/fast-stream-copy-using-javanio-channels/
100
-	private static void fastChannelCopy(ReadableByteChannel src, WritableByteChannel dest) throws IOException {
101
-		ByteBuffer buffer = ByteBuffer.allocateDirect(16 * 1024);
102
-		while (src.read(buffer) != -1) {
103
-			// prepare the buffer to be drained
104
-			buffer.flip();
105
-			// write to the channel, may block
106
-			dest.write(buffer);
107
-			// If partial transfer, shift remainder down
108
-			// If buffer is empty, same as doing clear()
109
-			buffer.compact();
110
-		}
111
-		// EOF will leave buffer in fill state
112
-		buffer.flip();
113
-		// make sure the buffer is fully drained.
114
-		while (buffer.hasRemaining()) {
115
-			dest.write(buffer);
100
+			return;
116 101
 		}
117 102
 	}
118 103
 
@@ -122,10 +107,11 @@ public class HelperUtility {
122 107
 	 * @return Array of port names. First entry is "No serial ports!" if no
123 108
 	 *         others
124 109
 	 */
110
+	// Get ports as single String from getPortsOS() and put them in an array
125 111
 	public static String[] getPorts() {
126 112
 		String portLines = getPortsOS();
127 113
 		if (portLines == null) {
128
-			String[] ports = { "Select serial port..." };
114
+			String[] ports = { "No serial ports!" };
129 115
 			return ports;
130 116
 		} else {
131 117
 			StringTokenizer sT = new StringTokenizer(portLines, "\n");
@@ -153,15 +139,9 @@ public class HelperUtility {
153 139
 			} else {
154 140
 				return getThePorts("tty");
155 141
 			} 
156
-		} catch (Exception e) {
157
-			System.out.println("Exception: " + e.toString());
158
-			return null;
159 142
 		} catch (UnsatisfiedLinkError e) {
160 143
 			System.out.println("ERROR: Library not loaded! (getPorts)");
161
-			// System.out.println(e.toString());
162
-			// Show error message because this is called in the initializer.
163
-			Frame.errorMessageStat("Could not load Serial Library!\nNo Serial functionality available!");
164
-			return null;
144
+			return "Serial Library Error!\n";
165 145
 		}
166 146
 	}
167 147
 
@@ -179,7 +159,6 @@ public class HelperUtility {
179 159
 			return openPortNative(name);
180 160
 		} catch (UnsatisfiedLinkError e) {
181 161
 			System.out.println("ERROR: Library not loaded! (openPort)");
182
-			// System.out.println(e.toString());
183 162
 			return false;
184 163
 		}
185 164
 	}
@@ -194,7 +173,6 @@ public class HelperUtility {
194 173
 			closePortNative();
195 174
 		} catch (UnsatisfiedLinkError e) {
196 175
 			System.out.println("ERROR: Library not loaded! (closePort)");
197
-			// System.out.println(e.toString());
198 176
 		}
199 177
 	}
200 178
 
@@ -212,7 +190,6 @@ public class HelperUtility {
212 190
 			return readDataNative(length);
213 191
 		} catch (UnsatisfiedLinkError e) {
214 192
 			System.out.println("ERROR: Library not loaded! (readData)");
215
-			// System.out.println(e.toString());
216 193
 			return null;
217 194
 		}
218 195
 	}
@@ -232,9 +209,28 @@ public class HelperUtility {
232 209
 			writeDataNative(data, length);
233 210
 		} catch (UnsatisfiedLinkError e) {
234 211
 			System.out.println("ERROR: Library not loaded! (writeData)");
235
-			// System.out.println(e.toString());
236 212
 		}
237 213
 	}
238 214
 
239 215
 	private static native void writeDataNative(short[] data, int length);
216
+
217
+	// http://thomaswabner.wordpress.com/2007/10/09/fast-stream-copy-using-javanio-channels/
218
+	private static void fastChannelCopy(ReadableByteChannel src, WritableByteChannel dest) throws IOException {
219
+		ByteBuffer buffer = ByteBuffer.allocateDirect(16 * 1024);
220
+		while (src.read(buffer) != -1) {
221
+			// prepare the buffer to be drained
222
+			buffer.flip();
223
+			// write to the channel, may block
224
+			dest.write(buffer);
225
+			// If partial transfer, shift remainder down
226
+			// If buffer is empty, same as doing clear()
227
+			buffer.compact();
228
+		}
229
+		// EOF will leave buffer in fill state
230
+		buffer.flip();
231
+		// make sure the buffer is fully drained.
232
+		while (buffer.hasRemaining()) {
233
+			dest.write(buffer);
234
+		}
235
+	}
240 236
 }

+ 4
- 15
CubeControl/libSerial/makefile View File

@@ -2,13 +2,13 @@ CC = gcc
2 2
 STANDARD = gnu99
3 3
 # Path to jni.h
4 4
 ifdef SystemRoot
5
-HEADERPATH = C:/Program\ Files/Java/jdk1.6.0_29/include
5
+HEADERPATH = C:/Program\ Files/Java/jdk1.6.0_31/include
6 6
 RM = del
7 7
 else
8 8
 ifdef SYSTEMROOT
9 9
 # Looks like Cygwin or Mingw shell
10
-HEADERPATH = C:\Programme\Java\jdk1.6.0_07\include
11
-HEADERPATH += -IC:\Programme\Java\jdk1.6.0_07\include\win32
10
+HEADERPATH = C:\Programme\Java\jdk1.6.0_31\include
11
+HEADERPATH += -IC:\Programme\Java\jdk1.6.0_31\include\win32
12 12
 RM = rm -rf
13 13
 else
14 14
 RM = rm -f
@@ -25,15 +25,6 @@ endif
25 25
 
26 26
 all: libSerial
27 27
 
28
-doc: doc/index.html
29
-
30
-serialInterface.h: HelperUtility.class
31
-	javah -o serialInterface.h HelperUtility
32
-
33
-HelperUtility.class: ../HelperUtility.java
34
-	javac -sourcepath ../ ../HelperUtility.java
35
-	cp ../HelperUtility.class HelperUtility.class
36
-
37 28
 # SystemRoot is only defined in Windows
38 29
 ifdef SystemRoot
39 30
 libSerial: Serial.dll
@@ -58,13 +49,11 @@ libSerial.so: serialHelper.c unixSerial.c serialInterface.h
58 49
 	$(CC) -dynamiclib -o libSerial.so serialHelper.o
59 50
 
60 51
 Serial.dll: serialHelper.c winSerial.c serialInterface.h
61
-	$(CC) -x c -std=$(STANDARD) -I$(HEADERPATH) -c serialHelper.c -o serialHelper.o -D winHelper
52
+	$(CC) -x c -std=$(STANDARD) -DBUILDINGDLL -I$(HEADERPATH) -c serialHelper.c -o serialHelper.o -D winHelper
62 53
 	$(CC) -shared -o Serial.dll serialHelper.o
63 54
 
64 55
 # Delete intermediate files
65 56
 clean:
66
-	$(RM) *.class
67
-	$(RM) *.h
68 57
 	$(RM) *.o
69 58
 ifdef SystemRoot
70 59
 	$(RM) *.dll

+ 62
- 0
CubeControl/libSerial/serialInterface.h View File

@@ -0,0 +1,62 @@
1
+#include <jni.h>
2
+/* Header for class HelperUtility */
3
+
4
+#ifdef winHelper
5
+#ifdef BUILDINGDLL
6
+#define DLL __declspec(dllexport)
7
+#else
8
+#define DLL __declspec(dllimport)
9
+#endif
10
+#else
11
+#define DLL
12
+#endif
13
+
14
+#ifndef _Included_HelperUtility
15
+#define _Included_HelperUtility
16
+#ifdef __cplusplus
17
+extern "C" {
18
+#endif
19
+/*
20
+ * Class:     HelperUtility
21
+ * Method:    getThePorts
22
+ * Signature: (Ljava/lang/String;)Ljava/lang/String;
23
+ */
24
+JNIEXPORT jstring DLL JNICALL Java_HelperUtility_getThePorts
25
+  (JNIEnv *, jclass, jstring);
26
+
27
+/*
28
+ * Class:     HelperUtility
29
+ * Method:    openPortNative
30
+ * Signature: (Ljava/lang/String;)Z
31
+ */
32
+JNIEXPORT jboolean DLL JNICALL Java_HelperUtility_openPortNative
33
+  (JNIEnv *, jclass, jstring);
34
+
35
+/*
36
+ * Class:     HelperUtility
37
+ * Method:    closePortNative
38
+ * Signature: ()V
39
+ */
40
+JNIEXPORT void DLL JNICALL Java_HelperUtility_closePortNative
41
+  (JNIEnv *, jclass);
42
+
43
+/*
44
+ * Class:     HelperUtility
45
+ * Method:    readDataNative
46
+ * Signature: (I)[S
47
+ */
48
+JNIEXPORT jshortArray DLL JNICALL Java_HelperUtility_readDataNative
49
+  (JNIEnv *, jclass, jint);
50
+
51
+/*
52
+ * Class:     HelperUtility
53
+ * Method:    writeDataNative
54
+ * Signature: ([SI)V
55
+ */
56
+JNIEXPORT void DLL JNICALL Java_HelperUtility_writeDataNative
57
+  (JNIEnv *, jclass, jshortArray, jint);
58
+
59
+#ifdef __cplusplus
60
+}
61
+#endif
62
+#endif

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

@@ -118,7 +118,7 @@ int availableSerialPorts(char *ports) {
118 118
 }
119 119
 
120 120
 // Last element has to be NULL
121
-char** getSerialPorts(char *search) {
121
+char** getSerialPorts(const char *search) {
122 122
 	int i, num, c = 0, s;
123 123
 	char ports[20];
124 124
 	char **portList;

+ 0
- 6
CubeControl/makefile View File

@@ -1,15 +1,12 @@
1 1
 INJAR = *.class LEDoff.png LEDon.png splash.png bg.png
2 2
 # Path to jni.h
3 3
 ifdef SystemRoot
4
-HEADERPATH = C:/Program\ Files/Java/jdk1.6.0_29/include
5 4
 RM = del
6 5
 INJAR += Serial.dll
7 6
 PLATFORM = Win
8 7
 else
9 8
 ifdef SYSTEMROOT
10 9
 # Looks like cygwin or mingw shell
11
-HEADERPATH = C:\Programme\Java\jdk1.6.0_31\include
12
-HEADERPATH += -IC:\Programme\Java\jdk1.6.0_31\include\win32
13 10
 RM = rm -rf
14 11
 INJAR += Serial.dll
15 12
 PLATFORM = Win
@@ -19,11 +16,9 @@ UNAME := $(shell uname -s)
19 16
 ifeq ($(UNAME),Darwin)
20 17
 INJAR += libSerial.jnilib
21 18
 PLATFORM = Mac
22
-HEADERPATH = /System/Library/Frameworks/JavaVM.framework/Headers
23 19
 else
24 20
 INJAR += libSerial.so
25 21
 PLATFORM = Linux
26
-HEADERPATH = /usr/lib/jvm/java-6-openjdk/include
27 22
 endif
28 23
 endif
29 24
 endif
@@ -80,7 +75,6 @@ libSerial.so: libSerial/serialHelper.c libSerial/unixSerial.c
80 75
 clean:
81 76
 	make -C libSerial clean
82 77
 	$(RM) *.class
83
-	$(RM) *.
84 78
 	$(RM) *.o
85 79
 ifdef SystemRoot
86 80
 	$(RM) *.dll

Loading…
Cancel
Save