Un exemple réel
Lancez votre environnement Delphi, copiez la DLL yapi.dll dans un répertoire et créez une nouvelle
application console dans ce même répertoire, et copiez-coller le code ci dessous.
Vous reconnaîtrez dans cet exemple l'utilisation des fonctions expliquées ci-dessus, cette fois
utilisées avec le décorum nécessaire à en faire un petit programme d'exemple concret.
program
helloworld;
{$APPTYPE CONSOLE}
uses
SysUtils,
Windows,
yocto_api,
yocto_tilt,
yocto_compass,
yocto_accelerometer,
yocto_gyro;
Procedure
Usage();
var
exe : string;
begin
exe:= ExtractFileName(paramstr(0));
WriteLn(exe+'
WriteLn(exe+'
WriteLn(exe+'
halt;
End;
var
m
: TYmodule;
anytilt,tilt1,tilt2
Compass
: TYcompass;
accelerometer : TYAccelerometer;
gyro
: TYGyro;
errmsg,serial : string;
done
: boolean;
count
: integer;
begin
if (paramcount<1) then
// Setup the API to use local USB devices
if
yRegisterHub('usb', errmsg)<>YAPI_SUCCESS
begin
Write('RegisterHub error:
exit;
end;
if
paramstr(1)='any'
begin
// lets try to find the first available tilt sensor
anytilt := yFirstTilt();
if anytilt=nil then
begin
writeln('No module connected (check USB
halt;
end
end
else
// or the one specified on command line
anytilt:= YFindTilt(paramstr(1)+'.tilt1');
// make sure it is online
if
not anytilt.isOnline() then
begin
writeln('No module connected (check USB
halt;
end;
// lets find the parent module so we can get the other sensors
m
:=
anytilt.get_module();
serial :=
m.get_serialNumber();
www.yoctopuce.com
<serial_number>');
<logical_name>');
any');
: TYTilt;
usage();
'+errmsg);
then
18. Utilisation du Yocto-3D-V2 en Delphi
then
cable)');
cable)');
145