io
= YDigitalIO.FindDigitalIO(args[0]+ ".digitalIO");
} else {
io
= YDigitalIO.FirstDigitalIO();
}
if
(io
== null) {
System.out.println("No module connected (check USB
System.exit(1);
}
try {
// lets configure the channels direction
// bits 0 and 1 as output
// bits 2 and 3 as input
io.set_portDirection(0x03);
io.set_portPolarity(0);
io.set_portOpenDrain(0);
System.out.println("Channels 0..1 are configured as outputs and channels 2..3"
);
System.out.println("are configred as inputs, you can connect some inputs
System.out.println("ouputs and see what
int
outputdata
while (io.isOnline()) {
outputdata
io.set_portState(outputdata);
YAPI.Sleep(1000);
int
String
for
}
System.out.println("port value =
}
} catch
(YAPI_Exception
System.out.println("Module "
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
www.yoctopuce.com
// polarity set to regular
// No open drain
= 0;
=
(outputdata
inputdata
= io.get_portState();
line
= "";
// display port value value as binary
(int
i
= 0;
i
< 4; i++) {
if
((inputdata
&
(8
line
=
line
+ '1';
} else {
line
=
line
+ '0';
}
ex) {
cable)");
{
void
main(String[] args)
ex) {
== 0) {
happens");
+ 1) % 4;
// cycle ouput 0..3
// We could have used set_bitState as well
// read port values
>> i)) > 0) {
"+line);
+ io.describe() +
" disconnected (check
11. Utilisation du Yocto-IO en Java
cable)");
+
running");
[ON/OFF]");
to");
75