13. Utilisation du Yocto-Demo en Delphi
SysUtils,
yocto_api,
yocto_led;
Procedure
Usage();
var
exe : string;
begin
exe:= ExtractFileName(paramstr(0));
WriteLn(exe+'
WriteLn(exe+'
WriteLn(exe+'
halt;
End;
procedure
setLedState(led:TYLed; state:boolean);
begin
if (led.isOnline()) then
begin
if
state
then led.set_power(Y_POWER_ON)
else
end
else
Writeln('Module not connected (check identification and USB
end;
var
c
: char;
led
: TYLed;
errmsg
: string;
begin
// 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
// use the first available led
led := yFirstLed();
if
led=nil
then
begin
writeln('No module connected (check USB
halt;
end
end
else
// or use the one specified on the command line
led:= YFindLed(paramstr(1)+'.led');
// make sure it is connected
if not(led.isOnline()) then
begin
Writeln('Module not connected (check identification and USB
halt;
end;
// minimalist UI
Writeln('0: turn test led
Writeln('1: turn test led
Writeln('x:
exit');
repeat
read(c);
case
c
of
'0'
: setLedState(led,false);
'1'
: setLedState(led,true);
end;
until
c='x';
end.
Il n'y a que peu de lignes véritablement importantes dans le code précédent. Nous allons les
expliquer en détail.
72
<serial_number>');
<logical_name>');
any');
led.set_power(Y_POWER_OFF);
'+errmsg);
then
OFF');
ON');
then
cable)');
cable)');
cable)');
www.yoctopuce.com