omni before testing,

- recalculating correction factors and accuracies
- factory unseal
This commit is contained in:
Stoyan Zlatev
2024-02-05 14:48:35 +01:00
parent 89a9f1649d
commit 02943ebcbc
34 changed files with 1384 additions and 511 deletions
@@ -9,6 +9,7 @@
this.Add(new ItemsGridHeaderVM());
this.Add(new ItemsGridHeaderVM());
this.Add(new ItemsGridHeaderVM());
this.Add(new ItemsGridHeaderVM());
var auftrag = OmniContext.Current.Auftrag;
@@ -7,8 +7,9 @@
public DefaultsRowVM()
{
this.Add(new ItemsGridHeaderVM());
this.Add(new ItemsGridHeaderVM { Value = "PP:" });
this.Add(new ItemsGridHeaderVM());
this.Add(new ItemsGridHeaderVM());
this.Add(new ItemsGridHeaderVM { Value = "0.0" });
var auftrag = OmniContext.Current.Auftrag;
@@ -19,7 +20,7 @@
this.Add(new ItemsGridHeaderVM { Value = $"{pp.MinAccuracy}-{pp.MaxAccuracy}" });
}
this.Add(new ItemsGridHeaderVM { Value = "3.3" });
this.Add(new ItemsGridHeaderVM { Value = "0.0" });
}
}
}
@@ -9,6 +9,7 @@
this.Add(new ItemsGridHeaderVM { Width = ItemsGridHeaderVM.Auto });
this.Add(new ItemsGridHeaderVM { Value = "MeterNr", Width = ItemsGridHeaderVM.Star });
this.Add(new ItemsGridHeaderVM { Value = "SerialNr", Width = ItemsGridHeaderVM.Star });
this.Add(new ItemsGridHeaderVM { Value = "Crr.F. %", Width = ItemsGridHeaderVM.Auto });
var auftrag = OmniContext.Current.Auftrag;
@@ -22,7 +23,7 @@
});
}
this.Add(new ItemsGridHeaderVM { Value = "Crr. %", Width = ItemsGridHeaderVM.Star });
this.Add(new ItemsGridHeaderVM { Value = "Crr.F. %", Width = ItemsGridHeaderVM.Star });
}
}
}
@@ -10,8 +10,6 @@
protected ItemsGridVM() : base()
{
this.rows = new List<ItemsGridRowVM>();
this.InitializeItemsGridRows();
}
public IEnumerator<ItemsGridRowVM> GetEnumerator()
@@ -48,7 +46,5 @@
{
this.rows.Insert(index, item);
}
protected abstract void InitializeItemsGridRows();
}
}
@@ -2,8 +2,6 @@
{
using InspectionUI.Models;
using OmniPlus;
using System;
using System.Windows.Input;
@@ -13,7 +11,6 @@
{
this.IsReloadEnabled = true;
this.Reload = new Command(this.ReloadCommand);
this.CheckInspection = new Command(this.CheckInspectionCommand);
this.StartInspection = new Command(this.StartInspectionCommand);
this.CancelInspection = new Command(this.CancelInspectionCommand);
}
@@ -39,6 +36,13 @@
set => this.Set(() => this.suchnr = value);
}
private bool keepCorrection;
public bool KeepCorrection
{
get => this.keepCorrection;
set => this.Set(() => this.keepCorrection = value);
}
private bool reloadEnabled;
public bool IsReloadEnabled
{
@@ -48,22 +52,12 @@
public ICommand Reload { get; }
private bool checkInspectionEnabled;
public bool IsCheckInspectionEnabled
{
get => this.checkInspectionEnabled;
private set => this.Set(() => this.checkInspectionEnabled = value);
}
public ICommand CheckInspection { get; }
private bool startInspectionEnabled;
public bool IsStartInspectionEnabled
{
get => this.startInspectionEnabled;
private set => this.Set(() => this.startInspectionEnabled = value);
}
public ICommand StartInspection { get; }
private bool cancelInspectionEnabled;
@@ -94,20 +88,15 @@
this.EnableButtons(false);
this.Errors = default(string);
var omniContext = ServiceProvider.GetService<OmniContext>();
this.MetersPool = ServiceProvider.GetService<MetersPoolVM>();
if (!string.IsNullOrWhiteSpace(this.SuchNr))
{
ServiceProvider
.GetService<OmniContext>()
.LoadAuftrag(this.SuchNr);
this.MetersPool.LoadAuftrag(this.SuchNr);
}
else if (this.size >= 0 && !string.IsNullOrWhiteSpace(this.type))
{
ServiceProvider
.GetService<OmniContext>()
.LoadAuftrag((byte)this.size, this.type);
this.MetersPool.LoadAuftrag((byte)this.size, this.type);
}
else
{
@@ -119,7 +108,6 @@
this.StartNewTask(() =>
{
this.Errors = "Connecting meters ...";
this.MetersPool = ServiceProvider.GetService<MetersPoolVM>();
this.MetersPool.LoadMeters();
})
.ContinueWith(_ =>
@@ -134,22 +122,13 @@
}
}
private void CheckInspectionCommand()
{
this.StartNewTask(() =>
{
this.EnableButtons(false);
this.MetersPool.RunCheckInspection();
this.EnableButtons(true);
});
}
private void StartInspectionCommand()
{
this.StartNewTask(() =>
{
this.EnableButtons(false);
this.MetersPool.RunInspection();
this.MetersPool.RunInspection(this.KeepCorrection);
this.IsCancelInspectionEnabled = false;
this.IsReloadEnabled = true;
});
}
@@ -160,14 +139,14 @@
{
this.EnableButtons(false);
this.MetersPool.CancelInspection();
this.EnableButtons(true);
this.IsCancelInspectionEnabled = false;
this.IsReloadEnabled = true;
});
}
private void EnableButtons(bool enabled)
{
this.IsReloadEnabled = enabled;
this.IsCheckInspectionEnabled = enabled;
this.IsStartInspectionEnabled = enabled;
this.IsCancelInspectionEnabled = !enabled;
}
@@ -1,6 +1,5 @@
namespace InspectionUI.ViewModels
{
using InspectionUI.Models;
using OmniPlus;
using System;
@@ -22,6 +21,7 @@
this.Add(new ItemsGridHeaderVM { Value = $"{this.meter.SlotNr, 2}." });
this.Add(new ItemsGridCellVM());
this.Add(new ItemsGridCellVM());
this.Add(new ItemsGridCellVM());
var auftrag = OmniContext.Current.Auftrag;
@@ -66,31 +66,31 @@
base.Dispose();
}
public Task SaveMeterStateAsync()
public Task SaveMeterStateAsync(CancellationToken cancellationToken)
{
return this.StartNewTask(this.meter.SaveMeterState);
return this.StartNewTask(this.meter.SaveMeterState, cancellationToken);
}
public Task LoadTestRunAsync()
public Task LoadTestRunAsync(CancellationToken cancellationToken)
{
return this.StartNewTask(this.meter.LoadTestRun);
return this.StartNewTask(this.meter.LoadTestRun, cancellationToken);
}
public Task InitializeInspectionAsync(bool preserveState = false)
public Task InitializeInspectionAsync(bool keepCorrection, CancellationToken cancellationToken)
{
this.uinr = 0;
void InitializeInspection()
{
this.meter.InitializeForInspection(preserveState);
this.meter.InitializeForInspection(keepCorrection);
this.Set(this.meter.TestRun.CrrfBefore, "{0:0.0}", this.LastIndex);
this.Set(this.meter.TestRun.CrrfBefore, "{0:0.0}", 3);
}
return this.StartNewTask(InitializeInspection);
return this.StartNewTask(InitializeInspection, cancellationToken);
}
public Task StartCalibrationAsync(OmniPruefpunkt pp)
public Task StartCalibrationAsync(OmniPruefpunkt pp, CancellationToken cancellationToken)
{
this.uinr++;
@@ -98,28 +98,28 @@
{
this.meter.StartCalibration((ushort)pp.Rotations, (ushort)pp.Duration);
this.ShowRestTime(pp.Duration, this.uinr * 3);
this.ShowRestTime(pp.Duration, this.uinr * 3 + 1);
}
return this.StartNewTask(StartCalibration);
return this.StartNewTask(StartCalibration, cancellationToken);
}
public Task StopCalibrationAsync(OmniPruefpunkt pp, double refm3s)
public Task StopCalibrationAsync(OmniPruefpunkt pp, double refm3s, CancellationToken cancellationToken)
{
void StopCalibration()
{
var response = this.meter.StopCalibration(pp, refm3s);
var index = this.uinr * 3;
var index = this.uinr * 3 + 1;
this.Set(response.Item2, "{0}", index);
this.Set(response.Item1, "{0:0.0000000000}", index + 1);
this.Set(response.Item3, "{0:0.00}", index + 2);
}
return this.StartNewTask(StopCalibration);
return this.StartNewTask(StopCalibration, cancellationToken);
}
public Task FinishInspectionAsync()
public Task FinishInspectionAsync(CancellationToken cancellationToken)
{
void FinishInspection()
{
@@ -138,7 +138,7 @@
foreach (var testedPP in this.meter.TestRun.TestedPoints)
{
var index = this.uinr * 3 + 2;
var index = this.uinr * 3 + 1 + 2;
this.Set(testedPP.Acc, "{0:0.00}", index);
this.Set(x =>
@@ -153,7 +153,7 @@
}
}
return this.StartNewTask(FinishInspection);
return this.StartNewTask(FinishInspection, cancellationToken);
}
private void ShowRestTime(int duration, int index)
@@ -3,15 +3,17 @@
using InspectionUI.Models;
using OmniPlus;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
public class MetersPoolVM : ItemsGridVM
{
private readonly OmniContext omniContext;
private CancellationTokenSource cancellationTokenSource;
private ReferenceMeterVM referenceMeter;
public MetersPoolVM(OmniContext omniContext) : base()
@@ -21,7 +23,8 @@
public void CancelInspection()
{
this.referenceMeter.Stop();
this.cancellationTokenSource?.Cancel();
this.referenceMeter?.Stop();
}
public override void Dispose()
@@ -49,13 +52,11 @@
});
}
public void RunCheckInspection()
public void RunInspection(bool keepCorrection = false, bool addCorrection = false)
{
this.cancellationTokenSource = new CancellationTokenSource();
}
public void RunInspection()
{
var cancellationToken = this.cancellationTokenSource.Token;
var tasks = new List<Task>();
var meters = this
.Select(x => x is MeterVM m ? m : null)
@@ -64,21 +65,21 @@
foreach (var meterVM in meters)
{
tasks.Add(meterVM.LoadTestRunAsync());
tasks.Add(meterVM.LoadTestRunAsync(cancellationToken));
}
this.ContinueWhenAll(tasks);
foreach (var meterVM in meters)
{
tasks.Add(meterVM.SaveMeterStateAsync());
tasks.Add(meterVM.SaveMeterStateAsync(cancellationToken));
}
this.ContinueWhenAll(tasks);
foreach (var meterVM in meters)
{
tasks.Add(meterVM.InitializeInspectionAsync());
tasks.Add(meterVM.InitializeInspectionAsync(keepCorrection, cancellationToken));
}
this.ContinueWhenAll(tasks);
@@ -90,36 +91,75 @@
foreach (var pp in pruefpunkte)
{
if (cancellationToken.IsCancellationRequested)
{
break;
}
this.referenceMeter.Start(pp);
if (cancellationToken.IsCancellationRequested)
{
break;
}
foreach (var meterVM in meters)
{
tasks.Add(meterVM.StartCalibrationAsync(pp));
tasks.Add(meterVM.StartCalibrationAsync(pp, cancellationToken));
}
this.ContinueWhenAll(tasks);
if (cancellationToken.IsCancellationRequested)
{
break;
}
var refm3s = this.referenceMeter.GetFlow();
if (cancellationToken.IsCancellationRequested)
{
break;
}
foreach (var meterVM in meters)
{
tasks.Add(meterVM.StopCalibrationAsync(pp, refm3s));
tasks.Add(meterVM.StopCalibrationAsync(pp, refm3s, cancellationToken));
}
this.ContinueWhenAll(tasks);
if (cancellationToken.IsCancellationRequested)
{
break;
}
}
this.referenceMeter.Stop();
foreach (var meterVM in meters)
{
tasks.Add(meterVM.FinishInspectionAsync());
tasks.Add(meterVM.FinishInspectionAsync(cancellationToken));
}
this.ContinueWhenAll(tasks);
}
protected override void InitializeItemsGridRows()
internal void LoadAuftrag(byte size, string type)
{
this.omniContext.LoadAuftrag(size, type);
this.UpdateItemsGridHeaders();
}
internal void LoadAuftrag(string suchNr)
{
this.omniContext.LoadAuftrag(suchNr);
this.UpdateItemsGridHeaders();
}
private void UpdateItemsGridHeaders()
{
this.DispatcherInvoke(() =>
{
@@ -5,46 +5,34 @@
using InspectionUI.Models;
using OmniPlus;
using OmniPlus.Inspection;
using System;
using System.IO;
using System.Threading;
using System.Timers;
public class ReferenceMeterVM : ItemsGridRowVM
{
private readonly OmniContext omniContext;
private readonly ExchangeConnection signarR;
private readonly string outputFile;
private int ppnr = 0;
private int ppnr;
private bool cancel;
public ReferenceMeterVM() : base()
public ReferenceMeterVM(OmniContext omniContext, ExchangeConnection signarR) : base()
{
this.Add(new ItemsGridHeaderVM());
this.Add(new ItemsGridHeaderVM { Value = "RZ:" });
this.Add(new ItemsGridHeaderVM());
var auftrag = OmniContext.Current.Auftrag;
foreach (var _ in auftrag.Pruefpunkte)
{
this.Add(new ItemsGridHeaderVM());
this.Add(new ItemsGridHeaderVM());
this.Add(new ItemsGridHeaderVM());
}
this.Add(new ItemsGridHeaderVM());
this.signarR = new ExchangeConnection();
this.omniContext = omniContext;
this.signarR = signarR;
this.signarR.StateChanged += this.SignarR_StateChanged;
this.outputFile = Path.Combine(Appsettings.OutputDirectory, "signalr.txt");
this.signarR.Connect(Appsettings.HubURL);
this.ppnr = 1;
this.LoadHeaders();
}
internal void Start(OmniPruefpunkt pp)
{
this.ppnr += 3;
this.cancel = false;
this.StartFlow(pp);
this.StartRZ(pp);
@@ -53,7 +41,7 @@
private void StartFlow(OmniPruefpunkt pp)
{
var interval = 1000;
var timeout = 5;// 00;
var timeout = 500;
var volume = default(double);
var waitHandle = new ManualResetEventSlim();
var timer = new System.Timers.Timer
@@ -73,7 +61,7 @@
void TimerElapsed(object _, ElapsedEventArgs _1)
{
if (timeout < 0)
if (timeout < 0 || cancel)
{
timeout = 0;
@@ -107,7 +95,7 @@
private void StartRZ(OmniPruefpunkt pp)
{
var interval = 1000;
var timeout = 6;// 0;
var timeout = 60;
var seconds = default(double);
var waitHandle = new ManualResetEventSlim();
var timer = new System.Timers.Timer
@@ -127,7 +115,7 @@
void TimerElapsed(object _, ElapsedEventArgs _1)
{
if (timeout < 0)
if (timeout < 0 || cancel)
{
timeout = 0;
@@ -161,7 +149,7 @@
internal double GetFlow()
{
var interval = 1000;
var timeout = 6;// 0;
var timeout = 60;
var referenceV = 0D;
var waitHandle = new ManualResetEventSlim();
var timer = new System.Timers.Timer
@@ -182,7 +170,7 @@
void TimerElapsed(object _, ElapsedEventArgs _1)
{
if (timeout < 0)
if (timeout < 0 || cancel)
{
timeout = 0;
@@ -205,6 +193,8 @@
waitHandle.Wait(timeout * interval);
waitHandle.Reset();
OmniPlusFormulas.OutDebugM3S(ref referenceV);
this.signarR.StopReferenceMessurement -= ReceiveFlow;
timer.Elapsed -= TimerElapsed;
@@ -218,9 +208,9 @@
internal void Stop()
{
this.signarR.SendStopFlow();
this.cancel = true;
this.ppnr = 0;
this.signarR.SendStopFlow();
}
public override void Dispose()
@@ -232,7 +222,7 @@
}
catch (Exception e)
{
File.AppendAllText(this.outputFile, $"[{DateTime.Now}][...] {e}{Environment.NewLine}");
AppLogger.Log($"[...] {e}");
}
base.Dispose();
@@ -240,7 +230,27 @@
private void SignarR_StateChanged(string value, string groupName)
{
File.AppendAllText(this.outputFile, $"[{DateTime.Now}][{groupName}] {value}{Environment.NewLine}");
AppLogger.Log($"[{groupName}] {value}");
}
private void LoadHeaders()
{
this.DispatcherInvoke(() =>
{
this.Add(new ItemsGridHeaderVM());
this.Add(new ItemsGridHeaderVM { Value = "RZ:" });
this.Add(new ItemsGridHeaderVM());
this.Add(new ItemsGridHeaderVM());
foreach (var _ in this.omniContext.Pruefpunkte)
{
this.Add(new ItemsGridHeaderVM());
this.Add(new ItemsGridHeaderVM());
this.Add(new ItemsGridHeaderVM());
}
this.Add(new ItemsGridHeaderVM());
});
}
}
}
@@ -6,6 +6,7 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
@@ -84,18 +85,18 @@
this.NotifyPropertyChanged(property);
}
protected Task StartNewTask(Action action)
protected Task StartNewTask(Action action, CancellationToken cancellationToken = default(CancellationToken))
{
return Task
.Factory
.StartNew(action)
.StartNew(action, cancellationToken)
.ContinueWith(task =>
{
if (task.Exception != null)
{
AppLogger.Log(task.Exception);
}
});
}, cancellationToken);
}
protected class Command : ICommand