12. Utilisation du Yocto-Meteo en C#
if
((hsensor
Console.WriteLine("No module connected (check USB cable)
Environment.Exit(0);
}
} else {
hsensor
=
tsensor
=
psensor
=
}
if (!hsensor.isOnline()) {
Console.WriteLine("Module not
Console.WriteLine("check identification and USB
Environment.Exit(0);
}
while (hsensor.isOnline()) {
Console.WriteLine("Current humidity:
Console.WriteLine("Current temperature: "
Console.WriteLine("Current pressure:
Console.WriteLine("
YAPI.Sleep(1000,
}
YAPI.FreeAPI();
}
}
}
12.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.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace
ConsoleApplication1
{
class
Program
{
static
void
usage()
{
string
execname
Console.WriteLine("Usage:");
Console.WriteLine(execname
System.Threading.Thread.Sleep(2500);
Environment.Exit(0);
}
static
void
Main(string[] args)
{
YModule
m;
string
errmsg
if
(YAPI.RegisterHub("usb",
Console.WriteLine("RegisterHub error: "
Environment.Exit(0);
}
if
(args.Length
m
= YModule.FindModule(args[0]);
if (m.isOnline()) {
if
(args.Length
if (args[1].ToUpper() == "ON") {
84
== null) ||
(tsensor
YHumidity.FindHumidity(target
YTemperature.FindTemperature(target
YPressure.FindPressure(target
connected");
+
"
%RH");
+
"
°C");
+
"
hPa");
(press Ctrl-C to
ref errmsg);
= System.AppDomain.CurrentDomain.FriendlyName;
+
" <serial or logical name>
= "";
ref errmsg) !=
< 1)
usage();
>= 2) {
== null) ||
(psensor
+ ".humidity");
+ ".temperature");
+ ".pressure");
cable");
"
+ hsensor.get_currentValue().ToString()
+ tsensor.get_currentValue().ToString()
"
+ psensor.get_currentValue().ToString()
exit)");
YAPI.SUCCESS) {
+ errmsg);
// use serial or logical name
== null)) {
");
[ON/OFF]");
www.yoctopuce.com