It's a OT software for produce beer in my home, I have a timer that start 20 seconds and call this procedure, In my opinion the proble is some nil pointer...
procedure TFrameBrew.RefreshTemperature;
var
lfMashTemperatue: double;
lfSpargeTemperature: double;
begin
try
if Assigned(poOptional1Probe) then
lblOptional1.Caption := format('%.1f°', [poOptional1Probe.Temperature]);
if Assigned(poOptional2Probe) then
lblOptional2.Caption := format('%.1f°', [poOptional2Probe.Temperature]);
if piStep < poStep.Count then
begin
poMashProbe.Target := PStep(poStep.Items[piStep])^.Temperature;
end
else
LogError('piStep = ' + IntToStr(piStep));
//Some time the Dallas probe return zero value...
//if lfMashTemperatue > 0 then
//begin
//Sono in Mash
if (pbMash = True) and (piStep < poStep.Count) then
begin
lfMashTemperatue := poMashProbe.Temperature;
if Assigned(poSpargeProbe) then
begin
poSpargeProbe.Target := pfSpargeTemperature;
if not poIniFile.Simulation then
begin
lfSpargeTemperature := poSpargeProbe.Temperature;
end;
end;
if not Assigned(poStep.Items[piStep]) then
begin
LogError('Error in Refresh Temperature poStep not assigned piStep = ' +
IntToStr(piStep));
//Exit;
end;
poMashProbe.Target := PStep(poStep.Items[piStep])^.Temperature;
if poIniFile.Enviroment <> 2 then
begin
if lfMashTemperatue > PStep(poStep.Items[piStep])^.TempMax then
begin
try
PStep(poStep.Items[piStep])^.TempMax := lfMashTemperatue;
except
on e: Exception do
LogError('error in Refresh Temperature poStep = nil ' + e.Message);
end;
end;
lblActualMash.Caption := format('%.1f°', [lfMashTemperatue]);
if assigned(poSpargeGPIO) then
lblActualSparge.Caption := format('%.1f°', [lfSpargeTemperature]);
if (lfMashTemperatue < PStep(poStep.Items[piStep])^.Temperature) then
begin
try
if (lfMashTemperatue >= PStep(poStep.Items[piStep])^.Temperature -
DeltaTemperaturePID) then
begin
try
PowerOffActor(Sparge);
lblFinishBoil.Visible := True;
lblFinishBoil.Caption := 'PID algorithm ON';
PID(lfMashTemperatue, PStep(poStep.Items[piStep])^.Temperature);
except
on e: exception do
LogError('error in Refresh Temperature PID start ' + e.Message);
end;
end
else
PowerOnResistence(Mash);
except
on e: Exception do
LogError(
'Errore in RefreshTemperature lfMashTemperatue < PStep(poStep.Items[piStep])^.Temperature '
+ e.Message);
end;
end;
if lfMashTemperatue >= pfMashSetTemperature then
begin
try
PowerOffActor(Sparge);
lblFinishBoil.Visible := False;
if poIniFile.SpargeProbeValue <> '' then
begin
if lfSpargeTemperature < pfSpargeTemperature then
begin
if poIniFile.Simulation then
begin
lfSpargeTemperature := poSpargeProbe.Temperature;
lblActualSparge.Caption := format('%.1f°', [lfSpargeTemperature]);
end;
PowerOnResistence(Sparge);
end;
end;
if PStep(poStep.Items[piStep])^.FirstTime = False then
begin
PStep(poStep.Items[piStep])^.FirstTime := True;
tmrMash.Enabled := True;
end;
except
on e: Exception do
LogError('Error in Refresh temperature if lfMash >= pfMashTemperature ' +
e.Message);
end;
end;
if (Assigned(poSpargeGPIO)) and (lfSpargeTemperature >
pfSpargeTemperature) then
begin
try
PowerOffActor(Sparge);
except
on e: Exception do
LogError('Error in Refresh temperature if lfSpargeTemperature > pfSpargeTemperature '
+ e.Message);
end;
end;
end
else
//HERMS
begin
//Varifica Max Temperatura
CheckMash;
//pfSpargeActualTemperature := poSpargeProbe.Temperature;
if piStep < poStep.Count then
begin
lfSpargeTemperature := poSpargeProbe.Temperature;
lblActualMash.Caption := format('%.1f°', [lfMashTemperatue]);
lblActualSparge.Caption := format('%.1f°', [lfSpargeTemperature]);
end;
if (lfMashTemperatue < PStep(poStep.Items[piStep])^.Temperature) then
begin
if (lfMashTemperatue >= PStep(poStep.Items[piStep])^.Temperature -
DeltaTemperaturePID) then
begin
lblFinishBoil.Visible := True;
lblFinishBoil.Caption := 'PID algorithm ON';
PID(lfMashTemperatue, PStep(poStep.Items[piStep])^.Temperature);
lblFinishBoil.Visible := True;
end
else
begin
//Power ON HLT Resistence
PowerOnResistence(Sparge);
//In HERMS Kind this object is pumpMash
poMashPumpGPIO.WritePIN := ON;
end;
end;
if lfMashTemperatue >= pfMashSetTemperature then
begin
PowerOffActor(Sparge);
//In HERMS Kind this object is pumpMash
poMashPumpGPIO.WritePIN := OFF;
lblFinishBoil.Visible := False;
if PStep(poStep.Items[piStep])^.FirstTime = False then
begin
PStep(poStep.Items[piStep])^.FirstTime := True;
tmrMash.Enabled := True;
end;
end;
end;
end
else
begin
//Only after click
if pbBoil = True then
begin
//sono in boil o in rampa di risalita
poBoilProbe.Target := piBoilTemperature;
pfActualBoilTemperature := poBoilProbe.Temperature;
//This condition start the boil timer
if (pfActualBoilTemperature >= piBoilTemperature) and
(pbBoilFlag = False) and (piStep = poStep.Count) then
begin
if piStepTime = 0 then
piStepTime := edtBoilTime.Value;
pbBoilFlag := True;
tmrBoil.Enabled := True;
if poHop.Count > 0 then
begin
tmrHop.Interval :=
((piBoilTime - PHop(poHop.Items[0])^.Time)) * 60 * 1000;
//logError('timer hop ' + IntToStr(tmrHop.Interval) + ' Time init : ' + INtToStr(PHop(poHop.Items[0])^.Time));
if tmrHop.Interval = 0 then
begin
lblGettata.Caption := Format('#%d Throw Hop', [piThrowHop + 1]);
pnlgettataHop.Visible := True;
TframeMashStep(poHopStep.Items[piThrowHop]).shpStatus.Brush.Color :=
clGreen;
Inc(piThrowHop);
tmrHop.Interval :=
(piBoilTime - PHop(poHop.Items[piThrowHop])^.Time) * 60 * 1000;
//logError('timer hop ' + IntToStr(tmrHop.Interval));
end;
tmrHop.Enabled := True;
end;
lblFinishBoil.Caption :=
'Finish Boil Time: ' + FormatDateTime('hh:nn:ss',
IncMinute(now, tmrBoil.Interval div 1000 div 60));
lblFinishBoil.Visible := True;
poReport.Add(Format('<br> Boil Start %s', [TimeToStr(Now)]));
poReport.SaveToFile('Report_' + cmbRecipe.Text + '.html');
end;
pfActualBoilTemperature := poBoilProbe.Temperature;
lblActualBoil.Caption := format('%.1f°', [pfActualBoilTemperature]);
if (poIniFile.Enviroment = 1) or (poIniFile.Enviroment = 3) then
begin
lblActualMash.Caption := lblActualBoil.Caption;
end;
end;
end;
Application.ProcessMessages;
//end;
except
on e: Exception do
LogError(Format('Error in RefreshTemperature pistep=%d, ActualMash=%1.f, %s', [piStep, lfMashTemperatue, e.Message]));
end;
end;