26
1072_0_Product_Manual - February 24, 2011 2:52 PM
Advanced User’s Guide
This section describes use of the PhidgetSBC outside of the web configuration, and basic opening of Phidgets over
the network. This includes custom applications, SSH, customizing the system, etc. It is recommended that you have
some experience with Linux before trying some of these tasks.
Custom Applications
The PhidgetSBC supports custom user application written in either Java or C. Custom applications are set up and
managed using the configuration interface.
Custom applications are created under the /usr/userapps/(application name) directory and contain all application
files. This must include at least the executable file.
Note that custom applications should not try to get user input, as stdin is closed before the application gets run.
If your application writes important information to disk, make sure to call sync - otherwise data may be lost in an
unexpected reboot.
Java
First, install ‘libphidget21-java’ via ‘apt-get install’, or Install ‘Java Support’ via the ‘System: Packages’ web interface
page.
Java applications can be compiled on a separate development machine, where they can also be tested before
deployment. When coding, make sure to include the correct version of phidget21.jar file as part of the environment.
You can use the link under Projects: Projects page in the configuration interface to ensure that your Java program is
synchronized with the version of phidget21 on the PhidgetSBC. When using Java packages, make sure to create the
appropriate directory for them.
The PhidgetSBC also supports .jar files and you may find it easier to compile an upload a .jar instead of the all the
necessary .class files. When your project is completed we recommend to compile the project as a .jar. This reduces
the number of extra flies created into a single package that is easier to manage and can be executed from the
command line, or even by double clicking the file if you operating system environment is configured properly.
Under the command line, you can use the jar utility from the Java SDK to package the .class and .java files. The
process starts by going to the directory where your program is located and creating a manifest file. This manifest
file tells the java jar compiler the version of the program and the name of the Main-Class which acts as the entry
point for the application. The entry point is the class that contains the main method that is run when the program is
started. You also want to add a line to specify the class-path which will point to the phidget21.jar file that contains
the library for including into the jar.
Let’s assume we want to distribute our program MyProgram.java as an executable jar file. First, compile the
program to generate the .class files. Now, create the manifest file MyProgram.mf which contains the following lines:
Manifest-Version: 1.0
Class-Path: phidget21.jar
Main-Class: MyProgram
NOTE: The Manifest file (MyProgram.mf) MUST have a blank line at the end.
Save the file and close it. Create the jar by running the following command from the command line:
jar -cmf MyProgram.mf MyProgram.jar *.class
You should now have an executable jar file called MyProgram.jar that you can distribute easily as one package and
run from anywhere very easily. To run the executable jar file you can either type the following into the command
line:
java -jar MyProgram.jar
Or, you can double click the file in a visual operating system if your environment is configured properly.