temper_calibration changes

This commit is contained in:
Stoyan Zlatev 2023-09-19 09:26:14 +02:00
parent 1fb87b08d3
commit f5a38c2eff
5 changed files with 139 additions and 184 deletions

View File

@ -13,7 +13,7 @@
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
<IsWebBootstrapper>false</IsWebBootstrapper>
<PublishUrl>L:\TiloW\TempMeter\publish\</PublishUrl>
<PublishUrl>C:\Users\SZLATEV\Desktop\TempFlansh\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
@ -23,7 +23,7 @@
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>1</ApplicationRevision>
<ApplicationRevision>2</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<PublishWizardCompleted>true</PublishWizardCompleted>

View File

@ -779,24 +779,7 @@
{
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;
var start = this.automaticContentBox.Text.Length - length;
this.automaticContentBox.Select(start, length);
this.automaticContentBox.SelectionColor = color;
this.automaticContentBox.AppendText(Environment.NewLine);
}));
@ -808,11 +791,11 @@
var pcbid = this.currentGenesis?.PcbId ?? "000000000";
var temperature = currentT.ToString().Substring(0, 2);
File.AppendAllText($"./messuremensts/{pcbid}_{temperature}.txt", $"{pcbid}\t{currentT:F2}\t{meterTOF:F16}\t{timestamp}{Environment.NewLine}");
// File.AppendAllLines("_temp_luts.txt", new[] { $"{pcbid}\t{temperature:F2}\t{meterTOF}\t{timestamp}" });
// TODO: LocalWebRequest.PostRequestAsync(
// $"http://10.49.40.25/MeterProcessState/api/TempFlange/AddLut?PcbId={pcbid}&RefTempC={temperature}&AvgTof={meterTOF}&dt={timestamp}");
// File.AppendAllLines("_temp_luts.txt", new[] { $"{pcbid}\t{temperature:F2}\t{meterTOF}\t{timestamp}" });
File.AppendAllText($"./messuremensts/{pcbid}.txt", $"{pcbid}\t{currentT:F2}\t{meterTOF:F16}\t{timestamp}{Environment.NewLine}");
}
protected override void OnClosed(EventArgs e)

View File

@ -14,7 +14,7 @@
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<TargetFrameworkProfile />
<IsWebBootstrapper>false</IsWebBootstrapper>
<PublishUrl>L:\Stoyan\temperature_calibration\</PublishUrl>
<PublishUrl>C:\Users\SZLATEV\Desktop\GenesisToolBox\</PublishUrl>
<Install>false</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
@ -24,7 +24,7 @@
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>3</ApplicationRevision>
<ApplicationRevision>5</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<PublishWizardCompleted>true</PublishWizardCompleted>

View File

@ -28,42 +28,10 @@
public class RefTempRange
{
public Double Min { get; set; }
public Double Max { get; set; }
}
public class LutTemp
{
public int PcbId { get; set; }
public int FromTempC { get; set; }
public int ToTempC { get; set; }
public double? AvgRefTempC { get; set; }
public ICollection<double> ListOfRecordedTofs { get; set; } = new List<double>();
public double? AvgTofs { get; set; }
}
internal enum ProgrammState
{
Start,
Connected,
RecordRuning,
RecordStoped,
RecodCalculated,
}
internal struct Messurement
{
public double T { get; set; }
public double TOF { get; set; }
public DateTime DTS { get; set; }
}
class TemperatureSource : IDisposable
{
private readonly NamedPipeClientStream pipeStream;
@ -127,6 +95,7 @@
private readonly Timer timer;
private readonly Func<double> sourceTOF;
private readonly TemperatureSource temperature;
private readonly string messurementsLog;
private ICollection<double> timesOfFliights;
private ICollection<double> temperatures;
@ -139,6 +108,7 @@
public AutomaticTemperatureCalibration(Func<double> sourceTOF)
{
this.sourceTOF = sourceTOF;
this.messurementsLog = $"_{nameof(this.messurementsLog)}.txt";
this.temperature = new TemperatureSource();
this.timesOfFliights = new List<double>();
this.temperatures = new List<double>();
@ -149,15 +119,6 @@
public event Action<string> ErrorMessage;
public event Action<string> WarningMessage;
public event Action<double, double, DateTime> TemperatureMesured;
private void Messure(object sender, ElapsedEventArgs args)
{
var timestamp = args.SignalTime;
var currentTOF = this.sourceTOF?.Invoke() ?? default(double);
_ = this.temperature.TryGetTemperature(out var currentT);
this.TemperatureMesured?.Invoke(currentT, currentTOF, timestamp);
}
public void StartMessuring()
{
@ -165,19 +126,21 @@
Appsettings.Refresh();
this.waiting = true;
this.temperatureChecks = 0;
this.timer.Interval = Appsettings.MessurementStep;
// this.timer.Elapsed += this.CheckTemperature;
this.timer.Elapsed += this.Messure;
this.timer.Interval = Appsettings.TemperatureCheckInMs;
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\tPrevious\tCurrent\tDifference");
this.waiting = true;
this.temperatureChecks = 0;
File.AppendAllText(this.messurementsLog, $"[{DateTime.Now}]\tTemperature messurements started{Environment.NewLine}");
this.InfoMessage?.Invoke(string.Empty);
this.InfoMessage?.Invoke($"\t Nr\tPrevious\tCurrent\tDifference");
}
public void StopMessuring()
@ -186,143 +149,152 @@
this.timer?.Stop();
this.timer?.Dispose();
this.temperature?.Dispose();
File.AppendAllText(this.messurementsLog, $"[{DateTime.Now}]\tTemperature messurements stopped{Environment.NewLine}");
}
//private void CheckTemperature(object sender, ElapsedEventArgs args)
//{
// this.temperatureChecks++;
private void CheckTemperature(object sender, ElapsedEventArgs args)
{
if (this.temperature.TryGetTemperature(out var currentT))
{
var differenceT = Math.Abs(this.previousT - currentT);
// if (this.temperature.TryGetTemperature(out var currentT))
// {
// var differenceT = Math.Abs(this.previousT - currentT);
if (this.waiting)
{
// this.InfoMessage?.Invoke($"\t{this.temperatureChecks,3}\t{this.previousT,8:F2}\t{currentT,7:F2}\t{differenceT,10:F2}");
File.AppendAllText(this.messurementsLog, $"[{DateTime.Now}]\t{this.temperatureChecks}\t{currentT:0.00}°C\t{this.previousT:0.00}°C\t{differenceT:0.00}°C{Environment.NewLine}");
// if (this.waiting)
// {
// if (differenceT >= Appsettings.TemperatureCheckInC)
// {
// this.waiting = false;
// this.previousT = currentT;
// }
if (differenceT >= Appsettings.TemperatureCheckInC)
{
this.waiting = false;
this.previousT = currentT;
this.temperatureChecks++;
}
else
{
this.temperatureChecks = 0;
}
}
else
{
if (differenceT <= Appsettings.TemperatureCheckInC)
{
this.temperatureChecks++;
// this.temperatureChecks = 0;
// }
// else
// {
// if (differenceT <= Appsettings.TemperatureCheckInC)
// {
// if (this.temperatureChecks >= Appsettings.TemperatureChecksCount)
// {
// this.timer.Stop();
if (this.temperatureChecks >= Appsettings.TemperatureChecksCount)
{
this.previousT = currentT;
// this.waiting = true;
// this.messurementsN = 0;
// this.messurementsCount = Appsettings.MessurementDauerInMs / Appsettings.MessurementStep;
this.timer.Stop();
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.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.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(string.Empty);
this.InfoMessage?.Invoke($"\t Nr\tTimestamp\t TOF\tTemperature");
}
}
else
{
this.waiting = true;
}
// this.InfoMessage?.Invoke($"\t 0\t{this.previousT,8:F2}\t.......\t..........");
// }
//}
File.AppendAllText(this.messurementsLog, $"[{DateTime.Now}]\t{this.temperatureChecks}\t{currentT:0.00}°C\t{this.previousT:0.00}°C\t{differenceT:0.00}°C{Environment.NewLine}");
}
}
else
{
this.temperatureChecks = 0;
//private void Messure(object sender, ElapsedEventArgs args)
//{
// if (!this.temperature.TryGetTemperature(out var currentT))
// {
// this.WarningMessage?.Invoke("\t ... temperature could not be read.");
// this.StartMessuring();
this.InfoMessage?.Invoke($"\t 0\t{this.previousT,8:F2}\t.......\t..........");
File.AppendAllText(this.messurementsLog, $"[{DateTime.Now}]\tInvalid temperature messured{Environment.NewLine}");
}
}
// return;
// }
private void Messure(object sender, ElapsedEventArgs args)
{
if (!this.temperature.TryGetTemperature(out var currentT))
{
this.WarningMessage?.Invoke("\t ... temperature could not be read.");
this.StartMessuring();
// var differenceT = Math.Abs(this.previousT - currentT);
return;
}
var differenceT = Math.Abs(this.previousT - currentT);
var currentTOF = this.sourceTOF?.Invoke() ?? 0;
// if (differenceT > Appsettings.MessurementToleranceInC)
// {
// if (this.messurementsN >= this.messurementsCount / 2)
// {
// this.NotifyTemperatureMessured(args.SignalTime);
// this.InfoMessage?.Invoke("\t ... messurement saved, start looking new temperature change!");
// }
// else
// {
// this.ErrorMessage?.Invoke("\t ... not enough messurements!");
// }
File.AppendAllText(this.messurementsLog, $"[{DateTime.Now}]\t{this.messurementsN}\t{currentT:0.00}\t{this.previousT:0.00}\t{differenceT:0.00}\t{currentTOF:0.0000000000}{Environment.NewLine}");
// this.ErrorMessage?.Invoke($"\t ... temperature difference '{differenceT:F2}' is not in the tolerance span!");
// this.StartMessuring();
if (differenceT > Appsettings.MessurementToleranceInC)
{
if (this.messurementsN >= this.messurementsCount / 2)
{
this.NotifyTemperatureMessured(args.SignalTime);
this.InfoMessage?.Invoke("\t ... messurement saved, start looking new temperature change!");
}
else
{
this.ErrorMessage?.Invoke("\t ... not enough messurements!");
}
// return;
// }
this.ErrorMessage?.Invoke($"\t ... temperature difference '{differenceT:F2}' is not in the tolerance span!");
this.StartMessuring();
// var currentTOF = this.sourceTOF?.Invoke() ?? 0;
// var minTOF = currentTOF;
// var maxTOF = currentTOF;
return;
}
var minTOF = currentTOF;
var maxTOF = currentTOF;
// if (this.timesOfFliights.Any())
// {
// var tolerance = Appsettings.MessurementTOFTolerance / 100;
// minTOF = this.timesOfFliights.Min() * (1.00 - tolerance);
// maxTOF = this.timesOfFliights.Max() * (1.00 + tolerance);
// }
if (this.timesOfFliights.Any())
{
var tolerance = Appsettings.MessurementTOFTolerance / 100;
minTOF = this.timesOfFliights.Min() * (1.00 - tolerance);
maxTOF = this.timesOfFliights.Max() * (1.00 + tolerance);
}
// if (currentTOF < minTOF || currentTOF > maxTOF)
// {
// if (this.messurementsN >= this.messurementsCount / 2)
// {
// this.NotifyTemperatureMessured(args.SignalTime);
// this.WarningMessage?.Invoke("\t ... messurement saved, start looking new temperature change!");
// }
// else
// {
// this.ErrorMessage?.Invoke("\t ... not enough messurements!");
// }
if (currentTOF < minTOF || currentTOF > maxTOF)
{
if (this.messurementsN >= this.messurementsCount / 2)
{
this.NotifyTemperatureMessured(args.SignalTime);
this.WarningMessage?.Invoke("\t ... messurement saved, start looking new temperature change!");
}
else
{
this.ErrorMessage?.Invoke("\t ... not enough messurements!");
}
// this.ErrorMessage?.Invoke($"\t ... TOF is not in a tolerance span - {minTOF} <= {currentTOF} <= {maxTOF}!");
// this.StartMessuring();
this.ErrorMessage?.Invoke($"\t ... TOF is not in a tolerance span - {minTOF} <= {currentTOF} <= {maxTOF}!");
this.StartMessuring();
// return;
// }
return;
}
// this.temperatures.Add(currentT);
// this.timesOfFliights.Add(currentTOF);
this.temperatures.Add(currentT);
this.timesOfFliights.Add(currentTOF);
// this.InfoMessage?.Invoke($"\t{this.messurementsN,4}\t {args.SignalTime,8:hh:mm:ss}\t{currentTOF,17:F15}\t {currentT,5:F2}");
this.InfoMessage?.Invoke($"\t{this.messurementsN,4}\t {args.SignalTime,8:hh:mm:ss}\t{currentTOF,17:F15}\t {currentT,5:F2}");
// if (this.messurementsN >= this.messurementsCount)
// {
// this.NotifyTemperatureMessured(args.SignalTime);
// this.InfoMessage?.Invoke("\t ... messurement done!");
// this.StartMessuring();
if (this.messurementsN >= this.messurementsCount)
{
this.NotifyTemperatureMessured(args.SignalTime);
this.InfoMessage?.Invoke("\t ... messurement done!");
this.StartMessuring();
// return;
// }
return;
}
// this.messurementsN++;
//}
this.messurementsN++;
}
private void NotifyTemperatureMessured(DateTime timestamp)
{