| |
The class JavaFish
The
class JavaFish contains a number of methods and properties to access the
fischertechnik Interfaces. JavaFish uses the Wrapper-DLL javaFish.DLL for access
to the common umFish20.DLL via JNI. To obtain all changes of the E-Inputs,
umFish20.DLL polls them with high priority (using the MultiMediaTimer) in
intervals of about 10 msec. In addition to the polling a refresh of the
M-Outputs is done. If requested, it reads EX / EY too. The state is stored in an
internal control block (can be determinined with instancing). The changes of the
E-Inputs are counted and stored in special counter fields. This counters can be
used for determining the position of an model (look for "impulse
wheel" on the Industry Robots).
Sources and objects are contained in javaFish.ZIP. umFish20Setup.EXE
can be used to install the class files and the DLL's more comfortable. It
contains also a tool : InterfacePanel to control the Interface values
interactive.
The package ftcomputing.javaFish contains the class JavaFish and the
following methods and properties :
JavaFish(ftInstance) |
Constructor, ftInstance : Handle for the
internal control block (optional, only if more then one instances of
JavaFish are in use). |
setAnalogScan |
true : Analog-Inputs EX (0) and EY(1) will
be scanned (default : false): |
setSlave |
true : an Extension Module is connected to
the Intelligent Interface. |
setPollInterval |
Time interval (msec) for polling the
interface |
openInterface |
Opening a connection to the interface |
closeInterface |
Close the connection to the interface |
getVersion |
Version of javaFish.DLL |
showStatus |
Console output of the actual state values |
setMotor |
Switch the M-Outputs M1-M4(M8), (1-4(8))
Left(Links) turn = 1, Right(Rechts) turn = 2, On(Ein) = 1, Off(Aus) = 0 |
clearMotors |
Switch off all M-Outputs |
setLamp |
Switch the M-Output in "Lamp
wiring"
(one pin to ground, one to M-Output) 1-8(16), true/false |
getAnalog |
Read one Analog-Input EX(0), / EY(1) |
getInput |
Read one E-Input E1-E8(E16) 1-8(16), true/false |
getOutputs |
Read all M-Outputs M1-M4(M8), M1 = right bit
00000001 (M1 on) |
setOutputs |
Write all M-Outputs M1-M4(M8), M1 = right bit
00000001 (M1 on) |
getInputs |
Read all E-Inputs E1-E8(E16), E1 = right bit
00000001 (E1 on) |
clearCounter |
Clear all counters ( = 0 ) |
setCounter |
Write a single counter to a start value
(counter is decremented)
Counter 1 belongs to E1 ...
Can be changed to beginning with 0 by changing constant 12 to 11 |
getCounter |
Read a single counter value
Counter 1 belongs to E1 ... |
pause |
Stop the program flow for n msecs. |
finish |
Look for end request (ESC-Key or E-Input) |
Console Demo
public class FishTest{
public static void main(String[] args){
boolean res = false; int R;
ftcomputing.JavaFish ft = new ftcomputing.JavaFish();
ft.setAnalogScan(true);
System.out.println("Version Number : " + ft.getVersion());
R = ft.openInterface("COM1");
System.out.println("Open State : " + R);
ft.showStatus();
do{
ft.setMotor(1,1);
ft.pause(1000);
ft.setMotor(2,1);
ft.pause(1000);
ft.setMotor(3,1);
ft.pause(1000);
ft.clearMotors();
ft.pause(1000);
} while(!ft.finish(1));
ft.clearMotors();
System.out.println("Analog EX : " + ft.getAnalog(0));
ft.closeInterface();
System.out.println("Program finished");
}}
The demo switches the single lamps connected to M1 - M3 On, waits 1 second,
then next lamps. If all lamps are on they are switched Off, waiting for one
second. Done in a loop until E1 is true (or ESC Key is pressed).
- ftcomputing.JavaFish ft = new ftcomputing.JavaFish();
New instance of JavaFish
ft.setAnalogScan(true);
The Analog-Inputs (EX, EY) should be polled.
- ft.openInterface("COM1");
Connection to an interface and determining which kind of interface it
is (Universal/LPT or Intelligent)In this case an Intelligent Interface on COM1.
ft.showStatus
Show the actual state values on console.
- do{ ... } while(!ft.finish(1));
Endless loop, to end by E1 = true or ESC-Key.
- ft.setMotor() | ft.pause() ...
The M-Outputs will be switch On, one after the other, 1 second delay
and than switched off all, wait for 1 second.
- If ESC-Key is presed or E1 = true, the loop will be finished.
- ft.closeInterface
The connection to the interface is closed.
NOTICE : Use the package which come with the ZIP file, otherwise
javaFish.DLL doesn't work.
Something more Java and fischertechnik
German scripts - english comments in the sources : Axel T. Schreiner
University of Osnabrück
Vorlesungen
UNI Osnabrück
A small example with the JBuilder : ftcomputing.JavaFish and Swing : ftSwing
Stanzmaschine 51 663 : JavaSwing solution
(JBuilder5).
Stand : 05.06.2009 |