YAPI
.
Sleep
(
5
);
}
}
catch
(
YAPI_Exception
ex
)
{
System
.
out
.
println
(
"Exception durring execution ("
+
ex.
getLocalizedMessage
()
+
")"
);
YAPI
.
FreeAPI
();
System
.
exit
(
1
);
}
}
}
18.3. Control of the module part
Each module can be controlled in a similar manner, you can find below a simple sample program
displaying the main parameters of the module and enabling you to activate the localization beacon.
import
com.yoctopuce.YoctoAPI.*
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
public
class
Demo
{
public
static
void
main
(
String
[]
args
)
{
try
{
// setup the API to use local VirtualHub
YAPI
.
RegisterHub
(
"127.0.0.1"
);
}
catch
(
YAPI_Exception
ex
)
{
System
.
out
.
println
(
"Cannot contact VirtualHub on 127.0.0.1 ("
+
ex.
getLocalizedMessage
()
+
")"
);
System
.
out
.
println
(
"Ensure that the VirtualHub application is running"
);
System
.
exit
(
1
);
}
System
.
out
.
println
(
"usage: demo [serial or logical name] [ON/OFF]"
);
YModule
module
;
if
(
args.
length
==
0
)
{
module
=
YModule
.
FirstModule
();
if
(
module
==
null
)
{
System
.
out
.
println
(
"No module connected (check USB cable)"
);
System
.
exit
(
1
);
}
}
else
{
module
=
YModule
.
FindModule
(
args
[
0
]);
// use serial or logical name
}
try
{
if
(
args.
length
>
1
)
{
if
(
args
[
1
]
.
equalsIgnoreCase
(
"ON"
))
{
module.
setBeacon
(
YModule
.
BEACON_ON
);
}
else
{
module.
setBeacon
(
YModule
.
BEACON_OFF
);
}
}
System
.
out
.
println
(
"serial: "
+
module.
get_serialNumber
());
System
.
out
.
println
(
"logical name: "
+
module.
get_logicalName
());
System
.
out
.
println
(
"luminosity: "
+
module.
get_luminosity
());
if
(
module.
get_beacon
()
==
YModule
.
BEACON_ON
)
{
System
.
out
.
println
(
"beacon: ON"
);
}
else
{
System
.
out
.
println
(
"beacon: OFF"
);
}
System
.
out
.
println
(
"upTime: "
+
module.
get_upTime
()
/
1000
+
" sec"
);
System
.
out
.
println
(
"USB current: "
+
module.
get_usbCurrent
()
+
" mA"
);
System
.
out
.
println
(
"logs:
\n
"
+
module.
get_lastLogs
());
}
catch
(
YAPI_Exception
ex
)
{
System
.
out
.
println
(
args
[
1
]
+
" not connected (check identification and USB
cable)"
);
}
YAPI
.
FreeAPI
();
18. Using the Yocto-Display with Java
110
www.yoctopuce.com
Summary of Contents for Yocto-Display
Page 1: ...Yocto Display User Manual...
Page 2: ......
Page 40: ...34 www yoctopuce com...
Page 52: ...46 www yoctopuce com...
Page 84: ...78 www yoctopuce com...
Page 92: ...86 www yoctopuce com...
Page 130: ...124 www yoctopuce com...
Page 422: ...416 www yoctopuce com...