10. Utilisation du Yocto-RangeFinder en C#
}
ir
=
YLightSensor.FindLightSensor(target
tmp
=
YTemperature.FindTemperature(target
while (rf.isOnline()) {
Console.WriteLine("Distance
Console.WriteLine("Ambiant IR
Console.WriteLine("Temperature : "
Console.WriteLine("
YAPI.Sleep(1000,
}
YAPI.FreeAPI();
}
}
}
10.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") {
m.set_beacon(YModule.BEACON_ON);
}
if (args[1].ToUpper() == "OFF") {
m.set_beacon(YModule.BEACON_OFF);
}
}
Console.WriteLine("serial:
Console.WriteLine("logical name: "
Console.WriteLine("luminosity:
Console.Write("beacon:
if (m.get_beacon() == YModule.BEACON_ON)
Console.WriteLine("ON");
else
Console.WriteLine("OFF");
58
: "
: "
(press Ctrl-C to
ref errmsg);
= System.AppDomain.CurrentDomain.FriendlyName;
+
" <serial or logical name>
= "";
ref errmsg) !=
< 1)
usage();
// use serial or logical name
>= 2) {
");
+ ".lightSensor1");
+ ".temperature1");
+ rf.get_currentValue().ToString());
+ ir.get_currentValue().ToString());
+ tmp.get_currentValue().ToString());
exit)");
YAPI.SUCCESS) {
+ errmsg);
"
+ m.get_serialNumber());
+ m.get_logicalName());
"
+ m.get_luminosity().ToString());
[ON/OFF]");
www.yoctopuce.com