|
@@ -67,7 +67,7 @@ public class Frame extends JFrame implements ListSelectionListener {
|
67
|
67
|
private JButton load = new JButton();
|
68
|
68
|
private JButton save = new JButton();
|
69
|
69
|
private JButton saveAs = new JButton();
|
70
|
|
- private JComboBox jComboBox1 = new JComboBox();
|
|
70
|
+ public JComboBox jComboBox1 = new JComboBox();
|
71
|
71
|
private JButton upload = new JButton();
|
72
|
72
|
private JButton download = new JButton();
|
73
|
73
|
private JLabel jLabel4 = new JLabel();
|
|
@@ -805,8 +805,43 @@ public class Frame extends JFrame implements ListSelectionListener {
|
805
|
805
|
l.resetView();
|
806
|
806
|
}
|
807
|
807
|
|
|
808
|
+ if (s.startsWith("port ")) {
|
|
809
|
+ s = s.substring(5);
|
|
810
|
+ f.jComboBox1.addItem(s);
|
|
811
|
+ f.jComboBox1.setSelectedItem(s);
|
|
812
|
+ }
|
|
813
|
+
|
|
814
|
+ if (s.startsWith("send ")) {
|
|
815
|
+ s = s.substring(5);
|
|
816
|
+ HelperUtility.openPort(((String)f.jComboBox1.getSelectedItem()) + "\n");
|
|
817
|
+ short[] dat = toShortArray(s);
|
|
818
|
+ HelperUtility.writeData(dat, dat.length);
|
|
819
|
+ HelperUtility.closePort();
|
|
820
|
+ }
|
|
821
|
+
|
|
822
|
+ if (s.startsWith("read ")) {
|
|
823
|
+ s = s.substring(5);
|
|
824
|
+ int leng = Integer.parseInt(s);
|
|
825
|
+ HelperUtility.openPort((String)f.jComboBox1.getSelectedItem());
|
|
826
|
+ short[] data = HelperUtility.readData(leng);
|
|
827
|
+ System.out.println(shortToString(data));
|
|
828
|
+ HelperUtility.closePort();
|
|
829
|
+ }
|
|
830
|
+
|
|
831
|
+ if (s.equals("s") || s.equals("scan")) {
|
|
832
|
+ String[] sPorts = f.worker.getSerialPorts();
|
|
833
|
+ f.jComboBox1.removeAllItems();
|
|
834
|
+ for(int i = 0; i < sPorts.length; i++){
|
|
835
|
+ f.jComboBox1.addItem(sPorts[i]);
|
|
836
|
+ }
|
|
837
|
+ }
|
|
838
|
+
|
808
|
839
|
if (s.equals("h") || (s.equals("help"))) {
|
809
|
840
|
System.out.println("Commands:");
|
|
841
|
+ System.out.println("\t'port *name*'\t:\tSet serial port to this");
|
|
842
|
+ System.out.println("\t'send *datas*'\t:\tSend data to serial port");
|
|
843
|
+ System.out.println("\t'read *leng*'\t:\tRead data from serial port");
|
|
844
|
+ System.out.println("\t'scan' / 's'\t:\tScan for serial ports");
|
810
|
845
|
System.out.println("\t'on' / '1'\t:\tToggle all LEDs on");
|
811
|
846
|
System.out.println("\t'off' / '0'\t:\tToggle all LEDs off");
|
812
|
847
|
System.out.println("\t'print' / 'p'\t:\tPrint 3D Translation Matrix Data");
|
|
@@ -819,4 +854,22 @@ public class Frame extends JFrame implements ListSelectionListener {
|
819
|
854
|
}
|
820
|
855
|
} while (true);
|
821
|
856
|
}
|
|
857
|
+
|
|
858
|
+ private static short[] toShortArray(String s) {
|
|
859
|
+ char[] d = s.toCharArray();
|
|
860
|
+ System.out.println("Length: " + d.length);
|
|
861
|
+ short[] r = new short[d.length];
|
|
862
|
+ for (int i = 0; i < d.length; i++) {
|
|
863
|
+ r[i] = (short)d[i];
|
|
864
|
+ }
|
|
865
|
+ return r;
|
|
866
|
+ }
|
|
867
|
+
|
|
868
|
+ private static String shortToString(short[] d) {
|
|
869
|
+ String s = "";
|
|
870
|
+ for (int i = 0; i < d.length; i++) {
|
|
871
|
+ s += String.valueOf((char)d[i]);
|
|
872
|
+ }
|
|
873
|
+ return s;
|
|
874
|
+ }
|
822
|
875
|
}
|