Java Serial Tools

Java Serial Tools is an open source GUI and SHELL application that can read and log serial port data to various formats

It is based on jSerialComm library with a graphical interface added on top and a lot of options.

How to use Java Serial Tools – SHELL

The SHELL application is made with Spring Shell and you can use the built in help command.
Open a terminal and run the command:

java -jar serialtools-1.1.jar shell
serial-tools:> help
AVAILABLE COMMANDS

Port Command
        connect: Connect to a Serial Port
        disconnect: Disconnect from a Serial Port
        list: Display available Serial Ports and status
        listen: Show received data of a Serial Port

serial-tools:> list

Use the connect  port-ID command and then the listen port-ID command to see the output in the console.

By default, in the shell application all the data is logged into the console.

If you want to change the destionation of the logs, modify the ro/paha/serialtools/console/command/PortCommand.java file and add these lines of code to the connect command.

        
try {
            connector.connectToPort(port);
            port.getSerialPort().addDataListener(new DataReceivedListener(
                    new LineFeed(),
                    new Database()
            ));
            shellHelper.printSuccess("Connected to port id=" + port.getId());
....

 

How to use Java Serial Tools – GUI

Java Serial Tools is shipped with some defaults:

  • uses new line character to separate lines
  • writes output to the console

If you want to run a short test, download the jar file, and run it from command line. Connect your computer to a serial device that generates log entries, and then, from Java Serial Tools connect to that Serial port. You should see the received data in the console.

Make sure you have installed Java Runtime Environment on your computer.

You can use an Arduino to generate serial data :

int counter = 0;
void setup() {
  // https://www.arduino.cc/reference/en/language/functions/communication/serial/begin/
  Serial.begin(9600, SERIAL_8N1);
}

void loop() {
  Serial.print("NEW LINE ");
  Serial.println(counter);
  counter ++;
  delay(5000);
}

Default options:

By default it splits the lines by newline “\n” character and the output is sent to the console.

Changing the line delimiter

You can create custom delimiters and use a separate delimiter for each port.

Open the project with the preferred IDE and then edit the src/main/java/ro/paha/ serialtools/view/ArduinoSerial.java file and change the “messageSeparator” object to another line separator.

Because this app is based on jSerialComm , you can create delimiters that splits lines by words.  New delimiters can be created in  src/main/java/ro/paha/serialtools/delimiter folder.

Changing the output format

The output formats are defined in src/main/java/ro/paha/serialtools/repository folder.

If you want to log the data  into a mysql database,  modify the src/main/resource/db.properties file with your database user and password, and then update the  src/main/java/ro/paha/ serialtools/view/ArduinoSerial.java file and change the “repo” object to “Database”.

After you change the source code, proceed to the build jar section in this article.

How to import the project

Install IntelliJ and import the project:

Copy the project by downloading from GitHub or clone it by git:
git clone https://github.com/floringavrila/serialtools

Open IntelliJ, click File -> New -> Project From Existing Sources -> select the gradle.build file.

OR

Open IntelliJ and choose import project and then select the downloaded folder.

In the next window choose Gradle and in the next one choose “Use auto-import” and then click on “Finish”.

How to build the jar file

Activate the graddle window in IntelliJ (View->Tool Windows->Gradle), expand the “Tasks->build” group and then double click the “bootJar” task.

The jar can be found in build/libs/ folder

You can open the jar by double click or from command line.

 

for linux users:
sudo usermod -a -G uucp username
sudo usermod -a -G dialout username
sudo usermod -a -G lock username
sudo usermod -a -G tty username