Thomas Buck 12 лет назад
Родитель
Сommit
91d328c955
3 измененных файлов: 41 добавлений и 10 удалений
  1. 13
    7
      CubeControl/Frame.java
  2. 20
    0
      CubeControl/SerialHelper.java
  3. 8
    3
      CubeControl/cubeWorker.java

+ 13
- 7
CubeControl/Frame.java Просмотреть файл

896
 		}
896
 		}
897
 	}
897
 	}
898
 
898
 
899
+	// We get detailed error messages from the SerialHelper...
899
 	public void upload_ActionPerformed(ActionEvent evt) {
900
 	public void upload_ActionPerformed(ActionEvent evt) {
900
 		if (jComboBox1.getSelectedItem().equals("Select serial port...")) {
901
 		if (jComboBox1.getSelectedItem().equals("Select serial port...")) {
901
-			errorMessage("No serial port selected...");
902
+			// errorMessage("No serial port selected...");
902
 		} else {
903
 		} else {
903
-			if (worker
904
-					.probeCubeConnected((String) jComboBox1.getSelectedItem())) {
904
+			if (worker.probeCubeConnected((String) jComboBox1.getSelectedItem())) {
905
 				if (worker.uploadState((String) jComboBox1.getSelectedItem()) != 0) {
905
 				if (worker.uploadState((String) jComboBox1.getSelectedItem()) != 0) {
906
-					errorMessage("Could not upload data!");
906
+					// errorMessage("Could not upload data!");
907
 				}
907
 				}
908
 			} else {
908
 			} else {
909
-				errorMessage("Cube does not respond...");
909
+				// errorMessage("Cube does not respond...");
910
 			}
910
 			}
911
 		}
911
 		}
912
 	}
912
 	}
913
 
913
 
914
 	public void download_ActionPerformed(ActionEvent evt) {
914
 	public void download_ActionPerformed(ActionEvent evt) {
915
 		if (jComboBox1.getSelectedItem().equals("Select serial port...")) {
915
 		if (jComboBox1.getSelectedItem().equals("Select serial port...")) {
916
-			errorMessage("No serial port selected...");
916
+			// errorMessage("No serial port selected...");
917
 		} else {
917
 		} else {
918
-			worker.downloadState((String) jComboBox1.getSelectedItem());
918
+			if (worker.probeCubeConnected((String) jComboBox1.getSelectedItem())) {
919
+				if (worker.downloadState((String) jComboBox1.getSelectedItem()) != 0) {
920
+					// errorMessage("Could not download data!");
921
+				}
922
+			} else {
923
+				// errorMessage("Cube does not respond...");
924
+			}
919
 		}
925
 		}
920
 	}
926
 	}
921
 
927
 

+ 20
- 0
CubeControl/SerialHelper.java Просмотреть файл

48
 	 */
48
 	 */
49
 	public SerialHelper(String serialPort, Frame frame) throws Exception {
49
 	public SerialHelper(String serialPort, Frame frame) throws Exception {
50
 		if (HelperUtility.openPort(serialPort) == false) {
50
 		if (HelperUtility.openPort(serialPort) == false) {
51
+			printErrorMessage("Could not open serial port \"" + serialPort + "\"");
51
 			throw new Exception("Could not open serial port \"" + serialPort + "\"");
52
 			throw new Exception("Could not open serial port \"" + serialPort + "\"");
52
 		}
53
 		}
53
 		this.frame = frame;
54
 		this.frame = frame;
54
 	}
55
 	}
55
 
56
 
56
 	/**
57
 	/**
58
+	 * Poll to check if the cube is there...
59
+	 * @return TRUE if cube is connected.
60
+	 */
61
+	public boolean probeForCube() {
62
+		short[] data = new short[1];
63
+		data[0] = OK;
64
+		if (!writeData(data)) {
65
+			printErrorMessage("Timeout Probing for Cube");
66
+			return false;
67
+		}
68
+		data = readData(1);
69
+		if ((data == null) || (data[0] != OK)) {
70
+			printErrorMessage("No response from cube!");
71
+			return false;
72
+		}
73
+		return true;
74
+	}
75
+
76
+	/**
57
 	 * Recieve all animations saved in cube.
77
 	 * Recieve all animations saved in cube.
58
 	 * @return A cubeWorker populated with the new data or null.
78
 	 * @return A cubeWorker populated with the new data or null.
59
 	 */
79
 	 */

+ 8
- 3
CubeControl/cubeWorker.java Просмотреть файл

426
 			sh.closeSerialPort();
426
 			sh.closeSerialPort();
427
 			return ret;
427
 			return ret;
428
 		} catch (Exception e) {
428
 		} catch (Exception e) {
429
-			System.out.println("Serial Exception: " + e.getMessage());
430
 			return -1;
429
 			return -1;
431
 		}
430
 		}
432
 	}
431
 	}
450
 				return 0;
449
 				return 0;
451
 			}
450
 			}
452
 		} catch (Exception e) {
451
 		} catch (Exception e) {
453
-			System.out.println("Serial Exception: " + e.getMessage());
454
 			return -1;
452
 			return -1;
455
 		}
453
 		}
456
 	}
454
 	}
470
 	 * @param port Name of serial port
468
 	 * @param port Name of serial port
471
 	 */
469
 	 */
472
 	public boolean probeCubeConnected(String port) {
470
 	public boolean probeCubeConnected(String port) {
473
-		return false;
471
+		try {
472
+			SerialHelper sh = new SerialHelper(port, parentFrame);
473
+			boolean response = sh.probeForCube();
474
+			sh.closeSerialPort();
475
+			return response;
476
+		} catch (Exception e) {
477
+			return false;
478
+		}
474
 	}
479
 	}
475
 
480
 
476
 	/**
481
 	/**

Загрузка…
Отмена
Сохранить