### External Jar TinkerForge

Using TinkerForge with help of Library JavaObject.
Additional jar to include: RinkerForge
Reference: http://www.tinkerforge.com
Notes:
• The version of the additional Jar might have changed. Lookup the related website.
• See Tinkerforge more additional comprehensive information
Project Attributes
#Region Project Attributes
#MainFormWidth: 600
#MainFormHeight: 400
' Add the Tinkerforge jar - ensure to store in the B4J additional libraries folder
#AdditionalJar: Tinkerforge
#End Region
Example B4J App
Purpose
Read the Temperature using a TF Temperature Bricklet connected to a TF Master Brick.
Hardware Requirements
TinkerForge Master Brick ( https://www.tinkerforge.com/en/shop/bricks/master-brick.html )
TinkerForge Temperature Bricklet ( https://www.tinkerforge.com/en/shop/bricklets/temperature-bricklet.html )
Software Requirements:
Install the Brick Daemon (brickd) and the Brick Viewer (brickv) on the device.
Read here:
http://www.tinkerforge.com/en/doc/Tutorials/Tutorial_Extending/Tutorial.html#tutorial-first-steps
TF Temperature Java API Binding:
http://www.tinkerforge.com/en/doc/Software/Bricklets/Temperature_Bricklet_Java.html#temperature-bricklet-java-api
Access the TF Temperature Bricklet Principle
The principle to read the temperature, but basically for every TF Bricklet is:
• Define new instances to access the Master Brick and the Bricklet.
• Connect to the Master Brick.
• Run a Bricklet Method (as described in the Java API Binding documentation).
Hint:
Important: The parameter must be exactly match the parameter types for the method. So short must be short and not int.
In B4J JavaObjects are defined and used to access the external Classes from the TinkerForge Java API Library tinkerforge.jar.
Hint:
Use jd-gui ( http://jd.benow.ca ) to explore the tinkerforge.jar code.
B4J Code
This is example using defining a class and use a method to get the temperature.
B4J Class Temperature
'Class module
`Sub Class_Globals
Type TemperatureType (Host As String, Port As Int, UID As String)
End Sub`
`Public Sub Initialize
End Sub`
' Read the Temperature.
' Important: The parameter must be exactly match the parameter types for the method. So short must be short and not int.
' Parameter: bt as TemperatureType
' Returns the temperature as Short
`Public Sub getBrickletTemperature(bt As TemperatureType) As Short
Dim result As Short = 0
' Define the JavaObject to access the masterbrick
Dim joIPConnection As JavaObject
' Init the JavaObject = Packagename.Class
joIPConnection.InitializeNewInstance("com.tinkerforge.IPConnection", Null)
' Define the JavaObjects to connect to the Bricklet
Dim joBrickletTemperature As JavaObject
' Init the JavaObject = Packagename.Class
joBrickletTemperature.InitializeNewInstance("com.tinkerforge.BrickletTemperature", Array(bt.UID, joIPConnection))
Try
' Connect to the brick master via host and port
joIPConnection.RunMethod("connect", Array(bt.Host, bt.Port))
Dim ipconnectionstate As Byte = joIPConnection.RunMethod("getConnectionState", Null)
' Get the temperature using the JavaObject instance
' API Binding Method: public short getTemperature()
result = joBrickletTemperature.RunMethod("getTemperature", Null)
' Disconnect from tbe host
joIPConnection.RunMethod("disconnect", Null)
Catch
Log(" Error Connect: " & LastException.Message)
End Try
Return result
End Sub`

Changed: , Category: Jar, File: T6C204M1500.htm, ID: 1500