![Yoctopuce Yocto-GPS User Manual Download Page 50](http://html1.mh-extra.com/html/yoctopuce/yocto-gps/yocto-gps_user-manual_3415557050.webp)
example using URL
http://127.0.0.1/EcmaScript/example_html/Doc-GettingStarted-Yocto-GPS/
demo.html
then the beginning of your
jspm.browser.js
file should look like:
SystemJS.
config
({
baseURL:
"/EcmaScript/example_html/Doc-GettingStarted-Yocto-GPS/"
,
...
}
If you prefer to open the demo code as a local file rather than through a web server, or if you would
like the example to load as a single JavaScript file rather than as dynamically loaded modules, you
can
build
it with the command:
jspm build --minify src/demo.js demo-sfx.js
This will create a single JavaScript file named
demo-sfx.js
in the root directory of the project, that
can be included directly in the HTML file instead of the 6
script
lines:
<
script
src
='demo-sfx.js'></
script
>
Once your project is built in this way, the example can be opened by a browser directly from the local
disk.
7.4. Control of the module part
Each module can be controlled in a similar manner, you can find below a simple sample program
displaying the main parameters of the module and enabling you to activate the localization beacon.
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
)
{
if(
args
[
1
]
==
'ON'
)
{
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
<
3
)
{
console.
log
(
"usage: jspm run src/demo.js <serial or logicalname> [ ON | OFF ]"
)
;
}
else
{
startDemo
(
process.
argv
.
slice
(
process.
argv
.
length
-
3
))
;
7. Using Yocto-GPS with JavaScript / EcmaScript
44
www.yoctopuce.com
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: ......