Browse Source

Tried fixing serial library for windows...

unknown 12 years ago
parent
commit
b495b5e0cc

+ 23
- 27
CubeControl/Frame.java View File

270
 
270
 
271
 		// ----- 3D Stuff -----
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
 		// Add Layer edit buttons
297
 		// Add Layer edit buttons
779
 		cp.add(serialPanel);
775
 		cp.add(serialPanel);
780
 	
776
 	
781
 		settingsPanel.setBounds(409, 100, 243, 65);
777
 		settingsPanel.setBounds(409, 100, 243, 65);
782
-		settingsPanel.setBorder(BorderFactory.createTitledBorder("Serial communication"));
778
+		settingsPanel.setBorder(BorderFactory.createTitledBorder("Frame duration"));
783
 		cp.add(settingsPanel);
779
 		cp.add(settingsPanel);
784
 	
780
 	
785
 		// Ende Komponenten
781
 		// Ende Komponenten

+ 28
- 32
CubeControl/HelperUtility.java View File

88
 			} catch (NullPointerException e) {
88
 			} catch (NullPointerException e) {
89
 				System.out.println("ERROR: Library name is null!");
89
 				System.out.println("ERROR: Library name is null!");
90
 				return;
90
 				return;
91
+			} catch (Exception e) {
92
+				System.out.println("ERROR: " + e.toString());
93
+				return;
91
 			}
94
 			}
92
 			System.out.println("Loaded Serial Library at \"" + path + "\"");
95
 			System.out.println("Loaded Serial Library at \"" + path + "\"");
96
+			return;
93
 		} catch (Exception e) {
97
 		} catch (Exception e) {
94
 			System.out.println("ERROR: Failed to load Serial Library:");
98
 			System.out.println("ERROR: Failed to load Serial Library:");
95
 			e.printStackTrace();
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
 	 * @return Array of port names. First entry is "No serial ports!" if no
107
 	 * @return Array of port names. First entry is "No serial ports!" if no
123
 	 *         others
108
 	 *         others
124
 	 */
109
 	 */
110
+	// Get ports as single String from getPortsOS() and put them in an array
125
 	public static String[] getPorts() {
111
 	public static String[] getPorts() {
126
 		String portLines = getPortsOS();
112
 		String portLines = getPortsOS();
127
 		if (portLines == null) {
113
 		if (portLines == null) {
128
-			String[] ports = { "Select serial port..." };
114
+			String[] ports = { "No serial ports!" };
129
 			return ports;
115
 			return ports;
130
 		} else {
116
 		} else {
131
 			StringTokenizer sT = new StringTokenizer(portLines, "\n");
117
 			StringTokenizer sT = new StringTokenizer(portLines, "\n");
153
 			} else {
139
 			} else {
154
 				return getThePorts("tty");
140
 				return getThePorts("tty");
155
 			} 
141
 			} 
156
-		} catch (Exception e) {
157
-			System.out.println("Exception: " + e.toString());
158
-			return null;
159
 		} catch (UnsatisfiedLinkError e) {
142
 		} catch (UnsatisfiedLinkError e) {
160
 			System.out.println("ERROR: Library not loaded! (getPorts)");
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
 			return openPortNative(name);
159
 			return openPortNative(name);
180
 		} catch (UnsatisfiedLinkError e) {
160
 		} catch (UnsatisfiedLinkError e) {
181
 			System.out.println("ERROR: Library not loaded! (openPort)");
161
 			System.out.println("ERROR: Library not loaded! (openPort)");
182
-			// System.out.println(e.toString());
183
 			return false;
162
 			return false;
184
 		}
163
 		}
185
 	}
164
 	}
194
 			closePortNative();
173
 			closePortNative();
195
 		} catch (UnsatisfiedLinkError e) {
174
 		} catch (UnsatisfiedLinkError e) {
196
 			System.out.println("ERROR: Library not loaded! (closePort)");
175
 			System.out.println("ERROR: Library not loaded! (closePort)");
197
-			// System.out.println(e.toString());
198
 		}
176
 		}
199
 	}
177
 	}
200
 
178
 
212
 			return readDataNative(length);
190
 			return readDataNative(length);
213
 		} catch (UnsatisfiedLinkError e) {
191
 		} catch (UnsatisfiedLinkError e) {
214
 			System.out.println("ERROR: Library not loaded! (readData)");
192
 			System.out.println("ERROR: Library not loaded! (readData)");
215
-			// System.out.println(e.toString());
216
 			return null;
193
 			return null;
217
 		}
194
 		}
218
 	}
195
 	}
232
 			writeDataNative(data, length);
209
 			writeDataNative(data, length);
233
 		} catch (UnsatisfiedLinkError e) {
210
 		} catch (UnsatisfiedLinkError e) {
234
 			System.out.println("ERROR: Library not loaded! (writeData)");
211
 			System.out.println("ERROR: Library not loaded! (writeData)");
235
-			// System.out.println(e.toString());
236
 		}
212
 		}
237
 	}
213
 	}
238
 
214
 
239
 	private static native void writeDataNative(short[] data, int length);
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
 STANDARD = gnu99
2
 STANDARD = gnu99
3
 # Path to jni.h
3
 # Path to jni.h
4
 ifdef SystemRoot
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
 RM = del
6
 RM = del
7
 else
7
 else
8
 ifdef SYSTEMROOT
8
 ifdef SYSTEMROOT
9
 # Looks like Cygwin or Mingw shell
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
 RM = rm -rf
12
 RM = rm -rf
13
 else
13
 else
14
 RM = rm -f
14
 RM = rm -f
25
 
25
 
26
 all: libSerial
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
 # SystemRoot is only defined in Windows
28
 # SystemRoot is only defined in Windows
38
 ifdef SystemRoot
29
 ifdef SystemRoot
39
 libSerial: Serial.dll
30
 libSerial: Serial.dll
58
 	$(CC) -dynamiclib -o libSerial.so serialHelper.o
49
 	$(CC) -dynamiclib -o libSerial.so serialHelper.o
59
 
50
 
60
 Serial.dll: serialHelper.c winSerial.c serialInterface.h
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
 	$(CC) -shared -o Serial.dll serialHelper.o
53
 	$(CC) -shared -o Serial.dll serialHelper.o
63
 
54
 
64
 # Delete intermediate files
55
 # Delete intermediate files
65
 clean:
56
 clean:
66
-	$(RM) *.class
67
-	$(RM) *.h
68
 	$(RM) *.o
57
 	$(RM) *.o
69
 ifdef SystemRoot
58
 ifdef SystemRoot
70
 	$(RM) *.dll
59
 	$(RM) *.dll

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

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

+ 0
- 6
CubeControl/makefile View File

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

Loading…
Cancel
Save