
16. Using the Yocto-RangeFinder with Java
Java is an object oriented language created by Sun Microsystem. Beside being free, its main
strength is its portability. Unfortunately, this portability has an excruciating price. In Java, hardware
abstraction is so high that it is almost impossible to work directly with the hardware. Therefore, the
Yoctopuce API does not support native mode in regular Java. The Java API needs a Virtual Hub to
communicate with Yoctopuce devices.
16.1. Getting ready
Go to the Yoctopuce web site and download the following items:
• The Java programming library
1
• The VirtualHub software
2
for Windows, Mac OS X or Linux, depending on your OS
The library is available as source files as well as a
jar
file. Decompress the library files in a folder of
your choice, connect your modules, run the VirtualHub software, and you are ready to start your first
tests. You do not need to install any driver.
In order to keep them simple, all the examples provided in this documentation are console
applications. Naturally, the libraries function in a strictly identical manner if you integrate them in an
application with a graphical interface.
16.2. Control of the RangeFinder function
A few lines of code are enough to use a Yocto-RangeFinder. Here is the skeleton of a Java code
snippet to use the RangeFinder function.
[
...
]
// Get access to your device, connected locally on USB for instance
YAPI.
RegisterHub
(
"127.0.0.1"
)
;
rangefinder = YRangeFinder.
FindRangeFinder
(
"YRNGFND1-123456.rangeFinder"
)
;
// Hot-plug is easy: just check that the device is online
if
(
rangefinder.
isOnline
())
{
// Use rangefinder.get_currentValue()
[
...
]
1
www.yoctopuce.com/EN/libraries.php
2
www.yoctopuce.com/EN/virtualhub.php
www.yoctopuce.com
97
Содержание Yocto-RangeFinder
Страница 1: ...Yocto RangeFinder User s guide...
Страница 2: ......
Страница 18: ...12 www yoctopuce com...
Страница 26: ...20 www yoctopuce com...
Страница 42: ...36 www yoctopuce com...
Страница 70: ...gcc lyocto lm lpthread lusb 1 0 lstdc 10 Using Yocto RangeFinder with C 64 www yoctopuce com...
Страница 90: ...84 www yoctopuce com...
Страница 120: ...114 www yoctopuce com...
Страница 130: ...124 www yoctopuce com...
Страница 158: ...21 High level API Reference On failure throws an exception or returns a negative error code 152 www yoctopuce com...
Страница 484: ...478 www yoctopuce com...
Страница 488: ...482 www yoctopuce com...
Страница 490: ...23 Characteristics 484 www yoctopuce com...
Страница 491: ......
Страница 492: ......