System.out.println("Ensure that the VirtualHub application is
System.exit(1);
}
YRangeFinder
if
(args.length
rf
= YRangeFinder.FindRangeFinder(args[0] + ".rangeFinder1");
} else {
rf
= YRangeFinder.FirstRangeFinder();
if
(rf
System.out.println("No module connected (check USB
System.exit(1);
}
}
if (!rf.isOnline()) {
System.out.println("Module not connected (check identification and USB cable)"
);
System.exit(1);
}
System.out.println("press a test button or hit
try {
String
YLightSensor
YTemperature
while (true) {
System.out.println(String.format("Distance
);
System.out.println(String.format("Ambiant IR
);
System.out.println(String.format("Temperature :
));
YAPI.Sleep(1000);
}
} catch
(YAPI_Exception
System.out.println("Module "
USB
cable)");
System.out.println(ex.getMessage());
System.exit(1);
}
}
}
12.3. Contrôle de la partie module
Chaque module peut-être contrôlé d'une manière similaire, vous trouverez ci-dessous un simple
programme d'exemple affichant les principaux paramètres d'un module et permettant d'activer la
balise de localisation.
import com.yoctopuce.YoctoAPI.*;
import java.util.logging.Level;
import java.util.logging.Logger;
public class
Demo
public static
{
try {
// setup the API to use local VirtualHub
YAPI.RegisterHub("127.0.0.1");
} catch
(YAPI_Exception
System.out.println("Cannot contact VirtualHub on 127.0.0.1 ("
ex.getLocalizedMessage() + ")");
System.out.println("Ensure that the VirtualHub application is
System.exit(1);
}
System.out.println("usage: demo [serial or logical name]
YModule
module;
if
(args.length
module
if
(module
www.yoctopuce.com
rf;
> 0) {
== null) {
serial
= rf.get_module().get_serialNumber();
ir
=
YLightSensor.FindLightSensor(serial
tmp
=
YTemperature.FindTemperature(serial
ex) {
{
void
main(String[] args)
ex) {
== 0) {
= YModule.FirstModule();
== null) {
12. Utilisation du Yocto-RangeFinder en Java
Ctrl-C");
+
rf
+
" not connected (check identification and
running");
cable)");
+ ".lightSensor1");
+ ".temperature1");
:
%f",
rf.get_currentValue())
:
%f",
ir.get_currentValue())
%f",
tmp.get_currentValue()
+
running");
[ON/OFF]");
83