Salve a tutti qualcuno sa darmi una spigazione di questo erempio di dll?
Questo esempio serve per creare una dll che poi verrà caricata su un software di automatismi vorrei capirci qualcosa e poi modificare tale sorgente.
Example DLL source (Delphi)
The compiled DLL file can be found in the EXAMPLES directory (COUNTER.DLL).
codice:
library Counter;
// Delphi 5 DLL-source (COUNTER.DLL)
// Defines a simple 8-Bit counter component for ProfiLab
uses
SysUtils,Windows,Classes;
{$R *.RES}
Const Inputs = 2; // number of inputs
Outputs = 8; // number of outputs
{INPUTS}
CLK = 0; // index of input variable CLK
RST = 1; // index of input variable RST
{OUTPUTS}
{USER}
CLK_old = 0; // index user variable CLK_old
RST_old = 1; // index user variable RST_old
Count = 2; // index user variable COUNT
Type TDLLParams = array[0..100] of extended; //Type of ProfiLab DLL parameters
PDLLParams = ^TDLLParams; // Pointer to ProfiLab DLL parameters
function NumInputs: Byte;
begin
result:=Inputs; //Define number of component input pins
end;
function NumOutputs: Byte;
begin
result:=Outputs; //Define number of component output pins
end;
Function InputName(Channel: Byte): ShortString; // Return name for each component input pin
begin
case Channel of
CLK: result:='CLK'; // "CLK" (Clock)
RST: result:='/RST'; // "/RST" (NOT RESET)
end;
end;
Function OutputName(Channel: Byte): ShortString; // Return name for each component output pin
begin
result:='Q'+intToStr(Channel); //"Q0".."Q7" (Binary count)
end;
Procedure SimStart(PInput,POutput,PUser: PDLLParams); //called when ProfiLab enters RUN mode
var i: Integer;
begin
PUser^[Count]:=0; //RESET COUNTER
For i:=0 to Outputs do
begin
POutput[i]:=0; //Set binary outputs with COUNT=0
end;
end;
Procedure SimStop(PInput,POutput,PUser: PDLLParams); //called when ProfiLab RUN mode is terminated
begin
// nothing to be done
end;
Procedure Calculate(PInput,POutput,PUser: PDLLParams); //called regularly from ProfiLab
var i: Integer;
begin
if PInput^[RST]<2.5 then //check RST input HIGH or LOW
begin
if (not (PInput^[RST]>=2.5)) and (PUser^[RST_old]>2.5) then //check out falling edge at RST input
begin
PUser^[Count]:=0; //RESET COUNT
For i:=0 to Outputs do
begin
POutput[i]:=0; //Set binary outputs with COUNT=0
end;
end;
exit;
end;
PUser^[RST_old]:=PInput^[RST]; //Remember RST status for next call
if PInput^[CLK]>2.5 then //check CLK input HIGH or LOW
begin
if (PInput^[CLK]>2.5) and not(PUser^[CLK_old]>2.5) then //check out rising edge at CLK input
begin
PUser^[Count]:=PUser^[Count]+1; // increase COUNT
if PUser^[Count]>255 then PUser^[Count]:=0; //check overflow
For i:=0 to Outputs do
begin
if (round(PUser^[Count]) and (1 shl i))>0 then POutput^[i]:=5 else POutput[i]:=0; //Set binary outputs with current COUNT
end;
end;
end;
PUser^[CLK_old]:=PInput^[CLK]; //Remember CLK status for next call
end;
//export methods for ProfiLab
exports SimStart,
SimStop,
NumInputs,
NumOutputs,
Calculate,
InputName,
OutputName;
begin
end.