Serial Communication with Palm OS - Part 4/4

On Windows XP and Java

23.11.2019

Be warened: Windows XP is outdated since a few years and it shouldn'te be used on a production base. Best way to use it, is without a Wifi- or LAN-Connection.

Sometimes, there are applications, which only run on Windows XP, like CodeWarrior 9 for Palm OS Development. This IDE has an advantage over the development on Ubuntu: The Debugger works just fine out of the box. This is on reason why this article exists.

For developing applications on Windows XP I got myself Fujitsu Futro S900, which is not perfect in this case, but it is doing the job and has some advantages like the fan-less design and the two serial ports. On the down side it is a bit slow, especially for the Eclipse IDE.

Preparation

A few words regarding Eclipse and the needed Java JDK: On Windows XP Eclipse "Helios" works great and as a JDK java-1.8.0-openjdk-1.8.0.232-1.b09.ojdkbuild.windows.x86_64.zip is still availabe. Just download the "java-1.8.0-openjdk-1.8.0.232-1.b09.ojdkbuild.windows.x86_64.zip" and extract it into a folder for your choice. Afterwards the path pointing to "...\java-1.8.0-openjdk-1.8.0.232-1.b09.ojdkbuild.windows.x86\bin" must be inserted into the PATH environment variable.

In order to be able to communicate or receive data from a Palm through the serial port, like on Ubunut, a library is needed, which provides this possiblity. I had the least problems with "jSerialComm".

Important for Windows XP is to have the correct version of jSerialComm. The needed version is "1.3.9" and it is available here. Also the "jSerialComm.dll" is needed, which an be found here.

Installation of jSerialComm

The only step, which is mandatory, is to copy the .jar- and .dll-file into the eclipse-project-folder and integrate the .jar-file into your project:

  1. Click on the project and hit "Alt+Enter" to open the properties for the project
  2. Select "Java Build Path" in the menue.
  3. Select the "Libraries"-Tab.
  4. Add the jSerialComm.jar via the "Add External JARs..."-button.

The Java-Application

Now, everyhting is set up for creating the application. There are some examples out there to create a small programm, which let you read from the serial interface. The following example is very simple:

package serialComm;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;

import com.fazecast.jSerialComm.SerialPort;

public class SerialComm {

	/**
	 * 
	 * @param args
	 * @throws Exception 
	 */
	public static void main(String[] args) throws Exception {
		
		// A instance of our own class to get access to the readFromSerial-method.
		SerialComm serial = new SerialComm();
		
		// The computer has two serial ports, in my case, the port on position [1] is the correct one.
		SerialPort comPort = SerialPort.getCommPorts()[1];
		
		// Check if the port was not already opened.
		if(!comPort.isOpen()){
			
			// Here are some parameter, like the baud rate, are set.
			comPort.setComPortParameters(9600, 8,SerialPort.ONE_STOP_BIT, SerialPort.NO_PARITY);
			
			// The port gets opened.
			comPort.openPort();
			
			try {	
				while(true){
					
					// Get the inputStream, if possible.				
				    InputStream in = comPort.getInputStream();
				    // ... and read from it.
				    serial.readFromSerial(in);
				}
	
			   
			}
			// If a NullPointerException occurs, because probably getInputStream() failed, which probably means that the port is already in use by e.g. HotSyncManager. 
			catch (NullPointerException e) { System.err.println("Port probably already in use!"); }
			catch (Exception e) { e.printStackTrace(); }
			comPort.closePort();
		}else{
			throw new Exception("Port already opened!");
		}
	}
	
	/**
	 * This function reads from from a InputStream and print the related strings on the console.
	 * 
	 * @param in
	 * @throws IOException 
	 */
	private void readFromSerial(InputStream in) throws IOException {
	    Reader reader = new InputStreamReader(in);
        Reader buffer = new BufferedReader(reader);
        
        int r;
        while (buffer.ready() && (r = buffer.read()) != -1) {
            char ch = (char) r;
            System.out.print(ch);
        }
	}

}

The source-code is based on this example.

After the programm gets executed and some data was sent from the related Palm OS Application, which was created here, it should look like this:


Misc