Tutorial: Access non-Java code by running a separate process

Summary

These tutorials explains how to use foreign (as in non-Java) code in your Reactive Block application. Another term for foreign is native, because embedding non-Java code usually introduces platform and portability issues.

Make sure you have read the intro foreign-code-intro to prepare what you need for this tutorial.

Doing the tutorial

Alt text

Download the tutorial named “(Level 3) Foreign code v1: External process”

Part 1 - Build application on Raspberry-Pi

  • Look at the project in the Package Explorer view. You will see the process directory. Inside there you will see a file named wd-1.c.

Alt text * Transfer the file to your Raspberry-Pi. * Compile to an executable with this command: gcc -W -o wd wd-1.c

Alt text

Now you you have created one executable named wd on the Raspberry-Pi that you can test.

Part 2 - Understand Reactive Blocks application

The block to understand is the WD Process. It has three start pins, enable, disable and heartbeat that controls the watchdog. Each command takes some time to execute and in that period the block will not accept any other command. Errors are reported on the error pin and the ok pin indicates successful operation.

Alt text

All commands to the watchdog will generate a commandline that is forwarded to the Process Runner, that also resides in the same project.

In case the command is not completed in time, the process will be killed. You should be careful to tune the timeout to not abort the child-process to early vs. having a blocked/runaway process for too long time.

Alt text

All commands reference the applicaton you generated in part 1 of this tutorial.

Part 3 - Build application and execute on Raspberry-Pi

  1. Select Test WD Process application, press Build from rightclick menu and build Java executable. Select Java SE as project type.
  2. Export the generated project as Runnable JAR and transfer to your Raspberry-Pi to the same directory as the executable you generated in part 1. Alt text
  3. Try it (Hint: Note you have to use sudo because of file rights) Alt text
  4. Now that you successfully have this done tutorial, we have to dissapoint you and say we do not recommend this pattern. The wrap-up has a discussion about that.