unit uFtInterface; { zur Dokumentation siehe umFish13.doc, mk 17.5.03 }

interface

const
  ftiAus=0; ftiEin=1; ftiLinks=1; ftiRechts=2;
  ftiFehler=$0001FFFF; ftiTrue=-1; ftiFalse=0;

type
  TftiDCB = record
              hCom        : LongInt;
              PortID      : LongInt;
              LPTDelay    : LongInt;
              LPTAnalog   : LongInt;
              InputStatus : LongInt;
              MotorStatus : LongInt;
            end;
  TpftiDCB = ^TftiDCB;

  TftInterface = class(TObject)
  private
    ftiDCB  : TftiDCB;
    ft      : TpftiDCB;
  public
    constructor Create;
    function OpenInterface : boolean; 
    procedure CloseInterface;
    function GetInputs : word;
    function GetInput(InputNr : byte) : boolean;
    procedure ClearMotors;
    procedure SetMotors(Status: byte);
    procedure SetMotor(MotorNr, Richtung : byte);
    procedure SetLamp(LampNr, Zustand : byte);
    function GetMotorStatus : word;
    function GetAnalog(AnalogNr : byte) : word;
    function StartDriver : boolean;
    procedure StopDriver;
  end;

implementation

  constructor TftInterface.Create;
  begin
    inherited;
    ft := @ftiDCB;
  end;

  function OpenInterfaceDll(ft: TpftiDCB; PortName: string):LongInt;
       stdcall; external 'umFish.dll' name 'OpenInterface';
  function CloseInterfaceDLL(ft: TpftiDCB):LongInt;
         stdcall; external 'umFish.dll' name 'CloseInterface';
  function GetInputDLL(ft: TpftiDCB; InputNr:LongInt):LongInt;
         stdcall; external 'umFish.dll' name 'GetInput';
  function GetInputsDLL(ft: TpftiDCB):LongInt;
         stdcall; external 'umFish.dll' name 'GetInputs';
  function ClearMotorsDLL(ft: TpftiDCB):LongInt;
         stdcall; external 'umFish.dll' name 'ClearMotors';
  function SetMotorsDLL(ft: TpftiDCB; MotorStatus:LongInt):LongInt;
         stdcall; external 'umFish.dll' name 'SetMotors';
  function SetMotorDLL(ft: TpftiDCB; MotorNr, Direction:LongInt):LongInt;
         stdcall; external 'umFish.dll' name 'SetMotor';
  function SetLampDLL(ft: TpftiDCB; LampNr, OnOff:LongInt):LongInt;
         stdcall; external 'umFish.dll' name 'SetLamp';
  function GetAnalogDLL(ft: TpftiDCB; AnalogNr:LongInt):LongInt;
         stdcall; external 'umFish.dll' name 'GetAnalog';
  function StartDriverDLL():LongInt;
         stdcall; external 'umFish.dll' name 'StartDriver';
  function StopDriverDLL():LongInt;
         stdcall; external 'umFish.dll' name 'StopDriver';

function TftInterface.OpenInterface : boolean;
begin
  Result := (OpenInterfaceDLL(ft,'LPT')<> ftiFehler);
end;

procedure TftInterface.CloseInterface;
begin
  CloseInterfaceDLL(ft);
end;

function TftInterface.GetInputs : word;
begin
  Result := GetInputsDLL(ft);
end;

function TftInterface.GetInput(InputNr : byte) : boolean;
begin
  result := (GetInputDLL(ft,InputNr) < 0);
end;

procedure TftInterface.ClearMotors;
begin
  ClearMotorsDLL(ft);
end;

function TftInterface.GetMotorStatus : word;
begin
  Result := ftiDCB.MotorStatus;
end;

procedure TftInterface.SetMotors(Status : byte);
begin
  SetMotorsDLL(ft,Status);
end;

procedure TftInterface.SetMotor(MotorNr, Richtung : byte);
begin
  SetMotorDLL(ft,MotorNr,Richtung);
end;

procedure TftInterface.SetLamp(LampNr, Zustand : byte);
begin
  if LampNr mod 2 = 1 then Inc(LampNr) else Dec(LampNr);
  SetLampDLL(ft,LampNr,Zustand);
end;

function TftInterface.GetAnalog(AnalogNr : byte) : word;
begin
  Result := GetAnalogDLL(ft,AnalogNr);
end;

function TftInterface.StartDriver : boolean;
begin
  Result := (StartDriverDLL()<> ftiFehler);
end;

procedure TftInterface.StopDriver;
begin
  StopDriverDLL();
end;

end.

