and USB cable)"
)
;
System
.
out
.
println
(
ex.
getMessage
())
;
System
.
exit
(
1
)
;
}
YAPI.
FreeAPI
()
;
}
}
Warning: the number of write cycles of the nonvolatile memory of the module is limited. When this
limit is reached, nothing guaranties that the saving process is performed correctly. This limit, linked to
the technology employed by the module micro-processor, is located at about 100000 cycles. In short,
you can use the
YModule.saveToFlash()
function only 100000 times in the life of the module.
Make sure you do not call this function within a loop.
Listing the modules
Obtaining the list of the connected modules is performed with the
YModule.yFirstModule()
function which returns the first module found. Then, you only need to call the
nextModule()
function of this object to find the following modules, and this as long as the returned value is not
null
. Below a short example listing the connected modules.
import
com.yoctopuce.YoctoAPI.*
;
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
(
"Device list"
)
;
YModule module = YModule.
FirstModule
()
;
while
(
module !=
null
)
{
try
{
System
.
out
.
println
(
module.
get_serialNumber
()
+
" ("
+
module.
get_productName
()
+
")"
)
;
}
catch
(
YAPI_Exception ex
)
{
break
;
}
module = module.
nextModule
()
;
}
YAPI.
FreeAPI
()
;
}
}
15.4. Error handling
When you implement a program which must interact with USB modules, you cannot disregard error
handling. Inevitably, there will be a time when a user will have unplugged the device, either before
running the software, or even while the software is running. The Yoctopuce library is designed to help
you support this kind of behavior, but your code must nevertheless be conceived to interpret in the
best possible way the errors indicated by the library.
The simplest way to work around the problem is the one used in the short examples provided in this
chapter: before accessing a module, check that it is online with the
isOnline
function, and then
hope that it will stay so during the fraction of a second necessary for the following code lines to run.
This method is not perfect, but it can be sufficient in some cases. You must however be aware that
you cannot completely exclude an error which would occur after the call to
isOnline
and which
could crash the software.
15. Using the Yocto-GPS with Java
www.yoctopuce.com
103
Summary of Contents for Yocto-GPS
Page 1: ...Yocto GPS User s guide...
Page 2: ......
Page 6: ...22 Characteristics 557 Blueprint 559 Index 561...
Page 10: ...4 www yoctopuce com...
Page 14: ...8 www yoctopuce com...
Page 18: ...12 www yoctopuce com...
Page 22: ...16 www yoctopuce com...
Page 38: ...32 www yoctopuce com...
Page 42: ...36 www yoctopuce com...
Page 54: ...48 www yoctopuce com...
Page 72: ...66 www yoctopuce com...
Page 92: ...86 www yoctopuce com...
Page 122: ...116 www yoctopuce com...
Page 132: ...126 www yoctopuce com...
Page 564: ...22 Characteristics 558 www yoctopuce com...
Page 565: ......
Page 566: ......