### About

TinkerForge Inline Java
Introduction
TinkerForge http://www.tinkerforge.com (TF) is an open source hardware platform of stackable microcontroller building blocks (Bricks)
that can control different modules (Bricklets). See B4J HowTo > TinkerForge > About.
TinkerForge Bricks and Bricklets can be controlled using the TinkerForge Java Binding TinkerForge.jar.
The Tinkerforge.jar is
• a precompiled Java library, which properties & methods are accessed via B4J Inline Java Code.
• has to be copied to the B4J additional libraries folder and added to the Project Attributes as #AdditionalJar: tinkerforge.jar.
• requires the JavaObject library.
To get an understanding of the binding and its properties&methods, read the reference:
http://www.tinkerforge.com/en/doc/Software/API_Bindings_Java.html
Inline Java
In B4J a dedicated standard class has to be defined,to be able to use the properties & methods defined in Inline Java.
A skeleton class looks like:
Private Sub Class_Globals
Dim joInline As JavaObject = Me
End Sub#LINERB#
' Initializes the object.
Public Sub Initialize
' NO ACTION - but must be called prior using the class
End Sub#LINERB#
#If Java
import com.tinkerforge.BrickletNAME;
import com.tinkerforge.IPConnection;
public void ... throws Exception {
}
#End If
TF Example Code
TF provides examples for the various bricks and bricklets. This example code can be embedded in the Inline Java Section of the Class.
Example IO-16 Bricklet:
If Java
import com.tinkerforge.BrickletIO16;
import com.tinkerforge.IPConnection;
// Set the output state of a pin for a port. After setting the pin, the connection is disconnected.
// Example B4J Code
// Public Sub SetPinState(HOST As String, Port As Int, UID As String, IOPort As Char, IOPin As Int, State As Boolean)
// joInline.RunMethod("SetPinState", Array(HOST, Port, UID, IOPort, IOPin, State))
// End Sub
public void SetPinState(String HOST, int PORT, String UID, char IOPort, int IOPin, Boolean IOState) throws Exception {
IPConnection ipcon = new IPConnection(); // Create IP connection
BrickletIO16 io = new BrickletIO16(UID, ipcon); // Create device object
ipcon.connect(HOST, PORT); // Connect to brickd
io.setPortConfiguration(IOPort, (short)(1 << IOPin), 'o', IOState);
ipcon.disconnect();
}
End If

Changed: , Category: TinkerForge Inline Java, File: T6C265M1970.htm, ID: 1970