19. Utilisation du Yocto-I2C en Delphi
// sample code reading MCP9804 temperature sensor
i2cPort.set_i2cMode('400kbps');
i2cPort.set_i2cVoltageLevel(Y_I2CVOLTAGELEVEL_3V3);
i2cPort.reset();
// do not forget to configure the powerOutput
// of the Yocto-I2C as well if used
writeln('****************************');
writeln('* make sure voltage levels
writeln('* are properly configured
writeln('****************************');
setLength(toSend, 1);
toSend[0]
:= $05;
received := i2cPort.i2cSendAndReceiveArray($1f, toSend, 2);
tempReg :=
(received[0] shl 8)
if
(tempReg
tempReg := tempReg -
else
tempReg := tempReg
WriteLn('Ambiant temperature:
end
else
writeln('Module not connected (check identification and USB
yFreeAPI();
end.
19.3. 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.
program
modulecontrol;
{$APPTYPE CONSOLE}
uses
SysUtils,
yocto_api;
const
serial = 'YI2CMK01-123456';
procedure refresh(module:Tymodule)
begin
if (module.isOnline())
begin
Writeln('');
Writeln('Serial
Writeln('Logical name : '
Writeln('Luminosity
Write('Beacon
if
(module.get_beacon()=Y_BEACON_ON) then Writeln('on')
Writeln('uptime
Writeln('USB current
Writeln('Logs
Writeln(module.get_lastlogs());
Writeln('');
Writeln('r : refresh / b:beacon ON / space : beacon
end
else
Writeln('Module not connected (check identification and USB
end;
procedure
beacon(module:Tymodule;state:integer);
begin
module.set_beacon(state);
refresh(module);
end;
var
module : TYModule;
c
: char;
errmsg : string;
156
+ received[1];
and $1000)
<>
0
then
$2000
and
$0fff;
', tempReg / 16.0);
// use serial number or logical name
;
then
: '
+ module.get_serialNumber());
+ module.get_logicalName());
: '
+ intToStr(module.get_luminosity()));
:');
: '
+
intToStr(module.get_upTime() div
: '
+ intToStr(module.get_usbCurrent())+'mA');
:
');
*');
*');
// perform sign extension
// clear status bits
else
Writeln('off');
off');
cable)');
1000)+'s');
cable)');
www.yoctopuce.com