await
module.
set_beacon
(
YModule
.
BEACON_ON
);
}
else
{
await
module.
set_beacon
(
YModule
.
BEACON_OFF
);
}
}
console.
log
(
'serial: '
+await
module.
get_serialNumber
());
console.
log
(
'logical name: '
+await
module.
get_logicalName
());
console.
log
(
'luminosity: '
+await
module.
get_luminosity
()+
'%'
);
console.
log
(
'beacon: '
+(await
module.
get_beacon
()==
YModule
.
BEACON_ON
?
'ON'
:
'OFF'
));
console.
log
(
'upTime: '
+
parseInt
(await
module.
get_upTime
()/
1000
)+
' sec'
);
console.
log
(
'USB current: '
+await
module.
get_usbCurrent
()+
' mA'
);
console.
log
(
'logs:'
);
console.
log
(await
module.
get_lastLogs
());
}
else
{
console.
log
(
"Module not connected (check identification and USB cable)
\n
"
);
}
await
YAPI
.
FreeAPI
();
}
if(
process.
argv
.
length
<
2
)
{
console.
log
(
"usage: node demo.js <serial or logicalname> [ ON | OFF ]"
);
}
else
{
startDemo
(
process.
argv
.
slice
(
2
));
}
Each property
xxx
of the module can be read thanks to a method of type
get_xxxx()
, and
properties which are not read-only can be modified with the help of the
set_xxx()
method. For
more details regarding the used functions, refer to the API chapters.
Changing the module settings
When you want to modify the settings of a module, you only need to call the corresponding
set_xxx()
function. However, this modification is performed only in the random access memory
(RAM) of the module: if the module is restarted, the modifications are lost. To memorize them
persistently, it is necessary to ask the module to save its current configuration in its permanent
memory. To do so, use the
saveToFlash()
method. Inversely, it is possible to force the module to
forget its current settings by using the
revertFromFlash()
method. The short example below
allows you to modify the logical name of a module.
"use strict"
;
require
(
'yoctolib-es2017/yocto_api.js'
);
async
function
startDemo
(
args
)
{
await
YAPI
.
LogUnhandledPromiseRejections
();
// 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: '
+
errmsg.
msg
);
return;
}
// Select the relay to use
let
module
=
YModule
.
FindModule
(
args
[
0
]);
if(await
module.
isOnline
())
{
if(
args.
length
>
1
)
{
let
newname
=
args
[
1
];
if
(!await
YAPI
.
CheckLogicalName
(
newname
))
{
console.
log
(
"Invalid name ("
+
newname
+
")"
);
process.
exit
(
1
);
}
await
module.
set_logicalName
(
newname
);
await
module.
saveToFlash
();
}
console.
log
(
'Current name: '
+await
module.
get_logicalName
());
}
else
{
console.
log
(
"Module not connected (check identification and USB cable)
\n
"
);
}
await
YAPI
.
FreeAPI
();
}
9. Using Yocto-Display with JavaScript / EcmaScript
www.yoctopuce.com
43
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...