if
(args.length
anytilt
if
(anytilt
System.out.println("No module connected (check USB
System.exit(1);
}
} else {
anytilt
if (!anytilt.isOnline()){
System.out.println("Module not connected (check identification and USB
cable)");
System.exit(1);
}
}
try {
String
tilt1
tilt2
tilt3
int
count
while (true) {
tilt2.get_currentValue() +
}
} catch
(YAPI_Exception
System.out.println("Module not connected (check identification and USB cable)"
);
}
YAPI.FreeAPI();
}
}
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
www.yoctopuce.com
== 0) {
= YTilt.FirstTilt();
== null) {
= YTilt.FindTilt(args[0] + ".tilt1");
serial
= anytilt.get_module().get_serialNumber();
=
YTilt.FindTilt(serial
=
YTilt.FindTilt(serial
=
YTilt.FindTilt(serial
= 0;
if (!tilt1.isOnline()) {
System.out.println("device
System.exit(0);
}
if
(count
%
10
== 0)
System.out.println("tilt1\ttilt2\ttilt3");
System.out.println(""
"\t"
+ tilt3.get_currentValue() );
count++;
YAPI.Sleep(250);
ex) {
{
void
main(String[] args)
ex) {
== 0) {
= YModule.FirstModule();
12. Utilisation du Yocto-Inclinometer en Java
+ ".tilt1");
+ ".tilt2");
+ ".tilt3");
disconnected");
+ tilt1.get_currentValue() +
cable)");
"\t"
+
+
running");
[ON/OFF]");
81