#!/usr/bin/python
# -*- coding: utf-8 -*-
import os,
sys
from
yocto_api
import
from
yocto_gps
import
def
usage():
scriptname
= os.path.basename(sys.argv[0])
print("Usage:")
print(scriptname +
print(scriptname +
print(scriptname +
sys.exit()
def
die(msg):
sys.exit(msg +
if len(sys.argv) <
usage()
target
= sys.argv[1]
# Setup the API to use local USB devices
errmsg
= YRefParam()
if YAPI.RegisterHub("usb", errmsg) !=
sys.exit("init error"
if
target
==
'any':
# retreive any gps
gps
= YGps.FirstGps()
if
gps
is
None:
die('No module
else:
gps
=
YGps.FindGps(target +
if not
(gps.isOnline()):
die('device not
while
gps.isOnline():
if gps.get_isFixed() !=
print("Fixing...")
else:
print(gps.get_latitude()
YAPI.Sleep(1000)
YAPI.FreeAPI()
15.4. Contrôle de la partie module
Chaque module peut-être contrôlé d'une manière similaire, vous trouverez ci-dessous un simple
programme d'exemple affichant les principaux paramètres d'un module et permettant d'activer la
balise de localisation.
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os,
sys
from
yocto_api
import
def
usage():
sys.exit("usage: demo <serial or logical name>
errmsg
= YRefParam()
if YAPI.RegisterHub("usb", errmsg) !=
sys.exit("RegisterHub error: "
if len(sys.argv) <
usage()
www.yoctopuce.com
*
*
'
<serial_number>')
'
<logical_name>')
' any
')
' (check USB
cable)')
2:
YAPI.SUCCESS:
+
errmsg.value)
connected')
'.gps')
connected')
YGps.ISFIXED_TRUE:
+
"
"
*
YAPI.SUCCESS:
+
str(errmsg))
2:
+
gps.get_longitude())
[ON/OFF]")
15. Utilisation du Yocto-GPS-V2 en Python
111