unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
type
TForm2 =
class(TForm)
Button1: TButton;
Timer1: TTimer;
Label1: TLabel;
Button2: TButton;
Label2: TLabel;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
ClockStarted: Boolean;
TimeElapsed: cardinal;
// in Millisekunden
TimeStarted: cardinal;
//
TimeStopped: cardinal;
//
procedure StartClock;
procedure StoppClock;
procedure ResetClock;
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
function OpenDevice(CardAddress: Longint): Longint;
stdcall;
external '
K8055d.dll';
procedure CloseDevice;
stdcall;
external '
K8055d.dll';
function ReadAnalogChannel(Channel: Longint):Longint;
stdcall;
external '
K8055d.dll';
procedure ReadAllAnalog(
var Data1, Data2: Longint);
stdcall;
external '
K8055d.dll';
procedure OutputAnalogChannel(Channel: Longint; Data: Longint);
stdcall;
external '
K8055d.dll';
procedure OutputAllAnalog(Data1: Longint; Data2: Longint);
stdcall;
external '
K8055d.dll';
procedure ClearAnalogChannel(Channel: Longint);
stdcall;
external '
K8055d.dll';
procedure ClearAllAnalog;
stdcall;
external '
K8055d.dll';
procedure SetAnalogChannel(Channel: Longint);
stdcall;
external '
K8055d.dll';
procedure SetAllAnalog;
stdcall;
external '
K8055d.dll';
procedure WriteAllDigital(Data: Longint);
stdcall;
external '
K8055d.dll';
procedure ClearDigitalChannel(Channel: Longint);
stdcall;
external '
K8055d.dll';
procedure ClearAllDigital;
stdcall;
external '
K8055d.dll';
procedure SetDigitalChannel(Channel: Longint);
stdcall;
external '
K8055d.dll';
procedure SetAllDigital;
stdcall;
external '
K8055d.dll';
function ReadDigitalChannel(Channel: Longint): Boolean;
stdcall;
external '
K8055d.dll';
function ReadAllDigital: Longint;
stdcall;
external '
K8055d.dll';
function ReadCounter(CounterNr: Longint): Longint;
stdcall;
external '
K8055d.dll';
procedure ResetCounter(CounterNr: Longint);
stdcall;
external '
K8055d.dll';
procedure SetCounterDebounceTime(CounterNr, DebounceTime:Longint);
stdcall;
external '
K8055d.dll';
// Auto ansteuern
procedure TForm2.Button1Click(Sender: TObject);
begin
SetDigitalChannel(1);
Timer1.Enabled := True;
StartClock;
end;
procedure TForm2.Timer1Timer(Sender: TObject);
begin
ClearDigitalChannel(1);
end;
// Stoppuhr
function TicksToTime(TickCount: cardinal):
string;
begin
result := Format('
%.2d:%.2d:%.2d',
[TickCount
div 1000
div 60,
// Minuten
TickCount
div 1000
mod 60,
// Sekunden
TickCount
mod 1000
div 10]);
// Hundertstel
end;
procedure TForm2.Button2Click(Sender: TObject);
begin
ResetClock;
end;
procedure TForm2.FormCreate(Sender: TObject);
begin
ClockStarted := False;
TimeStarted := 0;
TimeStopped := 0;
end;
procedure TForm2.ResetClock;
begin
StoppClock;
TimeStopped := 0;
Label2.Caption := TicksToTime(0);
// = '00:00:00'
end;
procedure TForm2.StartClock;
begin
ClockStarted := True;
TimeStarted := GetTickCount;
repeat
TimeElapsed := GetTickCount-TimeStarted;
Label2.Caption := TicksToTime(TimeStopped+TimeElapsed);
application.ProcessMessages;
// damit sich das Programm nicht "aufhängt"
if application.Terminated
then // Falls die Anwendung inzwischen beendet wurde
exit;
sleep(1);
// 100% CPU-Auslastung vermeiden
until not ClockStarted;
end;
procedure TForm2.StoppClock;
begin
ClockStarted := False;
TimeStopped := getTickcount-TimeStarted + TimeStopped;
Label2.Caption := TicksToTime(TimeStopped);
end;
end.