Java support
💡 Note:
-
Oracle, Java, and MySQL are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
-
to compile your Java files, you will need to install Open JDK 1.8.
-
you also need Iotize Studio installed. The versions of your Studio and your firmware must comply. If it is not the case, we recommend to update both your Iotize Studio and the firmware of your device (it must be registered onto your TapCLOUD account).
The documentation for using the embedded JVM is divided into 3 parts:
- this general presentation, to explain the features, the limitations and the configuration of the Virtual Machine.
- the list of the native classes that cover both the 'classic classes', and those specific to the TapNLink hardware environment
- how to use the Raisonance debugger. If you write just a few lines of code, you will not need anything else but IoTize Studio. However, if you plan to edit several hundred/thousand lines of code, you can download a powerful free environment to debug your application, either with a simulator or with a real time debugger that will be connected to your Tap through the lwM2M.
Preamble
For the moment, the Virtual Machine is only available with TnlFIW103, TnLFIR203 and TnlFIL103 TapNlink (or TapNPass) models (NFC+WiFi+BLE, NFC+BLE and NFC+LoRa). It is also available on all Tapioca models and for TapNPass NFC+BLE+WiFi. New implementations will be soon available.
It has been introduced in 2020Q2 and we strongly recommend you to check the versions of your tap firmware and Studio. See update your firmware and the IoTize Studio download page. Note that your byte-code will not be executed by TapNLink if it calls some native methods that are not supported by the current firmware.
Features
Duetware includes a Virtual Machine which has been optimized to:
- analyze the data and make decisions to create alarms and perform data logging,
- access the I/O signals or the communication peripherals: UART, I²C, CAN or SPI,
- manage sensors or actuators through communication ports, ADC, counters,...
- format MQTT messages, for example in JSON thanks to the JSON or String classes,
- send and receive MQTT messages or other notifications,
- use the TapNLink as a standalone device (without target) to control a simple sensor/actuator.
Java language offers the advantage of being understood by both the mobile apps developers and the embedded programmers, since its syntax is close to C/C++.
The TapNLink implementation is not fully compliant with Java (it can be considered as a subset), but IoTize tried to offer all functionalities that could be needed as complement for the TapNLink lwM2M machine. Indeed, the general syntax of the language is supported but some of the system classes are certainly missing.
If you really need to use a method that is not currently supported, please contact IoTize. We may find a workaround, or we may add this method to the next version of the firmware, but our goal is to keep a very light process so that the IOT_JVM can provide high performances:
- Very limited RAM usage (a few hundredth of bytes).
- Very limited FLASH footprint (around 60KB for the JVM + native classes).
- Very efficient execution (typ. 20µs per Java instruction).
Main limitations of the IOT_JVM
You have to consider the following limitations:
-
size: the current JVM uses 16-bit references. It means that the byte code and heap are both limited up to 65535 bytes. In reality, the available memory for most of the TapNLink models is less than 128KB. It also depends on the overall memory consumption (use of TLS, MQTT, ...).
-
the standard classes of the language are not all implemented. For the implemented classes, some methods may be missing. We have tried to implement most of the well known methods of the most important classes.
-
multi-threading, multiple-inheritance, low level networking are not supported,
-
only UTF-8 encoding is supported for characters,
-
link is done statically by calling IOT_JVM.
General principles of the IOT_JVM linker
IOT_JVM supports multiple classes that have to be linked statically. Refer to the examples in IoTize\IoTize Studio\Examples\JVM to get an idea of what you can do. You can also find several applications written in Java here.
Static link
The main class has to provide the following methods (the constructor and *onEvent* are optional): - void onCheck (int id) : this function is called periodically (depending of the periods declared for the TapNLink variables registration). - void onException (final in errorcode, final int jpc, final int jsp : This function is called when an unhandled error occured (division by zero, stack overflow, ...). Note that other exceptions can also be handled locally using the try - catch syntax. - void onEvent (Object data) : this function is called to notify your program that an event occured: MQTT message reception, external interrupt, ... This method is optional. Other classes can be added either in the same file (inner classes) or as external classes. The IoTize linker tool (IOT_JVM.exe) must be called with the main '.class' file as argument. This is done automatically when a Java file is specified into Studio (or within a Ride-7 project).Native subclasses
Some predefined subclasses are provided to link this main class to the TapNLink resources and are executed as native code. Various classes to access the Input/Output of the extension ports are also available. Their declarations are in "IoTize Studio/bin/com/iotize/JVM" directory..bcb file
The .bcb file is equivalent to the .class file generated by the JAVAC compiler, but it has been reformatted to make reading and execution easier in our simplified JVM. It is generated by the IOT_JVM.exe linker.Mostly, it contains static tables that the JVM handles very efficiency. Most of the ASCII names of the declared objects are also removed in order to shrink the initial class file.