11. Utilisation du Yocto-I2C en C#
Console.WriteLine("RegisterHub error: "
Environment.Exit(0);
}
if
(target
== "ANY") {
i2cPort
= YI2cPort.FirstI2cPort();
if
(i2cPort
Console.WriteLine("No module connected (check USB cable)
Environment.Exit(0);
}
target
= i2cPort.get_module().get_serialNumber();
}
i2cPort
=
YI2cPort.FindI2cPort(target
if (i2cPort.isOnline()) {
i2cPort.set_i2cMode("400kbps");
i2cPort.set_i2cVoltageLevel(YI2cPort.I2CVOLTAGELEVEL_3V3);
i2cPort.reset();
// do not forget to configure the powerOutput and
// of the Yocto-I2C as well if used
Console.WriteLine("****************************");
Console.WriteLine("* make sure voltage levels
Console.WriteLine("* are properly configured
Console.WriteLine("****************************");
List<int>
List<int>
int
tempReg
if
((tempReg
tempReg
} else {
tempReg
}
Console.WriteLine("Ambiant temperature: "
16.0)));
} else {
Console.WriteLine("Module not
Console.WriteLine("check identification and USB
}
YAPI.FreeAPI();
// wait 5 sec to show the output
ulong
now
= YAPI.GetTickCount();
while (YAPI.GetTickCount() -
}
}
}
11.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);
}
72
== null) {
toSend
= new List<int>(new int[] {0x05});
received
=
i2cPort.i2cSendAndReceiveArray(0x1f, toSend,
= (received[0] << 8) + received[1];
& 0x1000) != 0) {
-= 0x2000;
// perform sign extension
&= 0x0fff;
// clear status bits
connected");
now
= System.AppDomain.CurrentDomain.FriendlyName;
+
" <serial or logical name>
+ errmsg);
+ ".i2cPort");
*");
*");
+
String.Format("{0:0.000}", (tempReg
cable");
< 5000);
");
2);
[ON/OFF]");
www.yoctopuce.com
/