Télécharger Imprimer la page

Contrôle De La Partie Module - Yoctopuce Yocto-Temperature-IR Mode D'emploi

Publicité

#!/usr/bin/python
# -*- coding: utf-8 -*-
import os,
sys
from
yocto_api
import
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':
# retreive any temperature sensor
sensor
= YTemperature.FirstTemperature()
if
sensor
is
None:
die('No module
else:
sensor
=
YTemperature.FindTemperature(target +
if not
(sensor.isOnline()):
die('device not
# retreive module serial
serial
= sensor.get_module().get_serialNumber()
# retreive both channels
channel1
=
YTemperature.FindTemperature(serial +
channel2
=
YTemperature.FindTemperature(serial +
while
channel1.isOnline():
print("Ambiant: "
"%2.1f"
" deg C (Ctrl-C to
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>
www.yoctopuce.com
*
import
*
'
<serial_number>')
'
<logical_name>')
' any
')
' (check USB
cable)')
2:
YAPI.SUCCESS:
+
errmsg.value)
connected')
connected')
+
"%2.1f / Infrared: "
%
channel2.get_currentValue()
stop)")
*
8. Utilisation du Yocto-Temperature-IR en Python
'.temperature1')
'.temperature1')
'.temperature2')
%
channel1.get_currentValue()
+ \
[ON/OFF]")
+ \
39

Publicité

loading