Yoctopuce Yocto-RangeFinder Mode D'emploi page 147

Table des Matières

Publicité

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_rangeFinder,
yocto_lightSensor,
yocto_temperature;
Procedure
Usage();
var
exe : string;
begin
exe:= ExtractFileName(paramstr(0));
WriteLn(exe+'
WriteLn(exe+'
WriteLn(exe+'
sleep(2500);
halt;
End;
var
rf : TYRangeFinder;
ir : TYLightSensor;
tmp : TYTemperature;
m : TYModule;
errmsg,target : string;
done
: boolean;
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;
target := paramstr(1);
if
target='any'
begin
// search for the first available light sensor
rf := yFirstRangeFinder();
if
rf =
nil then
begin
writeln('No module connected (check USB
halt;
end;
m := rf.get_module();
target := m.get_serialNumber();
end
else
// or use the one specified on command line
rf := YFindRangeFinder(target+'.rangeFinder1');
ir := YFindLightSensor(target+'.lightSensor1');
tmp := YFindTemperature(target+'.temperature1');
// lets poll the sensor
done := false;
repeat
if (rf.isOnline()) then
begin
Writeln('Distance
Writeln('Ambiant IR
Writeln('Temperature :
Writeln('
YSleep(1000,errmsg);
end
else
begin
Writeln('Module not connected (check identification and USB
www.yoctopuce.com
<serial_number>');
<logical_name>');
any');
usage();
'+errmsg);
then
:
'+FloatToStr(rf.get_currentValue()));
:
'+FloatToStr(ir.get_currentValue()));
'+FloatToStr(tmp.get_currentValue()));
(press Ctrl-C to
exit)');
18. Utilisation du Yocto-RangeFinder en Delphi
then
cable)');
cable)');
141

Publicité

Table des Matières
loading

Table des Matières