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 thislimit is reached, nothing guaranties that the saving process is performed correctly. This limit, linked tothe 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 modulesObtaining 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 notnull. 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 VirtualHubYAPI.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 handlingWhen you implement a program which must interact with USB modules, you cannot disregard errorhandling. Inevitably, there will be a time when a user will have unplugged the device, either beforerunning the software, or even while the software is running. The Yoctopuce library is designed to helpyou support this kind of behavior, but your code must nevertheless be conceived to interpret in thebest 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 thischapter: before accessing a module, check that it is online with the isOnline function, and thenhope 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 thatyou cannot completely exclude an error which would occur after the call to isOnline and whichcould crash the software.15. Using the Yocto-GPS with Javawww.yoctopuce.com 103