diff --git a/.vscode/arduino.json b/.vscode/arduino.json index 3c4fa9a..6b06789 100644 --- a/.vscode/arduino.json +++ b/.vscode/arduino.json @@ -2,5 +2,6 @@ "port": "COM4", "configuration": "cpu=atmega2560", "board": "arduino:avr:mega", - "sketch": "Arduino-Test-Code\\Arduino-Test-Code.ino" + "sketch": "Arduino-Test-Code\\Arduino-Test-Code.ino", + "programmer": "arduinoisporg" } \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..7b0448d --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,28 @@ +{ + "tasks": [ + { + "type": "cppbuild", + "label": "C/C++: g++.exe build active file", + "command": "C:\\msys64\\ucrt64\\bin\\g++.exe", + "args": [ + "-fdiagnostics-color=always", + "-g", + "${file}", + "-o", + "${fileDirname}\\${fileBasenameNoExtension}.exe" + ], + "options": { + "cwd": "${fileDirname}" + }, + "problemMatcher": [ + "$gcc" + ], + "group": { + "kind": "build", + "isDefault": true + }, + "detail": "Task generated by Debugger." + } + ], + "version": "2.0.0" +} \ No newline at end of file diff --git a/Arduino-Test-Code/Arduino-Test-Code.ino b/Arduino-Test-Code/Arduino-Test-Code.ino index e4c9a03..eefdf44 100644 --- a/Arduino-Test-Code/Arduino-Test-Code.ino +++ b/Arduino-Test-Code/Arduino-Test-Code.ino @@ -8,6 +8,8 @@ void loop() { Serial.write(Serial.read()); // echo received data } } + Serial.println("Hello World"); + delay(100); diff --git a/mainCode/SerialDEV.pde b/mainCode/SerialDEV.pde new file mode 100644 index 0000000..9784aba --- /dev/null +++ b/mainCode/SerialDEV.pde @@ -0,0 +1,76 @@ +public void searchForPortsDEV() { + if (connectedToCOM == false) { + commPorts = SerialPort.getCommPorts(); // get available comm ports + systemPrintln("Found " + commPorts.length + " serial ports", "debug"); // print number of ports + + // iterate through port list and print detailed info + for (SerialPort commPort : commPorts) { + systemPrint("\n" + "System port name " + commPort.getSystemPortName() + ", ", "debug"); + systemPrint("Descriptive port name " + commPort.getDescriptivePortName() + ", ", "debug"); + systemPrint("Is Port opened ? " + commPort.isOpen() + "\n", "debug"); + } + + availableCOMs = new String[commPorts.length]; + // iterate through port list and add them to availableCOMs + for (int i = 0; i < commPorts.length; i ++) { + availableCOMs[i] = commPorts[i].getSystemPortName(); + } + + systemPrintln(java.util.Arrays.toString(availableCOMs), "debug"); + + if (availableCOMs.length > 0) { + portsFound = true; + selectedPort = availableCOMs[0]; + if (advancedOptions == true) { + buttonConnect.setText("Disconnected-click to connect " + selectedPort + "@" + selectedBaudRate + "," + selectedParity + "," + selectedDataBits + "," + selectedStopBits); + } else { + buttonConnect.setText("Disconnected-click to connect " + selectedPort + "@" + selectedBaudRate); + } + } else { + portsFound = false; + buttonConnect.setText("No serial ports found"); + } + } else if (connectedToCOM) { + commPorts = SerialPort.getCommPorts(); // get available comm ports + availableCOMs = new String[commPorts.length]; // resize COM list to match commPorts.length + + // iterate through port list and add them to availableCOMs + for (int i = 0; i < commPorts.length; i ++) { + availableCOMs[i] = commPorts[i].getSystemPortName(); + } + + if (availableCOMs[0].equals(selectedPort) == true || availableCOMs[comboBoxPortSelectedIndex].equals(selectedPort) == true) { + systemPrintln("connected port found" + availableCOMs[0], "debug"); + } else { + } + } +} + + + + // if (connectedToCOM == false) { + // availableCOMs = Serial.list(); + // if (availableCOMs.length > 0) { + // portsFound = true; + // selectedPort = availableCOMs[0]; + // if (advancedOptions == true) { + // buttonConnect.setText("Disconnected-click to connect " + selectedPort + "@" + selectedBaudRate + "," + selectedParity + "," + selectedDataBits + "," + selectedStopBits); + // } else { + // buttonConnect.setText("Disconnected-click to connect " + selectedPort + "@" + selectedBaudRate); + // } + // } else { + // portsFound = false; + // buttonConnect.setText("No serial ports found"); + // } + // } else if (connectedToCOM) { + // availableCOMs = Serial.list(); + // if (availableCOMs[0].equals(selectedPort) == true || availableCOMs[comboBoxPortSelectedIndex].equals(selectedPort) == true) { + // systemPrintln("connected port found" + availableCOMs[0], "debug"); + // } else { + // } + // } + + + + + diff --git a/mainCode/code/jSerialComm-2.11.4.jar b/mainCode/code/jSerialComm-2.11.4.jar new file mode 100644 index 0000000..d3fd712 Binary files /dev/null and b/mainCode/code/jSerialComm-2.11.4.jar differ diff --git a/mainCode/libs.pde b/mainCode/libs.pde index b7b48d0..df27bb4 100644 --- a/mainCode/libs.pde +++ b/mainCode/libs.pde @@ -47,4 +47,6 @@ import java.io.File; //import file library import java.io.FileWriter; //import file writer library import java.util.Collections; //import collections library import java.util.Scanner; //import scanner library -import java.util.Arrays; //import arrays library \ No newline at end of file +import java.util.Arrays; //import arrays library + +import com.fazecast.jSerialComm.*; \ No newline at end of file diff --git a/mainCode/mainCode.pde b/mainCode/mainCode.pde index e6e156d..a20252c 100644 --- a/mainCode/mainCode.pde +++ b/mainCode/mainCode.pde @@ -126,7 +126,7 @@ BufferedImage convertToBufferedImage(PImage imgToConvert) { systemPrintln("convertToBufferedImage complete @ " + millis(), "debug"); return convertedImg; } -// print to system console +// print newline to system console public void systemPrintln(String msg, String type) { try { if (showDebugStatements == true) { @@ -142,6 +142,22 @@ public void systemPrintln(String msg, String type) { catch (Exception error) { } } +// print to system console +public void systemPrint(String msg, String type) { + try { + if (showDebugStatements == true) { + if (type.equals("debug")) { + System.out.print(msg); + } else if (type.equals("error")) { + System.err.print(msg); + } + } else { + //do nothing + } + } + catch (Exception error) { + } +} // set terminal text fonts public void setFont(String fontName, float fontSize) { @@ -287,9 +303,6 @@ public void setupMain() { while (mainUiInit == false) { delay(1); } - setFont(selectedFont, selectedFontSize); - searchForPorts(); // search for available serial ports - initSearch(); // initialize textAreaMain searching //set startup message length based on selected font size if (selectedFontSize == 12) { textAreaMainMsg("", " -------------------------------------" + versionInfo + "-------------------------------------", ""); @@ -301,13 +314,16 @@ public void setupMain() { textAreaMainMsg("", " -------------------" + versionInfo + "--------------------", ""); } textAreaMainMsg("\n", "Enter -h for help", ""); //print help message + setFont(selectedFont, selectedFontSize); + searchForPortsDEV(); + //searchForPorts(); // search for available serial ports + initSearch(); // initialize textAreaMain searching systemPrintln("Startup complete" + " @ " + millis(), "debug"); } // Processing setup function public void setup() { setupMain(); // software setup function - // enter code here } diff --git a/mainCode/processSerial.pde b/mainCode/processSerial.pde index 0b1813c..f6b4cb5 100644 --- a/mainCode/processSerial.pde +++ b/mainCode/processSerial.pde @@ -2,7 +2,7 @@ //search for available serial ports public void searchForPorts() { - if (connectedToCOM == false) { + if (connectedToCOM == false) {// availableCOMs = Serial.list(); if (availableCOMs.length > 0) { portsFound = true; diff --git a/mainCode/settingsWindowUI.pde b/mainCode/settingsWindowUI.pde index e69df3b..686e960 100644 --- a/mainCode/settingsWindowUI.pde +++ b/mainCode/settingsWindowUI.pde @@ -117,8 +117,12 @@ void drawPortConfig() { buttonRefreshCOMs.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { if (connectedToCOM == false) { - availableCOMs = processing.serial.Serial.list(); //get available serial ports - comboBoxPort.setModel(new DefaultComboBoxModel(availableCOMs)); + commPorts = SerialPort.getCommPorts(); + availableCOMs = new String[commPorts.length]; + // iterate through port list and add them to availableCOMs + for (int i = 0; i < commPorts.length; i ++) { + availableCOMs[i] = commPorts[i].getSystemPortName(); + } comboBoxPort.setModel(new DefaultComboBoxModel(availableCOMs)); systemPrintln("Available COMs:" + java.util.Arrays.toString(availableCOMs), "debug"); systemPrintln("buttonRefreshCOMs clicked @ " + millis(), "debug"); } else { diff --git a/mainCode/sketch.properties b/mainCode/sketch.properties deleted file mode 100644 index e0fa0cf..0000000 --- a/mainCode/sketch.properties +++ /dev/null @@ -1 +0,0 @@ -main=main.pde diff --git a/mainCode/variables.pde b/mainCode/variables.pde index 359bf3f..5b2f6d8 100644 --- a/mainCode/variables.pde +++ b/mainCode/variables.pde @@ -14,7 +14,7 @@ int prevCommandsIndex = 0; // count of up key presses for previous comma char selectedParity = 'N'; //serial port parity 'N' for none, 'E' for even, 'O' for odd, 'M' for mark, 'S' for space ('N' is the default) -boolean showDebugStatements = false; // if true show debug statements in console +boolean showDebugStatements = true; // if true show debug statements in console boolean connectToCOM = false; // if connecting to com port boolean connectedToCOM = false; // if connected to com port boolean loggingData = false ; // if logging succeeded @@ -56,7 +56,6 @@ String stopBitList[] = {"1.0", "1.5", "2.0"}; String selectedParityString = parityList[0]; // String value of selected parity for display purposes String selectedDataBitsString = dataBitList[3]; // String value of selected data bits for display purposes String selectedStopBitsString = stopBitList[0]; // String value of selected stop bits for display purposes -String serialPortList[]; String enteredCommand = ""; // command entered in textFieldMain updates on enter press String validCommands[] = { // list of valid commands "-h", // help @@ -110,6 +109,8 @@ int intBaudRate = int(selectedBaudRate); // integer value of selected processing.serial.Serial COMPort = null; // create object of Serial class Table preferenceTable; // preferences table +SerialPort[] commPorts; // list of available serial ports + //Controls for main window javax.swing.JFrame frameMainWindow; //create instance of JFrame