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,
yocto_api,
yocto_digitalIO;
procedure
usage();
var
execname,errmsg:string;
begin
execname := ExtractFileName(paramstr(0));
WriteLn('Usage:');
WriteLn(execname +
WriteLn(execname +
WriteLn(execname +
WriteLn('Example:');
WriteLn(execname +
ysleep(2500,errmsg);
halt;
end;
var
errmsg,target:string;
io:TYDigitalIO;
m : TYModule;
outputdata,inputdata,i :integer;
line:string;
begin
if (paramcount<1) then
// parse command line
target :=
UpperCase(paramstr(1));
// Setup the API to use local USB devices
if
(YRegisterHub('usb',
begin
writeln('RegisterHub error: '
halt;
end;
if (target='ANY') then
begin
// try to find the first available digitial IO
io :=
YFirstDigitalIO();
if
(io
=nil) then
begin
writeln('No module connected (check USB
halt;
end;
// retreive the hosting device serial
m :=
io.get_module();
target := m. get_serialNumber();
end;
Writeln('using '
// retreive the right DigitalIO function
io := YFindDigitalIO(target + '.digitalIO');
// make sure the device is here
if not(io.isOnline()) then
begin
writeln('Module not connected (check identification and USB
halt;
end;
// lets configure the channels direction
// bits 0..1 as output
// bits 2..3 as input
io.set_portDirection($03);
io.set_portPolarity(0);
io.set_portOpenDrain(0);
// We could have used set_bitXXX to configure channels one by one
www.yoctopuce.com
' <serial_number>
' <logical_name>
' any
');
' any
');
usage();
errmsg)
<>
YAPI_SUCCESS)
+ errmsg);
+ target);
// polarity set to regular
// No open drain
');
');
then
feature
cable)');
17. Utilisation du Yocto-IO en Delphi
cable)');
133