12. Utilisation du Yocto-4-20mA-Tx en C#
Environment.Exit(0);
}
if
(args.Length
target
= args[0].ToUpper();
value = Convert.ToDouble(args[1]);
if
(target
== "ANY") {
loop
= YCurrentLoopOutput.FirstCurrentLoopOutput();
if
(loop
== null) {
Console.WriteLine("No module connected (check USB cable)
Environment.Exit(0);
}
} else {
loop
=
YCurrentLoopOutput.FindCurrentLoopOutput(target
}
if (loop.isOnline()) {
loop.set_current(value);
int
loopPower
if
(loopPower
Console.WriteLine("Current loop not
Environment.Exit(0);
}
if
(loopPower
Console.WriteLine("Insufficient voltage on current
Environment.Exit(0);
}
Console.WriteLine("current loop set to "
} else {
Console.WriteLine("Module not
Console.WriteLine("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
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);
80
< 2) usage();
= loop.get_loopPower();
== YCurrentLoopOutput.LOOPPOWER_NOPWR) {
== YCurrentLoopOutput.LOOPPOWER_LOWPWR) {
connected");
= System.AppDomain.CurrentDomain.FriendlyName;
+
" <serial or logical name>
= "";
ref errmsg) !=
+ ".currentLoopOutput");
powered");
loop");
+ value.ToString() +
cable");
[ON/OFF]");
YAPI.SUCCESS) {
+ errmsg);
");
"
mA");
www.yoctopuce.com