javaclasspathtinyos

using java to read data from serial port in Tiny OS


I am going through Tiny OS tutorial lesson number 4 "Mote-PC serial communication and SerialForwarder" and I am stuck on the line where it says "Once you have installed TestSerial, you need to run the corresponding Java application that communicates with it over the serial port. This is built when you build the TinyOS application. From in the application directory, type

$ java TestSerial

However when I type this, I face the following error

Error: Could not find or load main class TestSerial

I tried several things to fix this issue, but none helped.

Solutions that I tried:

  1. set CLASSPATH to the directory that I am currently in, which is

export CLASSPATH=.:/home/wsn/tinyos-main/apps/tests/TestSerial

2)set CLASSPATH to the directory where tinyos.jar is located

export CLASSPATH=.:/home/wsn/tinyos-main/support/sdk/java/tinyos.jar

3)run command using java -cp . TestSerial

however I keep having the same error

Is there any other better way to fix it?

I am using Virtual Machine with Fedora OS
I am trying to run the program on mib520 platform and I use iris motes

my java version

openjdk version "1.8.0_31"
OpenJDK Runtime Environment (build 1.8.0_31-b13)
OpenJDK Server VM (build 25.31-b07, mixed mode)


Solution

  • You must have skipped the step when you had to run the make command.

    Navigate to the apps/tests/TestSerial folder and type make [platform] (such as make telosb, make iris e.t.c), the makefile that will be run will be the makefile in the TestSerial folder which is defined as follows:

    COMPONENT=TestSerialAppC
    TOSMAKE_PRE_EXE_DEPS += TestSerial.class
    TOSMAKE_CLEAN_EXTRA = *.class TestSerialMsg.java
    
    TestSerial.class: $(wildcard *.java) TestSerialMsg.java
        javac -target 1.4 -source 1.4 *.java
    
    TestSerialMsg.java:
        nescc-mig java $(CFLAGS) -java-classname=TestSerialMsg TestSerial.h test_serial_msg -o $@
    
    
    TINYOS_ROOT_DIR?=../../..
    include $(TINYOS_ROOT_DIR)/Makefile.include
    

    So the makefile compiles TestSerial.java. After this you can proceed to installing the application and then running the TestSerial application.

    So step by step on a iris mote for example you would

    1. Navigate to the apps/tests/TestSerial Folder

    2. Make the application by typing make iris

    3. Connect your mote and then type motelist. This command will list all connected motes. The name of your mote should be listed under the "Device" section. Note this for use in the next two steps.

    4. Install your application by typing the command make iris install.1 bsl, [DEVICE NAME]. This will make and upload your program to your device.

    5. Run the TestSerial application by running java TestSerial -comm serial@[DEVICE NAME]:iris

    If you use another platform such as telosb then just replace all occurances of iris in the commands above with telosb.