-
Notifications
You must be signed in to change notification settings - Fork 2
3. six steps to your first Elbfisch application
1. Download the Elbfisch binary org.jpac.jar.
2. Create your project in your Java development environment.
This should contain the following directories, in addition to those created by the development environment:
./cfg
./log
Elbfisch expects to find the configuration file log4j.properties in ./cfg. Download this file and copy it to the directory ./cfg. log4j.properties
3. Move the following directories and jars to your project’s classpath:
the directory ./cfg set up in the project folder
and the following jars:
- org.jpac.jar
- log4j-1.2.16.jar (www.apache.org)
- commons-configuration-1.6.jar (www.apache.org)
- commons-lang-2.6.jar (www.apache.org)
- commons-collections-3.2.1.jar (www.apache.org)
- commons-logging-2.6.jar (www.apache.org)
4. Create a new Java class in the project and derive this from org.jpac.Module:
import org.jpac.InputInterlockException;
import org.jpac.Module;
import org.jpac.OutputInterlockException;
import org.jpac.PeriodOfTime;
import org.jpac.ProcessException;
public class TestModule extends Module{
public TestModule(String name){
super(null, name);
}
@Override
public void start(){
super.start();
}
@Override
protected void work() throws ProcessException {
boolean done = false;
int cycle = 0;
PeriodOfTime time = new PeriodOfTime(1000 * ms);
Log.info("started....");
try{
do{
Log.info("hello world: " + cycle++);
time.await();
done = cycle > 10;
}
while (!done);
}
catch(Exception exc){
Log.error("Error: ", exc);
}
catch(Error exc){
Log.error("Error: ", exc);
}
finally{
Log.info("ended ...");
shutdown(0);
}
}
@Override
protected void preCheckInterlocks() throws InputInterlockException {
}
@Override
protected void postCheckInterlocks() throws OutputInterlockException {
}
@Override
protected void inEveryCycleDo() throws ProcessException {
throw new UnsupportedOperationException("Not supported yet.");
}
}
5. Create a Java class with a main() method through which the module can be started:
import org.apache.log4j.Logger;
import org.jpac.Module;
public class ElbfischTest {
protected static Logger Log = Logger.getLogger("ModuleTester");
public static void main(String[] args) {
try{
Module mainModule = new TestModule("TestModule");
mainModule.start();
}
catch(Exception exc){
Log.error("Error: ", exc);
}
catch(Error exc){
Log.error("Error: ", exc);
}
}
}
6. Run ModuleTester. You now should receive the following output via the console:
17:38:37,477 [INFO:JPac] >>>>>>> starting automation controller
17:38:37,477 [INFO:JPac] awaiting start up signal ...
17:38:37,481 [INFO:main] startCycling requested
17:38:37,481 [INFO:main] startCycling() acknowledged
17:38:37,481 [INFO:JPac] >>> starting up in FreeRunning mode ...
17:38:37,483 [INFO:TestModule] started....
17:38:37,483 [INFO:TestModule] hello world: 0
17:38:38,483 [INFO:TestModule] hello world: 1
17:38:39,483 [INFO:TestModule] hello world: 2
17:38:40,484 [INFO:TestModule] hello world: 3
17:38:41,484 [INFO:TestModule] hello world: 4
17:38:42,484 [INFO:TestModule] hello world: 5
17:38:43,484 [INFO:TestModule] hello world: 6
17:38:44,485 [INFO:TestModule] hello world: 7
17:38:45,485 [INFO:TestModule] hello world: 8
17:38:46,485 [INFO:TestModule] hello world: 9
17:38:47,485 [INFO:TestModule] hello world: 10
17:38:48,485 [INFO:TestModule] ended ...
17:38:48,486 [INFO:ShutdownHook] shutdown requested. Informing the automation controller ...
17:38:48,486 [INFO:JPac] shutting down modules ...
17:38:48,487 [INFO:JPac] ... shutting down modules done
17:38:48,487 [INFO:JPac] cycle mode : FreeRunning
17:38:48,487 [INFO:JPac] cycle time : 100000000 ns
17:38:48,487 [INFO:JPac] saving the configuration ...
17:38:48,505 [INFO:JPac] ... saving of the configuration done
17:38:48,505 [INFO:JPac] shutdown complete
17:38:48,587 [INFO:ShutdownHook] shutdown complete
If this works, you have now created your first Elbfisch application. Congratulations!