
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.
using
System
;
using
System.Diagnostics
;
using
System.Threading.Tasks
;
using
Windows.UI.Xaml.Controls
;
using
com.yoctopuce.YoctoAPI
;
namespace
Demo
{
public
class
Demo
:
DemoBase
{
public
string
HubURL
{
get;
set;
}
public
override
async
Task
<
int
>
Run
()
{
YModule
m
;
try
{
await
YAPI
.
RegisterHub
(
HubURL
);
WriteLine
(
"Device list"
);
m
=
YModule
.
FirstModule
();
while
(
m
!=
null)
{
WriteLine
(await
m
.
get_serialNumber
()
+
" ("
+
await
m
.
get_productName
()
+
")"
);
m
=
m
.
nextModule
();
}
}
catch
(
YAPI_Exception
ex
)
{
WriteLine
(
"Error:"
+
ex
.
Message
);
}
YAPI
.
FreeAPI
();
return
0
;
}
}
}
15.7. 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.
In the Universal Windows Platform library, error handling is implemented with exceptions. You must
therefore intercept and correctly handle these exceptions if you want to have a reliable project which
does not crash as soon as you disconnect a module.
Library thrown exceptions are always of the YAPI_Exception type, so you can easily separate them
from other exceptions in a
try{...} catch{...}
block.
Example:
15. Using the Yocto-Display with Universal Windows Platform
www.yoctopuce.com
93
Содержание Yocto-Display
Страница 1: ...Yocto Display User Manual...
Страница 2: ......
Страница 40: ...34 www yoctopuce com...
Страница 52: ...46 www yoctopuce com...
Страница 84: ...78 www yoctopuce com...
Страница 92: ...86 www yoctopuce com...
Страница 130: ...124 www yoctopuce com...
Страница 158: ...22 High level API Reference 152 www yoctopuce com On failure throws an exception or returns a negative error code...
Страница 422: ...416 www yoctopuce com...
Страница 424: ...24 Characteristics 418 www yoctopuce com...