12. Utilisation du Yocto-Color en C#
if
(YAPI.RegisterHub("usb",
Console.WriteLine("RegisterHub error: "
Environment.Exit(0);
}
if
(target ==
led1 = YColorLed.FirstColorLed();
if
(led1 ==
Console.WriteLine("No module connected (check USB cable)
Environment.Exit(0);
}
led2 = led1.nextColorLed();
} else {
led1 = YColorLed.FindColorLed(target + ".colorLed1");
led2 = YColorLed.FindColorLed(target + ".colorLed2");
}
if (led1.isOnline()) {
led1.set_rgbColor(color);// immediate switch
led2.rgbMove(color, 1000);
} else {
Console.WriteLine("Module not connected (check identification and USB
}
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 = System.AppDomain.CurrentDomain.FriendlyName;
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()
m.set_beacon(YModule.BEACON_ON);
76
ref errmsg)
"ANY") {
null) {
// smooth transition
" <serial or logical name>
ref errmsg)
<
1)
usage();
// use serial or logical name
>=
2) {
==
"ON") {
!=
YAPI.SUCCESS) {
+ errmsg);
[ON/OFF]");
!=
YAPI.SUCCESS) {
+ errmsg);
");
cable)");
www.yoctopuce.com