Browse Source

Tried fixing windows library problems.

Serial library is still not loaded correctly on the PCs in our school...
Thomas Buck 12 years ago
parent
commit
bf5c1a3943

+ 23
- 3
CubeControl/Frame.java View File

94
 	public cubeWorker worker = new cubeWorker(this);
94
 	public cubeWorker worker = new cubeWorker(this);
95
 	private boolean fileSelected = false;
95
 	private boolean fileSelected = false;
96
 	private Frame thisFrame;
96
 	private Frame thisFrame;
97
+	private static Frame recentFrame;
97
 
98
 
98
 	// Ende Variablen
99
 	// Ende Variablen
99
 
100
 
141
 		JOptionPane.showOptionDialog(this, msg, title, JOptionPane.YES_OPTION,
142
 		JOptionPane.showOptionDialog(this, msg, title, JOptionPane.YES_OPTION,
142
 			JOptionPane.ERROR_MESSAGE, null, Optionen, Optionen[0]);
143
 			JOptionPane.ERROR_MESSAGE, null, Optionen, Optionen[0]);
143
 	}
144
 	}
145
+
146
+	/**
147
+	 * Show an error message to the user via the most recent Frame.
148
+	 * @param s Error Message
149
+	 */
150
+	public static void errorMessageStat(String s) {
151
+		recentFrame.errorMessage(s);
152
+	}
153
+
154
+	/**
155
+	 *	Show an error message to the user via the most recent Frame.
156
+	 * @param title Title of message box
157
+	 * @param msg Error message.
158
+	 */
159
+	public static void errorMessageStat(String title, String msg) {
160
+		recentFrame.errorMessage(title, msg);
161
+	}
144
 	
162
 	
145
 	/**
163
 	/**
146
 	 * ListSelectionListener that updates Anim & Frame List
164
 	 * ListSelectionListener that updates Anim & Frame List
209
 	public Frame(String title) {
227
 	public Frame(String title) {
210
 		super(title);
228
 		super(title);
211
 		thisFrame = this;
229
 		thisFrame = this;
230
+		recentFrame = this;
212
 		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
231
 		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
213
 
232
 
214
 		// Build serial port selection
233
 		// Build serial port selection
241
 		int frameHeight = 646;
260
 		int frameHeight = 646;
242
 		setSize(frameWidth, frameHeight);
261
 		setSize(frameWidth, frameHeight);
243
 		Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
262
 		Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
244
-		int x = (d.width - getSize().width) / 2;
245
-		int y = (d.height - getSize().height) / 2;
246
-		setLocation(x, y);
263
+		// int x = (d.width - getSize().width) / 2;
264
+		// int y = (d.height - getSize().height) / 2;
265
+		// setLocation(x, y);
266
+		setLocation(10, 10);
247
 		Container cp = getContentPane();
267
 		Container cp = getContentPane();
248
 		cp.setLayout(null);
268
 		cp.setLayout(null);
249
 		Font font = new Font("Dialog", Font.PLAIN, 13);
269
 		Font font = new Font("Dialog", Font.PLAIN, 13);

+ 68
- 16
CubeControl/HelperUtility.java View File

62
 
62
 
63
 	/**
63
 	/**
64
 	 * Puts library to temp dir and loads to memory
64
 	 * Puts library to temp dir and loads to memory
65
+	 * @param path Put in front of file name
66
+	 * @param Complete name of file to load (w/ lib & .dll)
65
 	 */
67
 	 */
66
 	private static void loadLib(String path, String name) {
68
 	private static void loadLib(String path, String name) {
67
 		try {
69
 		try {
68
 			// have to use a stream
70
 			// have to use a stream
69
 			InputStream in = HelperUtility.class.getResourceAsStream(name);
71
 			InputStream in = HelperUtility.class.getResourceAsStream(name);
70
-			// System.out.println("Input Stream: " + in);
71
-			File fileOut = new File(System.getProperty("java.io.tmpdir") + "/"
72
-					+ path + name);
72
+			File fileOut = new File(System.getProperty("java.io.tmpdir") + "/" + path + name);
73
 			OutputStream out = new FileOutputStream(fileOut);
73
 			OutputStream out = new FileOutputStream(fileOut);
74
 			ReadableByteChannel inChannel = Channels.newChannel(in);
74
 			ReadableByteChannel inChannel = Channels.newChannel(in);
75
 			WritableByteChannel outChannel = Channels.newChannel(out);
75
 			WritableByteChannel outChannel = Channels.newChannel(out);
76
 			fastChannelCopy(inChannel, outChannel);
76
 			fastChannelCopy(inChannel, outChannel);
77
 			inChannel.close();
77
 			inChannel.close();
78
 			outChannel.close();
78
 			outChannel.close();
79
-			System.load(fileOut.toString());
80
-			System.out.println("Loaded Serial Library!");
79
+			path = fileOut.getPath();
80
+			try {
81
+				System.load(path);
82
+			} catch (UnsatisfiedLinkError e) {
83
+				System.out.println("ERROR: Library does not exist!");
84
+				return;
85
+			} catch (SecurityException e) {
86
+				System.out.println("ERROR: Not allowed to load Library!");
87
+				return;
88
+			} catch (NullPointerException e) {
89
+				System.out.println("ERROR: Library name is null!");
90
+				return;
91
+			}
92
+			System.out.println("Loaded Serial Library at \"" + path + "\"");
81
 		} catch (Exception e) {
93
 		} catch (Exception e) {
82
-			System.out.println("Failed to load Serial Library:");
94
+			System.out.println("ERROR: Failed to load Serial Library:");
83
 			e.printStackTrace();
95
 			e.printStackTrace();
84
-			System.exit(1);
85
 		}
96
 		}
86
 	}
97
 	}
87
 
98
 
88
 	// http://thomaswabner.wordpress.com/2007/10/09/fast-stream-copy-using-javanio-channels/
99
 	// http://thomaswabner.wordpress.com/2007/10/09/fast-stream-copy-using-javanio-channels/
89
-	private static void fastChannelCopy(ReadableByteChannel src,
90
-			WritableByteChannel dest) throws IOException {
100
+	private static void fastChannelCopy(ReadableByteChannel src, WritableByteChannel dest) throws IOException {
91
 		ByteBuffer buffer = ByteBuffer.allocateDirect(16 * 1024);
101
 		ByteBuffer buffer = ByteBuffer.allocateDirect(16 * 1024);
92
 		while (src.read(buffer) != -1) {
102
 		while (src.read(buffer) != -1) {
93
 			// prepare the buffer to be drained
103
 			// prepare the buffer to be drained
142
 				return getThePorts("tty.");
152
 				return getThePorts("tty.");
143
 			} else {
153
 			} else {
144
 				return getThePorts("tty");
154
 				return getThePorts("tty");
145
-			}
155
+			} 
146
 		} catch (Exception e) {
156
 		} catch (Exception e) {
147
-			// Unsatisfied linker error:
148
-			// Serial.dll was probably not found
149
 			System.out.println("Exception: " + e.toString());
157
 			System.out.println("Exception: " + e.toString());
150
 			return null;
158
 			return null;
159
+		} catch (UnsatisfiedLinkError e) {
160
+			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;
151
 		}
165
 		}
152
 	}
166
 	}
153
 
167
 
160
 	 * @param name
174
 	 * @param name
161
 	 *            Port to open
175
 	 *            Port to open
162
 	 */
176
 	 */
163
-	public static native boolean openPort(String name);
177
+	public static boolean openPort(String name) {
178
+		try {
179
+			return openPortNative(name);
180
+		} catch (UnsatisfiedLinkError e) {
181
+			System.out.println("ERROR: Library not loaded! (openPort)");
182
+			// System.out.println(e.toString());
183
+			return false;
184
+		}
185
+	}
186
+
187
+	private static native boolean openPortNative(String name);
164
 
188
 
165
 	/**
189
 	/**
166
 	 * Close Connection to port
190
 	 * Close Connection to port
167
 	 */
191
 	 */
168
-	public static native void closePort();
192
+	public static void closePort() {
193
+		try {
194
+			closePortNative();
195
+		} catch (UnsatisfiedLinkError e) {
196
+			System.out.println("ERROR: Library not loaded! (closePort)");
197
+			// System.out.println(e.toString());
198
+		}
199
+	}
200
+
201
+	private static native void closePortNative();
169
 
202
 
170
 	/**
203
 	/**
171
 	 * Read data from Cube
204
 	 * Read data from Cube
174
 	 *            Amount of data to read
207
 	 *            Amount of data to read
175
 	 * @return Data read
208
 	 * @return Data read
176
 	 */
209
 	 */
177
-	public static native short[] readData(int length);
210
+	public static short[] readData(int length) {
211
+		try {
212
+			return readDataNative(length);
213
+		} catch (UnsatisfiedLinkError e) {
214
+			System.out.println("ERROR: Library not loaded! (readData)");
215
+			// System.out.println(e.toString());
216
+			return null;
217
+		}
218
+	}
219
+
220
+	private static native short[] readDataNative(int length);
178
 
221
 
179
 	/**
222
 	/**
180
 	 * Write data to Cube
223
 	 * Write data to Cube
184
 	 * @param length
227
 	 * @param length
185
 	 *            Length of data
228
 	 *            Length of data
186
 	 */
229
 	 */
187
-	public static native void writeData(short[] data, int length);
230
+	public static void writeData(short[] data, int length) {
231
+		try {
232
+			writeDataNative(data, length);
233
+		} catch (UnsatisfiedLinkError e) {
234
+			System.out.println("ERROR: Library not loaded! (writeData)");
235
+			// System.out.println(e.toString());
236
+		}
237
+	}
238
+
239
+	private static native void writeDataNative(short[] data, int length);
188
 }
240
 }

+ 2
- 2
CubeControl/libSerial/makefile View File

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_31\include
11
-HEADERPATH += -IC:\Programme\Java\jdk1.6.0_31\include\win32
10
+HEADERPATH = C:\Programme\Java\jdk1.6.0_07\include
11
+HEADERPATH += -IC:\Programme\Java\jdk1.6.0_07\include\win32
12
 RM = rm -rf
12
 RM = rm -rf
13
 else
13
 else
14
 RM = rm -f
14
 RM = rm -f

+ 4
- 4
CubeControl/libSerial/serialHelper.c View File

79
 	return ret;
79
 	return ret;
80
 }
80
 }
81
 
81
 
82
-JNIEXPORT jshortArray JNICALL Java_HelperUtility_readData(JNIEnv *env, jclass class, jint length) {
82
+JNIEXPORT jshortArray JNICALL Java_HelperUtility_readDataNative(JNIEnv *env, jclass class, jint length) {
83
 	jshortArray arr = (*env)->NewShortArray(env, length);
83
 	jshortArray arr = (*env)->NewShortArray(env, length);
84
 	int toBeRead = 0, read, i;
84
 	int toBeRead = 0, read, i;
85
 	char *data = (char *)malloc(length * sizeof(char));
85
 	char *data = (char *)malloc(length * sizeof(char));
98
 	return arr;
98
 	return arr;
99
 }
99
 }
100
 
100
 
101
-JNIEXPORT void JNICALL Java_HelperUtility_writeData(JNIEnv *env, jclass class, jshortArray data, jint length) {
101
+JNIEXPORT void JNICALL Java_HelperUtility_writeDataNative(JNIEnv *env, jclass class, jshortArray data, jint length) {
102
 	int toWrite = length, written = 0, now, i;
102
 	int toWrite = length, written = 0, now, i;
103
 	char *dat = (char *)malloc(length * sizeof(char));
103
 	char *dat = (char *)malloc(length * sizeof(char));
104
 	jshort *dat2 = (jshort *)malloc(length * sizeof(jshort));
104
 	jshort *dat2 = (jshort *)malloc(length * sizeof(jshort));
114
 	}
114
 	}
115
 }
115
 }
116
 
116
 
117
-JNIEXPORT void JNICALL Java_HelperUtility_closePort(JNIEnv * env, jclass class) {
117
+JNIEXPORT void JNICALL Java_HelperUtility_closePortNative(JNIEnv * env, jclass class) {
118
 	serialClose();
118
 	serialClose();
119
 }
119
 }
120
 
120
 
121
-JNIEXPORT jboolean JNICALL Java_HelperUtility_openPort(JNIEnv *env, jclass class, jstring name) {
121
+JNIEXPORT jboolean JNICALL Java_HelperUtility_openPortNative(JNIEnv *env, jclass class, jstring name) {
122
 	jboolean isCopy;
122
 	jboolean isCopy;
123
 	const char *path = (*env)->GetStringUTFChars(env, name, &isCopy);
123
 	const char *path = (*env)->GetStringUTFChars(env, name, &isCopy);
124
 	int ret = serialOpen((char *)path);
124
 	int ret = serialOpen((char *)path);

Loading…
Cancel
Save