
if(
process.
argv
.
length
<
2
)
{
console.
log
(
"usage: node demo.js <serial> [newLogicalName]"
);
}
else
{
startDemo
(
process.
argv
.
slice
(
2
));
}
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
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.FirstModule()
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.
"use strict"
;
require
(
'yoctolib-es2017/yocto_api.js'
);
async
function
startDemo
()
{
await
YAPI
.
LogUnhandledPromiseRejections
();
await
YAPI
.
DisableExceptions
();
// Setup the API to use the VirtualHub on local machine
let
errmsg
=
new
YErrorMsg
();
if
(await
YAPI
.
RegisterHub
(
'127.0.0.1'
,
errmsg
)
!=
YAPI
.
SUCCESS
)
{
console.
log
(
'Cannot contact VirtualHub on 127.0.0.1'
);
return;
}
refresh
();
}
async
function
refresh
()
{
try
{
let
errmsg
=
new
YErrorMsg
();
await
YAPI
.
UpdateDeviceList
(
errmsg
);
let
module
=
YModule
.
FirstModule
();
while
(
module
)
{
let
line
=
await
module.
get_serialNumber
();
line
+=
'('
+
(await
module.
get_productName
())
+
')'
;
console.
log
(
line
);
module
=
module.
nextModule
();
}
setTimeout
(
refresh
,
500
);
}
catch(
e
)
{
console.
log
(
e
);
}
}
try
{
startDemo
();
}
catch(
e
)
{
console.
log
(
e
);
}
9.5. 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.
9. Using Yocto-Display with JavaScript / EcmaScript
44
www.yoctopuce.com
Содержание 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...