9. Utilisation du Yocto-IO en C#
Console.WriteLine("Channels 0..1 are configured as outputs and channels
Console.WriteLine("are configred as inputs, you can connect some inputs
Console.WriteLine("ouputs and see what
int
outputdata
while (io.isOnline()) {
int
inputdata
string
line
for
(int
i
if
((inputdata
line
=
} else {
line
=
}
}
Console.WriteLine("port value = "
outputdata
io.set_portState(outputdata);
YAPI.Sleep(1000,
}
YAPI.FreeAPI();
}
}
}
9.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);
}
}
50
= 0;
= io.get_portState();
= "";
// display port value as binary
= 0;
i
< 4; i++) {
&
(8
>> i)) > 0) {
line
+ '1';
line
+ '0';
=
(outputdata
+ 1) % 4;
// We could have used set_bitState as well
ref errmsg);
= System.AppDomain.CurrentDomain.FriendlyName;
+
" <serial or logical name>
= "";
ref errmsg) !=
< 1)
usage();
// use serial or logical name
>= 2) {
happens");
// read port values
+ line);
// cycle ouput 0..3
[ON/OFF]");
YAPI.SUCCESS) {
+ errmsg);
2..3");
to");
www.yoctopuce.com