OMNI: first test at the production
This commit is contained in:
@@ -1,26 +1,43 @@
|
||||
using System.Threading;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CommonConsole
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
private static Thread thread;
|
||||
|
||||
public static void Main()
|
||||
{
|
||||
thread = new Thread(new ParameterizedThreadStart(ThreadHandler));
|
||||
thread.IsBackground = true;
|
||||
thread.Start(thread);
|
||||
var cancelationTokenSource = new CancellationTokenSource();
|
||||
var cancelationToken = cancelationTokenSource.Token;
|
||||
var manualResetEventSlim = new ManualResetEventSlim();
|
||||
|
||||
while (thread.IsAlive)
|
||||
void LongRunningTask()
|
||||
{
|
||||
Console.WriteLine("started");
|
||||
|
||||
}
|
||||
manualResetEventSlim.Wait(3000, cancelationToken);
|
||||
|
||||
Console.WriteLine("stoped");
|
||||
}
|
||||
|
||||
private static void ThreadHandler(object parameter)
|
||||
Task.Factory.StartNew(LongRunningTask);
|
||||
|
||||
while (true)
|
||||
{
|
||||
Thread.Sleep(3000);
|
||||
var consoleKey = Console.ReadKey().Key;
|
||||
|
||||
if (consoleKey == ConsoleKey.X)
|
||||
{
|
||||
cancelationTokenSource.Cancel();
|
||||
}
|
||||
else if (consoleKey == ConsoleKey.C)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
Console.WriteLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ namespace ExchangeHub
|
||||
|
||||
this.disposables.Add(this.proxy.On(nameof(this.StopQ), () => this.StopQ?.Invoke()));
|
||||
this.disposables.Add(this.proxy.On(nameof(this.Disposed), () => this.Disposed?.Invoke()));
|
||||
this.disposables.Add(this.proxy.On(nameof(this.StartRef), duration => this.StartRef?.Invoke(duration)));
|
||||
this.disposables.Add(this.proxy.On<int>(nameof(this.StartRef), duration => this.StartRef?.Invoke(duration)));
|
||||
this.disposables.Add(this.proxy.On<double>(nameof(this.StartQ), volumeM3 => this.StartQ?.Invoke(volumeM3)));
|
||||
this.disposables.Add(this.proxy.On<double>(nameof(this.StopRef), volumeM3 => this.StopRef?.Invoke(volumeM3)));
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
<Setter Property="HorizontalContentAlignment" Value="Center"/>
|
||||
<Setter Property="VerticalContentAlignment" Value="Center"/>
|
||||
<Setter Property="Margin" Value="13, 0, 0, 0" />
|
||||
<Setter Property="Padding" Value="34, 8"/>
|
||||
<Setter Property="Padding" Value="13, 8"/>
|
||||
<Setter Property="Cursor" Value="Hand" />
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Windows;
|
||||
using System.Windows.Threading;
|
||||
|
||||
public partial class App : Application
|
||||
{
|
||||
@@ -11,8 +12,8 @@
|
||||
|
||||
public static event Action Disposed;
|
||||
|
||||
public static void Invoke(Action action)
|
||||
=> Current.Dispatcher.Invoke(action);
|
||||
public static void BeginInvoke(Action action)
|
||||
=> Current.Dispatcher.BeginInvoke(action, DispatcherPriority.ApplicationIdle);
|
||||
|
||||
public static void NotifyDisposed()
|
||||
=> Disposed?.Invoke();
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
namespace OMNIPruefung.ViewModels.Content
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@@ -13,6 +15,8 @@
|
||||
public class COMContentVM : ContentVM
|
||||
{
|
||||
private OmniPlusConnection connection;
|
||||
private readonly Dictionary<OmniPlusTestPoint, OmniPlusTest> results
|
||||
= new Dictionary<OmniPlusTestPoint, OmniPlusTest>();
|
||||
|
||||
public COMContentVM() : base()
|
||||
{
|
||||
@@ -131,6 +135,8 @@
|
||||
|
||||
internal Task PrepareConnectionTask(CancellationToken cancelationToken)
|
||||
{
|
||||
cancelationToken.Register(this.Dispose);
|
||||
|
||||
void PrepareConnection()
|
||||
{
|
||||
this.Progress = 0;
|
||||
@@ -157,6 +163,8 @@
|
||||
|
||||
internal Task ReadSystemParametersTask(CancellationToken cancelationToken)
|
||||
{
|
||||
cancelationToken.Register(this.Dispose);
|
||||
|
||||
void ReadSystemParameters()
|
||||
{
|
||||
if (!this.Running)
|
||||
@@ -194,6 +202,8 @@
|
||||
|
||||
internal Task SetInputVolumeTask(OmniPlusType defaults, CancellationToken cancelationToken)
|
||||
{
|
||||
cancelationToken.Register(this.Dispose);
|
||||
|
||||
void SetInputVolume()
|
||||
{
|
||||
if (!this.Running)
|
||||
@@ -228,8 +238,10 @@
|
||||
return Task.Factory.StartNew(SetInputVolume, cancelationToken);
|
||||
}
|
||||
|
||||
internal Task InspectPPTask(ushort rotations, ushort duration, CancellationToken cancelationToken)
|
||||
internal Task InspectPPTask(OmniPlusTestPoint pp, CancellationToken cancelationToken)
|
||||
{
|
||||
cancelationToken.Register(this.Dispose);
|
||||
|
||||
void InspectPP()
|
||||
{
|
||||
if (!this.Running)
|
||||
@@ -238,6 +250,10 @@
|
||||
}
|
||||
|
||||
this.Connected = this.connection.Connected;
|
||||
this.results[pp] = new OmniPlusTest();
|
||||
|
||||
var rotations = pp.Rotations;
|
||||
var duration = pp.Duration;
|
||||
|
||||
if (this.Connected)
|
||||
{
|
||||
@@ -246,8 +262,8 @@
|
||||
|
||||
if (this.Running)
|
||||
{
|
||||
var format = "Bereit in {0} Sekunden";
|
||||
var _duration = duration;
|
||||
var format = $"Prüfung für {rotations}/{duration} (rotations/seconds) Bereit in {{0}} Sekunden";
|
||||
var _duration = pp.Duration;
|
||||
|
||||
while (_duration > 0 && !cancelationToken.IsCancellationRequested)
|
||||
{
|
||||
@@ -263,7 +279,7 @@
|
||||
|
||||
if (!this.Running)
|
||||
{
|
||||
this.State = $"Prüfung für {rotations}/{duration} fehlgeschlagen: ({calibrationResult.Status})";
|
||||
this.State = $"Prüfung für {rotations}/{duration} (rotations/seconds) fehlgeschlagen: ({calibrationResult.Status})";
|
||||
}
|
||||
else if (calibrationResult.Control != ChamberCalibrationResponse.TEST_COMPLETED)
|
||||
{
|
||||
@@ -273,13 +289,14 @@
|
||||
: nameof(ChamberCalibrationResponse.TEST_FAILED);
|
||||
|
||||
this.Running = false;
|
||||
this.State = $"Prüfung für {rotations}/{duration} fehlgeschlagen: ({controlNr} - {controlTxt})";
|
||||
this.State = $"Prüfung für {rotations}/{duration} (rotations/seconds) fehlgeschlagen: ({controlNr} - {controlTxt})";
|
||||
}
|
||||
else // process calibration
|
||||
{
|
||||
this.Progress += 10;
|
||||
this.State = $"Prüfung für {rotations}/{duration} (rotations/seconds) erfolgreich";
|
||||
|
||||
this.State = $"Prüfung für {rotations}/{duration} erfolgreich";
|
||||
this.results[pp].Duration = calibrationResult.Duration;
|
||||
this.results[pp].Rotations = calibrationResult.Rotations;
|
||||
}
|
||||
}
|
||||
else // not activated
|
||||
@@ -289,7 +306,7 @@
|
||||
}
|
||||
else // not connected or running
|
||||
{
|
||||
this.State = $"PP {rotations}/{duration} wurde aufgrund ungültiger Eigenschaften abgebrochen";
|
||||
this.State = $"PP {rotations}/{duration} (rotations/seconds) wurde aufgrund ungültiger Eigenschaften abgebrochen";
|
||||
}
|
||||
|
||||
this.Progress += 10;
|
||||
@@ -298,6 +315,85 @@
|
||||
return Task.Factory.StartNew(InspectPP, cancelationToken);
|
||||
}
|
||||
|
||||
internal Task StopPPCalibrationTask(OmniPlusTestPoint pp, CancellationToken cancellationToken)
|
||||
{
|
||||
cancellationToken.Register(this.Dispose);
|
||||
|
||||
void StopPPCalibration()
|
||||
{
|
||||
if (this.Running && this.Connected)
|
||||
{
|
||||
var calibrationResult = connection.ViewChamberCalibration();
|
||||
this.results[pp].Rotations = calibrationResult.Rotations;
|
||||
this.results[pp].Duration = calibrationResult.Duration;
|
||||
this.Running = calibrationResult.Succeeded;
|
||||
|
||||
if (this.Running)
|
||||
{
|
||||
this.State = $"PP {pp.Rotations}/{pp.Duration} (rotations/seconds) wurde durchgeführt.";
|
||||
}
|
||||
else
|
||||
{
|
||||
this.State = $"PP {pp.Rotations}/{pp.Duration} (rotations/seconds) fehlgeschlagen: {(int)calibrationResult.Status} - {calibrationResult.Status}";
|
||||
}
|
||||
}
|
||||
|
||||
this.Progress += 10;
|
||||
}
|
||||
|
||||
return Task.Factory.StartNew(StopPPCalibration, cancellationToken);
|
||||
}
|
||||
|
||||
internal Task StartPPCalibrationTask(OmniPlusTestPoint pp, CancellationToken cancellationToken)
|
||||
{
|
||||
cancellationToken.Register(this.Dispose);
|
||||
|
||||
void StartPPCalibration()
|
||||
{
|
||||
this.results[pp] = new OmniPlusTest();
|
||||
|
||||
if (this.Running && this.Connected)
|
||||
{
|
||||
var rotations = pp.Rotations;
|
||||
var duration = pp.Duration;
|
||||
var activationResponse = connection.StartChamberCalibration(pp.Rotations, pp.Duration);
|
||||
this.Running = activationResponse.Succeeded;
|
||||
|
||||
if (this.Running)
|
||||
{
|
||||
this.State = $"PP {rotations}/{duration} (rotations/seconds) wurde gestarted.";
|
||||
}
|
||||
else
|
||||
{
|
||||
this.State = $"PP {rotations}/{duration} (rotations/seconds): {(int)activationResponse.Status} - {activationResponse.Status}";
|
||||
}
|
||||
}
|
||||
|
||||
this.Progress += 10;
|
||||
}
|
||||
|
||||
return Task.Factory.StartNew(StartPPCalibration, cancellationToken);
|
||||
}
|
||||
|
||||
internal void SetReferenceVolume(OmniPlusTestPoint pp, double referenceV)
|
||||
{
|
||||
if (this.results.ContainsKey(pp))
|
||||
{
|
||||
this.results[pp].VolumeMessured = referenceV;
|
||||
}
|
||||
}
|
||||
|
||||
internal double GetCorrectionFactor()
|
||||
{
|
||||
this.Meter.CorrectionFactor = this.results
|
||||
.OrderBy(x => x.Key.GalPerMin)
|
||||
.Select(x => x.Value.DifferencePercentage)
|
||||
.ToArray()
|
||||
.GetCorrectionFactor();
|
||||
|
||||
return this.Meter.CorrectionFactor;
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
try
|
||||
@@ -308,6 +404,17 @@
|
||||
{
|
||||
this.State = e.Message;
|
||||
}
|
||||
|
||||
// TODO: save state
|
||||
|
||||
try
|
||||
{
|
||||
this.results.Clear();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
this.State = e.Message;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,8 +16,12 @@
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
|
||||
using TimersTimer = System.Timers.Timer;
|
||||
|
||||
public class EOLContentVM : ContentVM
|
||||
{
|
||||
private static readonly string line = new string('=', 500);
|
||||
|
||||
private readonly EOLSettings omnisettings;
|
||||
private readonly ExchangeHubSettings hubsettings;
|
||||
private CancellationTokenSource cancellationTokenSource;
|
||||
@@ -25,7 +29,8 @@
|
||||
private OmniPlusDatabase dbcontext;
|
||||
private ExchangeConnection signalR;
|
||||
private ICollection<Task> tasks;
|
||||
private Task mainTask;
|
||||
private ManualResetEventSlim manualResetEventSlim;
|
||||
private TimersTimer timer;
|
||||
|
||||
public EOLContentVM() : base()
|
||||
{
|
||||
@@ -43,7 +48,6 @@
|
||||
this.dbcontext = new OmniPlusDatabase(this.omnisettings.OmniDB);
|
||||
this.signalR = new ExchangeConnection();
|
||||
this.signalR.OutputDir = this.hubsettings.ExchangeHubOutputDir;
|
||||
this.signalR.Connect(this.hubsettings.ExchangeHubURL);
|
||||
|
||||
this.LoadComPorts = new Command(this.InitializeComPorts);
|
||||
this.CancelInspection = new Command(this.CancelInspectionHandler);
|
||||
@@ -64,6 +68,18 @@
|
||||
}
|
||||
}
|
||||
|
||||
private string state;
|
||||
public string State
|
||||
{
|
||||
get => this.state;
|
||||
set
|
||||
{
|
||||
this.state = value;
|
||||
|
||||
this.NotifyPropertyChanged(nameof(this.State));
|
||||
}
|
||||
}
|
||||
|
||||
private bool canStart;
|
||||
public bool CanStart
|
||||
{
|
||||
@@ -88,13 +104,13 @@
|
||||
}
|
||||
}
|
||||
|
||||
private int availableIn;
|
||||
private int secondsLeft;
|
||||
public int AvailableIn
|
||||
{
|
||||
get => this.availableIn;
|
||||
get => this.secondsLeft;
|
||||
set
|
||||
{
|
||||
this.availableIn = value;
|
||||
this.secondsLeft = value;
|
||||
|
||||
this.NotifyPropertyChanged(nameof(this.AvailableIn));
|
||||
}
|
||||
@@ -112,6 +128,8 @@
|
||||
}
|
||||
}
|
||||
|
||||
public string Line => line;
|
||||
|
||||
public ICommand LoadComPorts { get; }
|
||||
|
||||
public ICommand CancelInspection { get; }
|
||||
@@ -155,53 +173,73 @@
|
||||
|
||||
this.CanStart = true;
|
||||
this.CanStop = false;
|
||||
this.State = default(string);
|
||||
this.Error = default(string);
|
||||
}
|
||||
|
||||
private void CancelInspectionHandler()
|
||||
{
|
||||
this.Error = "Warte bis abbruch abgeschlossen ...";
|
||||
this.State = default(string);
|
||||
this.CanStop = false;
|
||||
this.CanStart = true;
|
||||
|
||||
try
|
||||
{
|
||||
this.manualResetEventSlim?.Set();
|
||||
this.cancellationTokenSource?.Cancel();
|
||||
this.ContinueWhenAll();
|
||||
this.tasks.Clear();
|
||||
|
||||
this.Error = "Vorgang wurde abbgebrochen!";
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
this.Error = e.ToString();
|
||||
}
|
||||
|
||||
this.InitializeComPorts();
|
||||
|
||||
Task.Factory.StartNew(() =>
|
||||
{
|
||||
if (this.AvailableIn > 0)
|
||||
{
|
||||
this.CanStart = false;
|
||||
this.manualResetEventSlim = new ManualResetEventSlim();
|
||||
this.timer = new TimersTimer(1000)
|
||||
{
|
||||
AutoReset = true,
|
||||
Enabled = true
|
||||
};
|
||||
|
||||
this.WaitUntil(this.AvailableIn, true);
|
||||
this.AvailableIn = 0;
|
||||
this.CanStart = true;
|
||||
}
|
||||
|
||||
this.Error = default(string);
|
||||
});
|
||||
}
|
||||
|
||||
private void StartInspectionHandler()
|
||||
{
|
||||
this.CanStop = true;
|
||||
this.CanStart = false;
|
||||
this.Error = string.Empty;
|
||||
|
||||
this.cancellationTokenSource = new CancellationTokenSource();
|
||||
this.cancellationToken = this.cancellationTokenSource.Token;
|
||||
|
||||
this.cancellationToken.Register(() =>
|
||||
this.manualResetEventSlim = new ManualResetEventSlim();
|
||||
this.timer = new TimersTimer(1000)
|
||||
{
|
||||
this.CanStart = true;
|
||||
this.CanStop = false;
|
||||
AutoReset = true,
|
||||
Enabled = true
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
this.ContinueWhenAll();
|
||||
this.tasks.Clear();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
this.Error = e.ToString();
|
||||
this.dbcontext.LoadOmniDefaults(6, "T2", this.OmniDefaults);
|
||||
this.NotifyPropertyChanged(nameof(this.OmniDefaults));
|
||||
this.signalR.Connect(this.hubsettings.ExchangeHubURL);
|
||||
|
||||
this.cancellationToken.ThrowIfCancellationRequested();
|
||||
}
|
||||
});
|
||||
|
||||
this.dbcontext.LoadOmniDefaults(5, "T2", this.OmniDefaults);
|
||||
|
||||
this.mainTask = Task.Factory.StartNew(() =>
|
||||
Task.Factory.StartNew(() =>
|
||||
{
|
||||
var coms = this.Nodes.Cast<COMContentVM>();
|
||||
|
||||
@@ -226,6 +264,10 @@
|
||||
|
||||
this.ContinueWhenAll();
|
||||
|
||||
var results = this.OmniDefaults
|
||||
.TestPoints
|
||||
.ToDictionary(x => x, x => new List<OmniPlusTest>());
|
||||
|
||||
foreach (var pp in this.OmniDefaults.TestPoints)
|
||||
{
|
||||
var rotations = pp.Rotations;
|
||||
@@ -233,34 +275,85 @@
|
||||
|
||||
foreach (var comVM in coms)
|
||||
{
|
||||
var task = comVM.InspectPPTask(rotations, duration, this.cancellationToken);
|
||||
|
||||
Console.WriteLine($"\t{task.Id}: {task.Status}");
|
||||
|
||||
this.tasks.Add(task);
|
||||
this.tasks.Add(comVM.StartPPCalibrationTask(pp, this.cancellationToken));
|
||||
}
|
||||
|
||||
this.ContinueWhenAll();
|
||||
|
||||
this.signalR.NotifyStartRef(duration);
|
||||
this.WaitUntil((int)(duration * 1.2), true, false);
|
||||
|
||||
if (this.manualResetEventSlim.IsSet)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
this.cancellationTokenSource.Cancel();
|
||||
var referenceV = this.GetReferenceVolume();
|
||||
|
||||
foreach (var comVM in coms)
|
||||
{
|
||||
this.tasks.Add(comVM.StopPPCalibrationTask(pp, this.cancellationToken));
|
||||
}
|
||||
|
||||
this.ContinueWhenAll();
|
||||
|
||||
foreach (var comVM in coms)
|
||||
{
|
||||
comVM.SetReferenceVolume(pp, referenceV);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var comVM in coms)
|
||||
{
|
||||
comVM.GetCorrectionFactor();
|
||||
}
|
||||
|
||||
foreach (var comVM in coms)
|
||||
{
|
||||
comVM.Dispose();
|
||||
}
|
||||
|
||||
this.CancelInspectionHandler();
|
||||
this.signalR.Dispose();
|
||||
|
||||
}, this.cancellationToken);
|
||||
}
|
||||
|
||||
private void WaitUntil(int duration, bool show = false, bool error = true)
|
||||
{
|
||||
this.AvailableIn = duration;
|
||||
this.timer.Elapsed += (_1, _2) =>
|
||||
{
|
||||
this.AvailableIn -= 1;
|
||||
|
||||
if (show)
|
||||
{
|
||||
if (error)
|
||||
{
|
||||
this.State = null;
|
||||
this.Error = $"Verfügbar in {this.AvailableIn} Sekunden";
|
||||
}
|
||||
else
|
||||
{
|
||||
this.Error = null;
|
||||
this.State = $"Noch {this.AvailableIn} Sekunden verbleiben";
|
||||
}
|
||||
}
|
||||
};
|
||||
this.timer.Start();
|
||||
this.manualResetEventSlim.Wait(this.AvailableIn * 1000);
|
||||
this.timer.Stop();
|
||||
}
|
||||
|
||||
private void ContinueWhenAll()
|
||||
{
|
||||
if (tasks.Any())
|
||||
if (this.tasks.Any())
|
||||
{
|
||||
Task.Factory
|
||||
.ContinueWhenAll(this.tasks.ToArray(), _tasks =>
|
||||
{
|
||||
foreach (var task in _tasks)
|
||||
{
|
||||
Console.WriteLine($"\t{task.Id}: {task.Status}");
|
||||
}
|
||||
})
|
||||
.ContinueWhenAll(this.tasks.ToArray(), _ => { })
|
||||
.Wait();
|
||||
|
||||
this.tasks.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -271,5 +364,31 @@
|
||||
comVM.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private double GetReferenceVolume()
|
||||
{
|
||||
var received = false;
|
||||
var referenceV = 0D;
|
||||
var timeout = 10; // seconds
|
||||
|
||||
void referenceVolumeReceived(double m3h)
|
||||
{
|
||||
received = true;
|
||||
referenceV = m3h;
|
||||
}
|
||||
|
||||
this.signalR.StopRef += referenceVolumeReceived;
|
||||
|
||||
this.signalR.NotifyStopRef();
|
||||
|
||||
while (!received && timeout > 0)
|
||||
{
|
||||
Thread.Sleep(1000);
|
||||
|
||||
timeout--;
|
||||
}
|
||||
|
||||
return referenceV;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,12 +20,12 @@
|
||||
{
|
||||
this.Header = "Exchange HUB";
|
||||
this.Option = new ExchangeHubOptionVM(this);
|
||||
this.Option.OptionSelected += this.NotifyOptionSelected;
|
||||
this.Connect = new Command(this.ConnectHubHandler);
|
||||
this.Disconnect = new Command(this.DisconnectHubHandler);
|
||||
this.hubsettings = new ExchangeHubSettings();
|
||||
this.connection = new ExchangeConnection();
|
||||
|
||||
this.Option.OptionSelected += this.NotifyOptionSelected;
|
||||
this.connection.OutputDir = this.hubsettings.ExchangeHubOutputDir;
|
||||
this.connection.StateChanged += this.Connection_StateChanged;
|
||||
|
||||
this.NotifyPropertyChanged(nameof(this.LogContent));
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
namespace OMNIPruefung.ViewModels.Features
|
||||
{
|
||||
using OmniPlus.Features;
|
||||
using OMNIPruefung.ViewModels.Base;
|
||||
|
||||
using System.Collections.Generic;
|
||||
@@ -18,6 +19,11 @@
|
||||
}
|
||||
}
|
||||
|
||||
public double CorrectionFactor { get; set; }
|
||||
|
||||
public ChamberCalibrationResponse CalibrationResult { get; set; }
|
||||
= new ChamberCalibrationResponse();
|
||||
|
||||
public Dictionary<string, Dictionary<string, string>> Properties
|
||||
{
|
||||
get
|
||||
@@ -27,6 +33,11 @@
|
||||
dictionary["System parameters:"] = this.SystemParameters
|
||||
?.ToDictionary() ?? new Dictionary<string, string>();
|
||||
|
||||
dictionary["Test results:"] = new Dictionary<string, string>
|
||||
{
|
||||
{ nameof(this.CorrectionFactor), $"{this.CorrectionFactor:0.0000}" }
|
||||
};
|
||||
|
||||
return dictionary;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
VerticalAlignment="Stretch"
|
||||
Background="White">
|
||||
|
||||
<Grid Margin="21">
|
||||
<Grid Margin="13">
|
||||
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
@@ -15,25 +15,65 @@
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Label Grid.Row="0"
|
||||
Content="{Binding Header}"
|
||||
Background="Transparent"
|
||||
FontWeight="Bold"
|
||||
FontSize="20"
|
||||
Padding="0"
|
||||
Margin="0" />
|
||||
<Border Grid.Row="0"
|
||||
VerticalAlignment="Bottom"
|
||||
Background="Black"
|
||||
Opacity="0.7"
|
||||
Height="1"
|
||||
Margin="0" />
|
||||
<Grid Grid.Row="0">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" /> <!-- Auftrag:-->
|
||||
<RowDefinition Height="Auto" /> <!--Kd.Auftrag:-->
|
||||
<RowDefinition Height="Auto" /> <!-- PosNr:-->
|
||||
<RowDefinition Height="Auto" /> <!-- IdentNr:-->
|
||||
<RowDefinition Height="Auto" /> <!-- Kurztext:-->
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Label Grid.Column="0" Grid.Row="0" Content="Auftragskarte" Margin="0" Padding="0" FontWeight="Bold" FontSize="14" Grid.ColumnSpan="5" />
|
||||
<Label Grid.Column="0" Grid.Row="1" Content="{Binding Line}" Margin="0" Padding="0" FontWeight="Bold" Grid.ColumnSpan="5" />
|
||||
|
||||
<Label Grid.Column="0" Grid.Row="2" Content="AuftragNr:" HorizontalContentAlignment="Left" FontWeight="Bold" Margin="0" Padding="0, 2, 0, 0" />
|
||||
<Label Grid.Column="0" Grid.Row="3" Content="Kd.AuftragNr:" HorizontalContentAlignment="Left" FontWeight="Bold" Margin="0" Padding="0, 2, 0, 0" />
|
||||
<Label Grid.Column="0" Grid.Row="4" Content="PsNr:" HorizontalContentAlignment="Left" FontWeight="Bold" Margin="0" Padding="0, 2, 0, 0" />
|
||||
<Label Grid.Column="0" Grid.Row="5" Content="IdentNr:" HorizontalContentAlignment="Left" FontWeight="Bold" Margin="0" Padding="0, 2, 0, 0" />
|
||||
<Label Grid.Column="0" Grid.Row="6" Content="Kurztext:" HorizontalContentAlignment="Left" FontWeight="Bold" Margin="0" Padding="0, 2, 0, 0" />
|
||||
|
||||
<Label Grid.Column="2" Grid.Row="2" Content="Prüfpunkte" HorizontalContentAlignment="Left" FontWeight="Bold" Margin="0" Padding="0, 2, 21, 0"/>
|
||||
<Label Grid.Column="3" Grid.Row="2" Content="Toleranzen" HorizontalContentAlignment="Right" Grid.ColumnSpan="2" FontWeight="Bold" Margin="0" Padding="0, 2, 0, 0" />
|
||||
|
||||
<Label Grid.Column="2" Grid.Row="3" Content="Abweichung" HorizontalContentAlignment="Left" FontWeight="Bold" Margin="0" Padding="0, 2, 0, 0"/>
|
||||
<Label Grid.Column="3" Grid.Row="3" Content="min %" HorizontalContentAlignment="Right" FontWeight="Bold" Margin="0" Padding="0, 2, 21, 0"/>
|
||||
<Label Grid.Column="4" Grid.Row="3" Content="max %" HorizontalContentAlignment="Right" Grid.ColumnSpan="2" FontWeight="Bold" Margin="0" Padding="0, 2, 0, 0" />
|
||||
|
||||
<Label Grid.Column="2" Grid.Row="4" Content="{Binding OmniDefaults.TestPoints[0].VolumeM3H}" ContentStringFormat="{}{0:0.00} m³/h" HorizontalContentAlignment="Right" FontWeight="Bold" Margin="0" Padding="0, 2, 21, 0"/>
|
||||
<Label Grid.Column="2" Grid.Row="5" Content="{Binding OmniDefaults.TestPoints[1].VolumeM3H}" ContentStringFormat="{}{0:0.00} m³/h" HorizontalContentAlignment="Right" FontWeight="Bold" Margin="0" Padding="0, 2, 21, 0"/>
|
||||
<Label Grid.Column="2" Grid.Row="6" Content="{Binding OmniDefaults.TestPoints[2].VolumeM3H}" ContentStringFormat="{}{0:0.00} m³/h" HorizontalContentAlignment="Right" FontWeight="Bold" Margin="0" Padding="0, 2, 21, 0"/>
|
||||
|
||||
<Label Grid.Column="3" Grid.Row="4" Content="{Binding OmniDefaults.TestPoints[0].MinDiff}" ContentStringFormat="{}{0:0.00} %" HorizontalContentAlignment="Right" Margin="0" Padding="0, 2, 21, 0" Foreground="DimGray" />
|
||||
<Label Grid.Column="3" Grid.Row="5" Content="{Binding OmniDefaults.TestPoints[1].MinDiff}" ContentStringFormat="{}{0:0.00} %" HorizontalContentAlignment="Right" Margin="0" Padding="0, 2, 21, 0" Foreground="DimGray" />
|
||||
<Label Grid.Column="3" Grid.Row="6" Content="{Binding OmniDefaults.TestPoints[2].MinDiff}" ContentStringFormat="{}{0:0.00} %" HorizontalContentAlignment="Right" Margin="0" Padding="0, 2, 21, 0" Foreground="DimGray" />
|
||||
|
||||
<Label Grid.Column="4" Grid.Row="4" Content="{Binding OmniDefaults.TestPoints[0].MaxDiff}" ContentStringFormat="{}{0:0.00} %" HorizontalContentAlignment="Right" Margin="0" Padding="0, 2, 0, 0" Foreground="DimGray" />
|
||||
<Label Grid.Column="4" Grid.Row="5" Content="{Binding OmniDefaults.TestPoints[1].MaxDiff}" ContentStringFormat="{}{0:0.00} %" HorizontalContentAlignment="Right" Margin="0" Padding="0, 2, 0, 0" Foreground="DimGray" />
|
||||
<Label Grid.Column="4" Grid.Row="6" Content="{Binding OmniDefaults.TestPoints[2].MaxDiff}" ContentStringFormat="{}{0:0.00} %" HorizontalContentAlignment="Right" Margin="0" Padding="0, 2, 0, 0" Foreground="DimGray" />
|
||||
|
||||
<Label Grid.Column="0" Grid.Row="7" Content="{Binding Line}" Margin="0" Padding="0" FontWeight="Bold" Grid.ColumnSpan="5" />
|
||||
|
||||
<Label Grid.Column="0" Grid.Row="8" Content="{Binding State}" Margin="0" Padding="0, 3" Grid.ColumnSpan="5" FontWeight="Bold" />
|
||||
<Label Grid.Column="0" Grid.Row="8" Content="{Binding Error}" Margin="0" Padding="0, 3" Grid.ColumnSpan="5" FontWeight="Bold" Foreground="{StaticResource Red}" />
|
||||
</Grid>
|
||||
|
||||
<ItemsControl Grid.Row="1"
|
||||
ItemsSource="{Binding Option.Options}">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate DataType="{x:Type OptionsVM:COMOptionVM}">
|
||||
<Grid Margin="0, 30, 0, 0">
|
||||
<Grid Margin="0, 3, 0, 0">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
@@ -86,10 +126,6 @@
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
|
||||
<Label Grid.Row="2"
|
||||
Content="{Binding Error}"
|
||||
Foreground="{StaticResource Red}" />
|
||||
|
||||
<Grid Grid.Row="3">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
@@ -102,17 +138,17 @@
|
||||
Margin="0"
|
||||
Content="Plätze aktualisieren"
|
||||
Style="{DynamicResource SystemBtn}"
|
||||
Visibility="{Binding CanStartInspection, Converter={StaticResource BooleanVisibility}}"
|
||||
Visibility="{Binding CanStart, Converter={StaticResource BooleanVisibility}}"
|
||||
Command="{Binding LoadComPorts}"/>
|
||||
<Button Grid.Column="2"
|
||||
Content="Abbruch"
|
||||
Style="{DynamicResource SystemBtn}"
|
||||
Visibility="{Binding CanStopInspection, Converter={StaticResource BooleanVisibility}}"
|
||||
Visibility="{Binding CanStop, Converter={StaticResource BooleanVisibility}}"
|
||||
Command="{Binding CancelInspection}"/>
|
||||
<Button Grid.Column="3"
|
||||
Content="Prüfung starten"
|
||||
Style="{DynamicResource SystemBtn}"
|
||||
Visibility="{Binding CanStartInspection, Converter={StaticResource BooleanVisibility}}"
|
||||
Visibility="{Binding CanStart, Converter={StaticResource BooleanVisibility}}"
|
||||
Command="{Binding StartInspection}"/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
|
||||
@@ -60,7 +60,7 @@ namespace OmniPlus
|
||||
this.Write(request);
|
||||
this.InvokeLogMessage($"TX: {BitConverter.ToString(command)}");
|
||||
|
||||
while (!received /*&& sleep >= 0*/)
|
||||
while (!received && sleep >= 0)
|
||||
{
|
||||
sleep -= delay;
|
||||
|
||||
|
||||
@@ -154,8 +154,8 @@ namespace OmniPlus
|
||||
|
||||
protected void Write(params byte[] bytes)
|
||||
{
|
||||
this.BeginWaitingResponseAsync();
|
||||
|
||||
if (this.BeginWaitingResponseAsync())
|
||||
{
|
||||
lock (this.serialPort)
|
||||
{
|
||||
this.serialPort.Write(bytes, 0, bytes.Length);
|
||||
@@ -163,6 +163,7 @@ namespace OmniPlus
|
||||
|
||||
this.LogMessage?.Invoke($"TX: {BitConverter.ToString(bytes)}");
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void SerialPortConnection_DataReceived(byte[] bytes);
|
||||
|
||||
@@ -227,16 +228,21 @@ namespace OmniPlus
|
||||
this.LogMessage?.Invoke($"RX: {BitConverter.ToString(bytes)}");
|
||||
}
|
||||
|
||||
private void BeginWaitingResponseAsync()
|
||||
private bool BeginWaitingResponseAsync()
|
||||
{
|
||||
var buffer = new byte[1024];
|
||||
var stream = this.serialPort.BaseStream;
|
||||
|
||||
this.serialPort.BaseStream.BeginRead(buffer, 0, buffer.Length, delegate(IAsyncResult asyncResult)
|
||||
this.serialPort?.BaseStream?.BeginRead(buffer, 0, buffer.Length, delegate(IAsyncResult asyncResult)
|
||||
{
|
||||
try
|
||||
{
|
||||
var actualLength = this.serialPort.BaseStream.EndRead(asyncResult);
|
||||
var actualLength = this.serialPort?.BaseStream?.EndRead(asyncResult) ?? 0;
|
||||
|
||||
if (actualLength <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var received = new byte[actualLength];
|
||||
|
||||
Buffer.BlockCopy(buffer, 0, received, 0, actualLength);
|
||||
@@ -249,7 +255,9 @@ namespace OmniPlus
|
||||
this.StateChanged?.Invoke(this.state, $"{this.Options.PortName}: {e}");
|
||||
this.LogMessage?.Invoke(e.ToString());
|
||||
}
|
||||
}, stream);
|
||||
}, null);
|
||||
|
||||
return this.serialPort != null && this.serialPort.IsOpen;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -155,33 +155,33 @@ namespace OmniPlus
|
||||
|
||||
tasks.ContinueWhenAll();
|
||||
|
||||
//foreach (var point in this.omniType.TestPoints)
|
||||
//{
|
||||
// // TODO: 600 = 10min * 60sec - change for production.
|
||||
foreach (var point in this.omniType.TestPoints)
|
||||
{
|
||||
// TODO: 600 = 10min * 60sec - change for production.
|
||||
|
||||
// if (!this.signalRConnection.SetQAndWaitUntilReached(point.VolumeM3H))
|
||||
// {
|
||||
// this.CancelExecution();
|
||||
if (!this.signalRConnection.SetQAndWaitUntilReached(point.VolumeM3H))
|
||||
{
|
||||
this.CancelExecution();
|
||||
|
||||
// break;
|
||||
// }
|
||||
break;
|
||||
}
|
||||
|
||||
// tasks = new Task[connectionsCount];
|
||||
tasks = new Task[connectionsCount];
|
||||
|
||||
// foreach (var position in this.connections.Keys)
|
||||
// {
|
||||
// tasks[position - 1] = Task.Factory.StartNew(() => this.StartOmniInspection(position, point), this.cancellationToken);
|
||||
// }
|
||||
foreach (var position in this.connections.Keys)
|
||||
{
|
||||
tasks[position - 1] = Task.Factory.StartNew(() => this.StartOmniInspection(position, point), this.cancellationToken);
|
||||
}
|
||||
|
||||
// tasks.ContinueWhenAll();
|
||||
tasks.ContinueWhenAll();
|
||||
|
||||
// var volume = this.signalRConnection.RequestRefV();
|
||||
var volume = this.signalRConnection.RequestRefV();
|
||||
|
||||
// foreach (var position in this.connections.Keys)
|
||||
// {
|
||||
// this.SetPointDifference(position, point, volume);
|
||||
// }
|
||||
//}
|
||||
foreach (var position in this.connections.Keys)
|
||||
{
|
||||
this.SetPointDifference(position, point, volume);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var position in this.connections.Keys)
|
||||
{
|
||||
|
||||
@@ -104,6 +104,8 @@ namespace OmniPlus
|
||||
|
||||
public void LoadOmniDefaults(byte size, string variant, OmniPlusType omniType)
|
||||
{
|
||||
omniType?.TestPoints?.Clear();
|
||||
|
||||
using (var sqlConnection = new SqlConnection(this.connectionString))
|
||||
{
|
||||
sqlConnection.OpenConnection();
|
||||
@@ -173,8 +175,8 @@ namespace OmniPlus
|
||||
GalPerMin = sqlDataReader.GetValue<double>(field++),
|
||||
Rotations = (ushort)sqlDataReader.GetValue<short>(field++),
|
||||
Duration = (ushort)sqlDataReader.GetValue<short>(field++),
|
||||
MinDiff = (ushort)sqlDataReader.GetValue<double>(field++),
|
||||
MaxDiff = (ushort)sqlDataReader.GetValue<double>(field++),
|
||||
MinDiff = sqlDataReader.GetValue<double>(field++),
|
||||
MaxDiff = sqlDataReader.GetValue<double>(field++),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace OmniPlus
|
||||
{
|
||||
internal static class OmniPlusExtensions
|
||||
public static class OmniPlusExtensions
|
||||
{
|
||||
public const int BYTE_BITS = 8;
|
||||
|
||||
@@ -311,6 +311,11 @@ namespace OmniPlus
|
||||
|
||||
public static double GetCorrectionFactor(this double[] points)
|
||||
{
|
||||
if (points?.Length != 3)
|
||||
{
|
||||
return double.MinValue;
|
||||
}
|
||||
|
||||
var min = points[0];
|
||||
var mid = points[1];
|
||||
var max = points[2];
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace OmniPlus
|
||||
{
|
||||
internal class OmniPlusTest
|
||||
public class OmniPlusTest
|
||||
{
|
||||
public double Rotations { get; set; }
|
||||
|
||||
|
||||
@@ -10,9 +10,9 @@ namespace OmniPlus
|
||||
|
||||
public ushort Duration { get; set; }
|
||||
|
||||
public ushort MinDiff { get; set; }
|
||||
public double MinDiff { get; set; }
|
||||
|
||||
public ushort MaxDiff { get; set; }
|
||||
public double MaxDiff { get; set; }
|
||||
|
||||
public double MlPerRotation { get; set; }
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ namespace OmniPlus
|
||||
public InputVolume InputVolume { get; }
|
||||
= new InputVolume();
|
||||
|
||||
public ICollection<OmniPlusTestPoint> TestPoints { get; }
|
||||
public List<OmniPlusTestPoint> TestPoints { get; }
|
||||
= new List<OmniPlusTestPoint>();
|
||||
}
|
||||
}
|
||||
@@ -41,10 +41,10 @@ namespace OmniPlus
|
||||
{
|
||||
var startSeconds = seconds;
|
||||
|
||||
void waitRefStarted() => started = true;
|
||||
void waitRefStarted(int _) => started = true;
|
||||
this.slave.StartRef += waitRefStarted;
|
||||
|
||||
this.slave.NotifyStartRef();
|
||||
this.slave.NotifyStartRef(0);
|
||||
|
||||
while (!started && startSeconds >= 0)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user