Thema: Delphi Timer stoppen

Einzelnen Beitrag anzeigen

DelphiManiac

Registriert seit: 5. Dez 2005
742 Beiträge
 
#29

Re: Timer stoppen

  Alt 29. Feb 2008, 15:08
Ok du willst Code du kriegst Code

Delphi-Quellcode:
procedure TMainGUI.tmrAblaufTimer(Sender: TObject);
var
  active:Boolean;
  time1,time2:Cardinal;
  Failure:Boolean;
begin
  TTimer(Sender).Enabled:=false;
  active:=False;
  if TimerIsActive then exit;
try
  if not Assigned(aCS200) then Exit;
  TimerIsActive:=True;
  if TimeOut then exit;
  time1:=GetTickCount;
  tmrAblauf.Tag:= tmrAblauf.Tag+1;
  lblRequestVal.Caption:=IntToStr(tmrAblauf.Tag);
  Failure:=False;
  case tmrAblauf.Tag of
    1 : begin
          if (aCS200.Get_TempIntern(TempIntern))=0 then
          begin
            pbFortschritt.Position:=7;
          end
          else
          begin
            Failure:=True;
          end;
        end;
    2 : begin
         if (aCS200.Get_TempExtern(TempExtern))=0 then
         begin
           pbFortschritt.Position:=14;
         end
         else
         begin
           Failure:=True;
         end;
        end;
    3 : begin
          if (aCS200.Get_StoerungsFlags(stoerungsflags))=0 then
          begin
            pbFortschritt.Position:=21;
          end
          else
          begin
            Failure:=True;
          end;
        end;
    4 : begin
          if (aCS200.Get_SollWertFanIntern(SollWertFanIntern))=0 then
          begin
            pbFortschritt.Position:=28;
          end
          else
          begin
            Failure:=True;
          end;
        end;
    5 : begin
          if (aCS200.Get_FanInternSpeed_1(fan1InternSpeed))=0 then
          begin
            pbFortschritt.Position:=35;
          end
          else
          begin
            Failure:=True;
          end;
        end;
    6 : begin
          if (aCS200.Get_Fan1InternPuls(fan1InternPuls))=0 then
          begin
            pbFortschritt.Position:=42;
          end
          else
          begin
            Failure:=True;
          end;
        end;
    7 : begin
          if (aCS200.Get_FanInternSpeed_2(fan2InternSpeed))=0 then
          begin
            pbFortschritt.Position:=49;
          end
          else
          begin
            Failure:=True;
          end;
        end;
    8 : begin
          if (aCS200.Get_Fan2InternPuls(fan2InternPuls))=0 then
          begin
            pbFortschritt.Position:=56;
          end
          else
          begin
            Failure:=True;
          end;
        end;
    9 : begin
          if (aCS200.Get_SollWertFanExtern(SollWertFanExtern))=0 then
          begin
            pbFortschritt.Position:=63;
          end
          else
          begin
            Failure:=True;
          end;
        end;
    10: begin
          if (aCS200.Get_FanExternSpeed_1(fan1ExternSpeed))=0 then
          begin
            pbFortschritt.Position:=70;
          end
          else
          begin
            Failure:=True;
          end;
        end;
    11: begin
          if (aCS200.Get_FanExternSpeed_2(fan2ExternSpeed))=0 then
          begin
            pbFortschritt.Position:=77;
          end
          else
          begin
            Failure:=True;
          end;
        end;
    12: begin
          if (aCS200.Get_Fan1ExternPuls(fan1ExternPuls))=0 then
          begin
            pbFortschritt.Position:=84;
          end
          else
          begin
            Failure:=True;
          end;
        end;
    13: begin
          if (aCS200.Get_Fan2ExternPuls(fan2ExternPuls))=0 then
          begin
            pbFortschritt.Position:=91;
          end
          else
          begin
            Failure:=True;
          end;
        end;
    14: begin
          if (aCS200.Get_StoerungsFlags(stoerungsflags))=0 then
          begin
          pbFortschritt.Position:=95;
          end
          else
          begin
            Failure:=True;
          end;
        end;
    15: begin
          if (aCS200.Get_IOFlags(IOflags))=0 then
          begin
            pbFortschritt.Position:=98;
          end
          else
          begin
            Failure:=True;
          end;
        end;
    16: begin
          if (aCS200.Get_StatusFlags(Statusflags))=0 then
          begin
            pbFortschritt.Position:=100;
          end
          else
          begin
            Failure:=True;
          end;
        end;
    100 +1:
        begin
          WriteDataToDevice(Self);

        end;
    200 +1:
        begin
          ReadDataFromDevice(Self);

        end
    else
    begin
     tmrAblauf.Tag := 0;
     pbFortschritt.Position:=0;
    end;
  end;
  if Failure then
  begin
    MessageDlg('Fehler beim Lesen der Daten aus dem Wärmetauscher',mtError,[mbOK],0);
    exit;
  end;

  if TimeOut then
  begin
    exit;
  end;
  if Assigned(aCS200) then
  begin
    if aCS200.FSCI.isConnected then
    begin
      if not( (Assigned( aCS200 ))) then Exit;
      lnAkuelleInnenTemp.Clear;
      lnAktuelleAussenTemp.Clear;
      if not(stoerungsflags[8]) then
      begin
        // zeichne Aktuelle Innentemp auf Graph "Innenkreis"
        lnAkuelleInnenTemp.AddXY(TempIntern,-20,'',clBlack);
        lnAkuelleInnenTemp.AddXY(TempIntern+0.1,120,'',clBlack);

        // zeichne Aktuelle Innentemp auf Graph "Aussenkreis"
        lnAktuelleAussenTemp.AddXY(TempIntern,-20,'',clBlack);
        lnAktuelleAussenTemp.AddXY(TempIntern+0.1,120,'',clBlack);
      end
      else
      begin
        TempIntern:=-40;
      end;
      lblTempInternVal.Caption:=IntToStr(TempIntern) + ' [°C]';
      if (Statusflags[7]) then
      begin
        // TempFühler Aussen ist wirklich vorhanden
        lblTempExternVal.Caption:=IntToStr(TempExtern) + ' [°C]';
      end
      else
      begin
        lblTempExternVal.Caption:=' --' + ' [°C]';
      end;
      lblSollWertFanInternVal.Caption:=IntToStr(SollWertFanIntern) + ' [%] ';
      lblFanSpeed1InternVal.Caption:=IntToStr(fan1InternSpeed)+ ' [rpm] ' +
      ' bei '+IntToStr(fan1InternPuls)+ ' [P/s]';
      lblFanSpeed2InternVal.Caption:=IntToStr(fan2InternSpeed)+ ' [rpm]'+
      ' bei '+IntToStr(fan2InternPuls)+ ' [P/s]';


      lblSollWertFanExternVal.Caption:=IntToStr(SollWertFanExtern) + ' [%] ';
      lblFanSpeed1ExternVal.Caption:=IntToStr(fan1ExternSpeed)+ ' [rpm] ' +
      ' bei '+IntToStr(fan1ExternPuls)+ ' [P/s]';
      lblFanSpeed2ExternVal.Caption:=IntToStr(fan2ExternSpeed)+ ' [rpm]'+
      ' bei '+IntToStr(fan2ExternPuls)+ ' [P/s]';
      if IOflags[6] then begin
        ledTuerkontakt.ColorOn:=clLime;
      end else
      begin
        ledTuerkontakt.ColorOn:=clGray;
      end;
      if IOflags[5] then begin
        ledEndSchalter1.ColorOn:=clLime;
      end else
      begin
        ledEndSchalter1.ColorOn:=clGray;
      end;
      if IOflags[4] then begin
        ledEndSchalter2.ColorOn:=clLime;
      end else
      begin
        ledEndSchalter2.ColorOn:=clGray;
      end;
      if IOflags[3] then begin
        ledInAlarm1.ColorOn:=clLime;
      end else
      begin
        ledInAlarm1.ColorOn:=clGray;
      end;
      if IOflags[2] then begin
        ledInAlarm2.ColorOn:=clLime;
      end else
      begin
        ledInAlarm2.ColorOn:=clGray;
      end;
      if IOflags[8] then begin
        ledAlarm1.ColorOn:=clRed;
      end else
      begin
        ledAlarm1.ColorOn:=clGray;
      end;
      if IOflags[9] then begin
        ledAlarm2.ColorOn:=clRed;
      end else
      begin
        ledAlarm2.ColorOn:=clGray;
      end;
      if IOflags[10] then begin
        ledAlarm3.ColorOn:=clRed;
      end else
      begin
        ledAlarm3.ColorOn:=clGray;
      end;
      if IOflags[11] then begin
        ledHeizung.ColorOn:=clLime;
      end else
      begin
        ledHeizung.ColorOn:=clGray;
      end;
      if IOflags[12] then begin
        ledSammelstoerung.ColorOn:=clLime;
      end else
      begin
        ledSammelstoerung.ColorOn:=clGray;
      end;
      if IOflags[13] then begin
        ledExtern.ColorOn:=clLime;
      end else
      begin
        ledExtern.ColorOn:=clGray;
      end;
      if IOflags[14] then begin
        ledIntern.ColorOn:=clLime;
      end else
      begin
        ledIntern.ColorOn:=clGray;
      end;

      // Stoerungsflags
      lstStoerung.Clear;
      if stoerungsflags[8] then
      begin
        lstStoerung.AddItem('Temp-Sensor (intern) def.',nil);
        lblTempInternVal.Caption:='-- ' + ' [°C]';
        TempIntern:=-40;

      end;
      if stoerungsflags[7] then
      begin
        lstStoerung.AddItem('Temp-Sensor (extern) def.',nil);
        lblTempExternVal.Caption:='-- ' + ' [°C]';
      end;
      if stoerungsflags[6] then
      begin
        lstStoerung.AddItem('Feuchte-Sensor def.',nil);
      end;
      if stoerungsflags[1] then
      begin
        lstStoerung.AddItem('Fan-2 (extern) def.',nil);
      end;
      if stoerungsflags[2] then
      begin
        lstStoerung.AddItem('Fan-1 (extern) def.',nil);
      end;
      if stoerungsflags[3] then
      begin
        lstStoerung.AddItem('Fan-2 (intern) def.',nil);
      end;
      if stoerungsflags[4] then
      begin
        lstStoerung.AddItem('Fan-1 (intern) def.',nil);
      end;
      if stoerungsflags[5] then
      begin
        lstStoerung.AddItem('Heizung def.',nil);
      end;
      active:=True;
    end
    else
    begin
      InitGUI;
      exit;
    end;
  end;
  time2:=GetTickCount -time1;
finally
// windows.Beep(1500,200);
  TTimer(Sender).Enabled:=TimerSollLaufen;
  if not(TimerSollLaufen) then InitGUI;
  TimerIsActive:=false;
  if active then
  begin
    ledVerbunden.ColorOn:=clLime;;
  end
  else
  begin
    ledVerbunden.ColorOn:=clGray;
  end;
end;
end;
  Mit Zitat antworten Zitat