import os,
sys
from
yocto_api
import
from
yocto_rangefinder
from
yocto_lightsensor
from
yocto_temperature
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 +
errmsg
= YRefParam()
if len(sys.argv) <
usage()
target
= sys.argv[1]
# Setup the API to use local USB devices
if YAPI.RegisterHub("usb", errmsg) !=
sys.exit("init error"
if
target
==
'any':
# retrieve any Range finder
rf
= YRangeFinder.FirstRangeFinder()
if
rf
is
None:
die('No module
target
= rf.get_module().get_serialNumber()
else:
rf
=
YRangeFinder.FindRangeFinder(target +
if not
(rf.isOnline()):
die('device not
ir
= YLightSensor.FindLightSensor(target+'.lightSensor1')
tmp
= YTemperature.FindTemperature(target+'.temperature1')
while
rf.isOnline():
print("Distance
print("Ambiant IR
print("Temperature :
YAPI.Sleep(1000)
YAPI.FreeAPI()
8.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
*
import
*
import
*
import
*
'
<serial_number>')
'
<logical_name>')
' any
')
' (check USB
cable)')
2:
YAPI.SUCCESS:
+
errmsg.value)
connected')
connected')
:
"
+
str(int(rf.get_currentValue())) )
:
"
+
str(int(ir.get_currentValue())) )
"
+
str(int(tmp.get_currentValue())) )
*
YAPI.SUCCESS:
+
str(errmsg))
2:
8. Utilisation du Yocto-RangeFinder en Python
'.rangeFinder1')
[ON/OFF]")
43