relay
} else {
relay
if
(relay
System.out.println("No module connected (check USB
System.exit(1);
}
}
try {
System.out.println("Switch relay to
relay.set_state(YRelay.STATE_B);
YAPI.Sleep(1000);
System.out.println("Switch relay to
relay.set_state(YRelay.STATE_A);
} catch
(YAPI_Exception
System.out.println("Module "+relay.describe()+" not connected (check
identification and USB
}
YAPI.FreeAPI();
}
}
11.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
System.out.println("No module connected (check USB
System.exit(1);
}
} else {
module
}
try {
if
(args.length
if (args[1].equalsIgnoreCase("ON")) {
} else {
}
}
System.out.println("serial:
System.out.println("logical name: "
System.out.println("luminosity:
if (module.get_beacon() == YModule.BEACON_ON) {
www.yoctopuce.com
= YRelay.FindRelay(args[0]);
= YRelay.FirstRelay();
== null) {
ex) {
cable)");
{
void
main(String[] args)
ex) {
== 0) {
= YModule.FirstModule();
== null) {
= YModule.FindModule(args[0]);
> 1) {
module.setBeacon(YModule.BEACON_ON);
module.setBeacon(YModule.BEACON_OFF);
11. Utilisation du Yocto-PowerRelay-V2 en Java
B");
A");
[ON/OFF]");
// use serial or logical name
"
+ module.get_serialNumber());
+ module.get_logicalName());
"
+ module.get_luminosity());
cable)");
+
running");
cable)");
73