Eclipse.org Eclipse.org - Device Kit

Verifying Java communication with the hardware

After you verify that your hardware is working properly, and that the Eclipse configuration is correct, verify that the hardware is communicating with the Java code.

Note:
This step ensures that the correct shared libraries (.dll, .so) are in place and working.

To determine whether your hardware is communicating with the Java code, write a program that uses the serial port to listen to the GPS and prints any received data to the GPS.

To verify that the Connection Layer is functioning properly, use the following instructions:

  1. Create a new Java Project in Eclipse named Serial GPS Test.
  2. Create a new package within the Serial GPS Test project named tests.serial.
  3. Create a new class within the tests.serial package named GPSTest.
  4. Copy the following to the project's .classpath file:
    <classpath>
        <classpathentry kind="src" path=""/>
        <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
        <classpathentry kind="var"
            path="DEVICEKIT/bundlefiles/Connection.jar" sourcepath="DEVICEKIT/bundlefiles/source/src-Connection.jar"/>
        <classpathentry kind="var" path="DEVICEKIT/bundlefiles/SerialConnection.jar"/>
        <classpathentry kind="var" path="SERIAL_HOME/serial.jar"/>
        <classpathentry kind="var" path="DEVICEKIT/bundlefiles/Core.jar" sourcepath="DEVICEKIT/bundlefiles/source/src-Core.jar"/>
        <classpathentry kind="var" path="SMF_CLIENT/osgi.jar"/>
        <classpathentry kind="var" path="OAF_HOME/bundlefiles/OAF_Base.jar" sourcepath="OAF_HOME/source.jar"/>
        <classpathentry kind="output" path=""/>
    </classpath>
    
  5. Copy the following listing into the GPSTest class:
    package tests.serial;
    //Licensed Materials - Property of IBM
    //Copyright (c) 1999, 2007 IBM
    //US Government Users Restricted Rights - Use, duplication or disclosure
    //restricted by GSA ADP Schedule Contract with IBM Corp.
     
    import java.io.IOException;
    import org.eclipse.soda.dk.serial.connection.SerialConnection;
     
    public class GPSTest {
        public static void main(String[] args){
        //Create a Connection
            SerialConnection conn = new SerialConnection(1, 4800, SerialConnection.DATABITS_8, SerialConnection.PARITY_NONE, SerialConnection.STOPBITS_1, 0, 0, 100, 100, 100);
     
            //Create a place to put the read data, and a counter of how much data was read    
            byte[] data = new byte[1000];
     
            int bytesRead = 0;
     
            try{
                //Open the Connection
                conn.open();
                //Run Until Terminated
                while(true){
                //Read In The Data
                bytesRead = conn.read(data, 0, data.length);
                //If we got data, and didn't timeout, then print the data
                if(bytesRead > 0)
                    System.out.println("Message RX :" + new String(data, 0, bytesRead));
                }
            }catch(IOException e){
                //Print any errors
                e.printStackTrace();
            }
            try{
                //Attempt to close the serial port
                conn.close();
            }catch(IOException closeError){
                //Print any errors closing the port
                closeError.printStackTrace();
            }
        }
    }
    
  6. Run the GPSTest class.
  7. Verify the results of the test.

    If necessary, troubleshoot the test results.