Java library for serial communication between Java applications and Arduino boards with data visualization and export capabilities
npx @tessl/cli install tessl/maven-com-panamahitek--panama-hitek-arduino@3.2.0PanamaHitek_Arduino is a comprehensive Java library that provides a simple framework for handling serial communication between Java applications and Arduino boards. It includes three main classes for managing serial connections and communication, processing multiple simultaneous messages, and organizing data with table visualization and Excel export capabilities. The library also features specialized real-time graphical charting capabilities using JFreeChart components.
Add dependency to pom.xml:
<dependency>
<groupId>com.panamahitek</groupId>
<artifactId>PanamaHitek_Arduino</artifactId>
<version>3.2.1</version>
</dependency>For manual installation, download the latest JAR from the GitHub releases page and add it to your project classpath.
import com.panamahitek.PanamaHitek_Arduino;
import com.panamahitek.ArduinoException;
import com.panamahitek.PanamaHitek_MultiMessage;
import com.panamahitek.PanamaHitek_DataBuffer;For chart functionality:
import com.panamahitek.liveinterfaces.*;For event handling and serial communication:
import com.panamahitek.events.*;
import jssc.SerialPortEvent;
import jssc.SerialPortEventListener;
import jssc.SerialPortException;import com.panamahitek.PanamaHitek_Arduino;
import com.panamahitek.ArduinoException;
import jssc.SerialPortEvent;
import jssc.SerialPortEventListener;
import jssc.SerialPortException;
public class ArduinoExample {
private PanamaHitek_Arduino arduino = new PanamaHitek_Arduino();
public void setupConnection() throws ArduinoException {
// For receiving data from Arduino
arduino.arduinoRX("COM3", 9600, new SerialPortEventListener() {
@Override
public void serialEvent(SerialPortEvent event) {
try {
if (arduino.isMessageAvailable()) {
String message = arduino.printMessage();
System.out.println("Received: " + message);
}
} catch (SerialPortException | ArduinoException ex) {
ex.printStackTrace();
}
}
});
}
public void sendData() throws ArduinoException, SerialPortException {
// For bidirectional communication
arduino.arduinoRXTX("COM3", 9600, new SerialPortEventListener() {
@Override
public void serialEvent(SerialPortEvent event) {
// Handle incoming data events
}
});
arduino.sendData("Hello Arduino!");
}
public void cleanup() throws ArduinoException {
arduino.killArduinoConnection();
}
}The library is organized into four main functional areas:
Core Arduino serial communication functionality with configurable connection parameters and data transmission methods.
public class PanamaHitek_Arduino {
public PanamaHitek_Arduino();
public void arduinoTX(String PORT_NAME, int DATA_RATE) throws ArduinoException;
public void arduinoRX(String PORT_NAME, int DATA_RATE, SerialPortEventListener events) throws ArduinoException, SerialPortException;
public void arduinoRXTX(String PORT_NAME, int DATA_RATE, SerialPortEventListener events) throws ArduinoException;
public void sendData(String data) throws ArduinoException, SerialPortException;
public byte[] receiveData() throws ArduinoException, SerialPortException;
public void killArduinoConnection() throws ArduinoException;
}Comprehensive error management with multilingual support for Arduino communication errors.
public class ArduinoException extends Exception {
public ArduinoException(String portName, String methodName, String exceptionType);
public static void setLanguage(boolean englishLanguage);
public static String getExceptionMessage(String exceptionType);
}Handle reception of multiple simultaneous data messages from Arduino without complex logical sequences.
public class PanamaHitek_MultiMessage {
public PanamaHitek_MultiMessage(int inputMessages, PanamaHitek_Arduino arduinoObject);
public boolean dataReceptionCompleted() throws ArduinoException, SerialPortException;
public String getMessage(int index) throws IndexOutOfBoundsException;
public List<String> getMessageList();
}Data organization with table visualization and Excel export capabilities including event-driven data insertion.
public class PanamaHitek_DataBuffer {
public PanamaHitek_DataBuffer();
public void addColumn(int index, String variableName, Object dataType);
public void addValue(int column, Object value) throws Exception;
public void exportExcelFile() throws FileNotFoundException, IOException;
public void exportExcelFile(String path);
public JTable getTable();
}Live charting components for real-time data display including dial charts, thermometer displays, and time-series plots.
public class PanamaHitek_SingleDialChart {
public PanamaHitek_SingleDialChart(int chartType);
public void setValue(double value);
public void createArduinoFollowUp(String PORT_NAME, int DATA_RATE) throws ArduinoException, SerialPortException;
public JPanel getChartPanel();
}
public class PanamaHitek_TimeLineChart {
public PanamaHitek_TimeLineChart();
public void setDataBuffer(PanamaHitek_DataBuffer buffer) throws Exception;
public JPanel getChartPanel();
}// Chart type constants
public static final int ROUND_DIAL_CHART = 1;
public static final int HORIZONTAL_DIAL_CHART = 2;
public static final int VERTICAL_DIAL_CHART = 3;
// Dial position constants
public static final int OUTER_DIAL = 1;
public static final int INNER_DIAL = 2;
public static final int LEFT_DIAL = 1;
public static final int RIGHT_DIAL = 2;
// Event handling interface
public interface DataInsertionListener {
void onDataInsertion(DataInsertionEvent ev);
}