temperature calibration
This commit is contained in:
@@ -646,8 +646,6 @@
|
||||
this.btnAddLut.Enabled = false;
|
||||
this.nudRef.Visible = false;
|
||||
this.btnRefreshLut.Enabled = false;
|
||||
//this.startAutomaticBtn.Enabled = false;
|
||||
//this.stopAutomaticBtn.Enabled = false;
|
||||
break;
|
||||
case ProgrammState.Connected:
|
||||
this.btnStartRecord.Enabled = true;
|
||||
@@ -655,8 +653,6 @@
|
||||
this.btnAddLut.Enabled = false;
|
||||
this.nudRef.Visible = false;
|
||||
this.btnRefreshLut.Enabled = true;
|
||||
//this.startAutomaticBtn.Enabled = true;
|
||||
//this.stopAutomaticBtn.Enabled = false;
|
||||
break;
|
||||
case ProgrammState.RecordRuning:
|
||||
this.btnStartRecord.Enabled = false;
|
||||
@@ -664,8 +660,6 @@
|
||||
this.btnAddLut.Enabled = false;
|
||||
this.nudRef.Visible = false;
|
||||
this.btnRefreshLut.Enabled = true;
|
||||
//this.startAutomaticBtn.Enabled = false;
|
||||
//this.stopAutomaticBtn.Enabled = true;
|
||||
break;
|
||||
case ProgrammState.RecordStoped:
|
||||
this.btnStartRecord.Enabled = true;
|
||||
@@ -673,8 +667,6 @@
|
||||
this.btnAddLut.Enabled = true;
|
||||
this.nudRef.Visible = true;
|
||||
this.btnRefreshLut.Enabled = true;
|
||||
//this.startAutomaticBtn.Enabled = true;
|
||||
//this.stopAutomaticBtn.Enabled = false;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -718,12 +710,14 @@
|
||||
{
|
||||
if (this.currentGenesis is null)
|
||||
{
|
||||
MessageBox.Show(this, "Water meter not connected!", "Start aborted", MessageBoxButtons.OK);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
this.automatic = true;
|
||||
this.start = DateTimeOffset.Now;
|
||||
this.messurementsFile = $"messurements.txt";
|
||||
this.messurementsFile = $"_messurements.txt";
|
||||
|
||||
this.currentGenesis.StartRecordData();
|
||||
this.currentGenesis.WriteRegister(Register.Genesisflow.SampleRate, (byte)16, checkRegister: true);
|
||||
@@ -756,10 +750,12 @@
|
||||
|
||||
this.MergeToAutoFile();
|
||||
this.automaticCalibration.StopMessuring();
|
||||
|
||||
this.currentGenesis.WriteRegister(Register.Genesisflow.SampleRate, (byte)0, checkRegister: true);
|
||||
this.currentGenesis.WriteRegister("GENESISFLOW_MaxValidDeltaToF", 4294967295, checkRegister: true);
|
||||
this.currentGenesis.WriteRegister("GENESISFLOW_MaxValidToF", 4294967295, checkRegister: true);
|
||||
this.currentGenesis.WriteRegister("GENESISFLOW_MinValidToF", (uint)0, checkRegister: true);
|
||||
|
||||
this.SetEnabled(ProgrammState.RecordStoped);
|
||||
|
||||
this.startAutomaticBtn.Enabled = true;
|
||||
@@ -783,6 +779,15 @@
|
||||
{
|
||||
this.automaticContentBox.BeginInvoke(new Action(() =>
|
||||
{
|
||||
if (this.automaticContentBox.Lines.Length > 50)
|
||||
{
|
||||
this.automaticContentBox.Lines = this.automaticContentBox
|
||||
.Lines
|
||||
.Skip(1)
|
||||
.Take(50)
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
this.automaticContentBox.AppendText(message);
|
||||
|
||||
var length = message.Length;
|
||||
@@ -801,12 +806,37 @@
|
||||
private void SaveMessurement(double meterTOF, double temperature, DateTime timestamp)
|
||||
{
|
||||
var pcbid = this.currentGenesis?.PcbId ?? "000000000";
|
||||
|
||||
File.AppendAllLines("_temp_luts.txt", new[] { $"{pcbid}\t{temperature:F2}\t{meterTOF}\t{timestamp}" });
|
||||
|
||||
File.AppendAllLines(this.messurementsFile, new[] { $"{pcbid}\t{temperature}\t{meterTOF}\t{timestamp}" });
|
||||
// Note: the MeterProcessState should be also updated.
|
||||
// To the endpoint was added new property: dt <=> Timestamp -> this is the timestamp provided from the automatic temperature calibration.
|
||||
File.AppendAllLines("temp_luts.txt", new[] { $"{pcbid}\t{temperature}\t{meterTOF}\t{timestamp}" });
|
||||
// LocalWebRequest.PostRequestAsync($"http://10.49.40.25/MeterProcessState/api/TempFlange/AddLut?PcbId={pcbid}&RefTempC={temperature}&AvgTof={meterTOF}&dt={timestamp}");
|
||||
// TODO: LocalWebRequest.PostRequestAsync(
|
||||
// $"http://10.49.40.25/MeterProcessState/api/TempFlange/AddLut?PcbId={pcbid}&RefTempC={temperature}&AvgTof={meterTOF}&dt={timestamp}");
|
||||
}
|
||||
|
||||
protected override void OnClosed(EventArgs e)
|
||||
{
|
||||
base.OnClosed(e);
|
||||
|
||||
this.automatic = false;
|
||||
|
||||
if (this.automaticCalibration != null)
|
||||
{
|
||||
this.automaticCalibration.TemperatureMesured -= this.SaveMessurement;
|
||||
this.automaticCalibration.InfoMessage -= message => this.AddMessage(message, Color.Black);
|
||||
this.automaticCalibration.ErrorMessage -= message => this.AddMessage(message, Color.Red);
|
||||
this.automaticCalibration.WarningMessage -= message => this.AddMessage(message, Color.Orange);
|
||||
|
||||
this.automaticCalibration.StopMessuring();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
this.MergeToAutoFile();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// TODO:
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -761,6 +761,9 @@
|
||||
<Install>true</Install>
|
||||
</BootstrapperPackage>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="App_Data\" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
|
||||
@@ -14,13 +14,13 @@
|
||||
|
||||
private class DefaultValues
|
||||
{
|
||||
public const int TemperatureCheckInMs = 5_00;
|
||||
public const int TemperatureCheckInMs = 300_000; // 5 minuten
|
||||
public const double TemperatureCheckInC = 1.00;
|
||||
public const int TemperatureChecksCount = 5;
|
||||
public const int MessurementDauerInMs = 6_000;
|
||||
public const int MessurementStep = 5_00;
|
||||
public const double MessurementToleranceInC = 0.05;
|
||||
public const double MessurementTOFTolerance = 30.00;
|
||||
public const int TemperatureChecksCount = 2;
|
||||
public const int MessurementDauerInMs = 600_000;
|
||||
public const int MessurementStep = 1_000;
|
||||
public const double MessurementToleranceInC = 0.1;
|
||||
public const double MessurementTOFTolerance = 30;
|
||||
}
|
||||
|
||||
public class AppsettingsModel : INotifyPropertyChanged
|
||||
@@ -127,7 +127,7 @@
|
||||
}
|
||||
|
||||
public static AppsettingsModel Model { get; } = new AppsettingsModel();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="AppsettingsModel.TemperatureCheckInMs"/>
|
||||
/// </summary>
|
||||
|
||||
@@ -78,7 +78,7 @@
|
||||
this.pipeStream = new NamedPipeClientStream(".", "TempPipe", PipeDirection.In);
|
||||
this.pipeStream.Connect(3000);
|
||||
}
|
||||
catch (Exception e)
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@
|
||||
{
|
||||
var value = $"{this.pipeReader.ReadLine()}";
|
||||
|
||||
if (double.TryParse(value, Any, this.de, out temperature) || double.TryParse(value, Any, this.us, out temperature))
|
||||
if (double.TryParse(value, Any, this.us, out temperature) || double.TryParse(value, Any, this.de, out temperature))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -181,48 +181,61 @@
|
||||
|
||||
private void CheckTemperature(object sender, ElapsedEventArgs args)
|
||||
{
|
||||
this.temperatureChecks++;
|
||||
|
||||
if (this.temperature.TryGetTemperature(out var currentT))
|
||||
{
|
||||
var differenceT = Math.Abs(this.previousT - currentT);
|
||||
|
||||
this.InfoMessage?.Invoke($"\t{this.temperatureChecks,3}\t{this.previousT,8:F2}\t{currentT,7:F2}\t{differenceT,10:F2}");
|
||||
|
||||
if (this.waiting && differenceT >= Appsettings.TemperatureCheckInC)
|
||||
if (this.waiting)
|
||||
{
|
||||
this.waiting = false;
|
||||
this.previousT = currentT;
|
||||
}
|
||||
|
||||
if (!this.waiting && differenceT <= Appsettings.TemperatureCheckInC)
|
||||
{
|
||||
if (this.temperatureChecks >= Appsettings.TemperatureChecksCount)
|
||||
if (differenceT >= Appsettings.TemperatureCheckInC)
|
||||
{
|
||||
this.timer.Stop();
|
||||
|
||||
this.waiting = true;
|
||||
this.messurementsN = 0;
|
||||
this.messurementsCount = Appsettings.MessurementDauerInMs / Appsettings.MessurementStep;
|
||||
|
||||
this.timer.Interval = Appsettings.MessurementStep;
|
||||
this.timer.Elapsed -= this.CheckTemperature;
|
||||
this.timer.Elapsed += this.Messure;
|
||||
this.timer.AutoReset = true;
|
||||
this.timer.Enabled = true;
|
||||
|
||||
this.timer.Start();
|
||||
|
||||
this.InfoMessage?.Invoke(string.Empty);
|
||||
this.InfoMessage?.Invoke($"\t Nr\tTimestamp\t TOF\tTemperature");
|
||||
this.waiting = false;
|
||||
this.previousT = currentT;
|
||||
}
|
||||
|
||||
this.temperatureChecks++;
|
||||
this.temperatureChecks = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (differenceT <= Appsettings.TemperatureCheckInC)
|
||||
{
|
||||
if (this.temperatureChecks >= Appsettings.TemperatureChecksCount)
|
||||
{
|
||||
this.timer.Stop();
|
||||
|
||||
this.InfoMessage?.Invoke($"\t{this.temperatureChecks,3}\t{this.previousT,8:F2}\t{currentT,7:F2}\t{differenceT,10:F2}");
|
||||
this.waiting = true;
|
||||
this.messurementsN = 0;
|
||||
this.messurementsCount = Appsettings.MessurementDauerInMs / Appsettings.MessurementStep;
|
||||
|
||||
this.timer.Interval = Appsettings.MessurementStep;
|
||||
this.timer.Elapsed -= this.CheckTemperature;
|
||||
this.timer.Elapsed += this.Messure;
|
||||
this.timer.AutoReset = true;
|
||||
this.timer.Enabled = true;
|
||||
|
||||
this.timer.Start();
|
||||
|
||||
this.InfoMessage?.Invoke(string.Empty);
|
||||
this.InfoMessage?.Invoke($"\t Nr\tTimestamp\t TOF\tTemperature");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.waiting = true;
|
||||
this.previousT = currentT;
|
||||
this.temperatureChecks = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.temperatureChecks = 0;
|
||||
|
||||
this.InfoMessage?.Invoke($"\t 1\t{this.previousT,8:F2}\t.......\t..........");
|
||||
this.InfoMessage?.Invoke($"\t 0\t{this.previousT,8:F2}\t.......\t..........");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user