![Yoctopuce Yocto-GPS User Manual Download Page 51](http://html1.mh-extra.com/html/yoctopuce/yocto-gps/yocto-gps_user-manual_3415557051.webp)
}
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.
import
{
YAPI, YErrorMsg, YModule
}
from
'yoctolib-es'
;
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
)
{
var
newname = args
[
1
]
;
if
(
!
await
YAPI.
CheckLogicalName
(
newname
))
{
console.
log
(
"Invalid name ("
+ n
")"
)
;
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
()
;
}
if(
process.
argv
.
length
<
3
)
{
console.
log
(
"usage: jspm run src/demo.js <serial> [newLogicalName]"
)
;
}
else
{
startDemo
(
process.
argv
.
slice
(
process.
argv
.
length
-
3
))
;
}
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.
import
{
YAPI, YModule, YErrorMsg
}
from
'yoctolib-es'
;
async
function
startDemo
()
7. Using Yocto-GPS with JavaScript / EcmaScript
www.yoctopuce.com
45
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: ......