2" - R2, T2 - getested
This commit is contained in:
@@ -11,9 +11,11 @@
|
||||
{
|
||||
public App()
|
||||
{
|
||||
ServiceProvider
|
||||
.ServiceCollection
|
||||
.AddSingleton(new OmniContext(Appsettings.OmniDB, Appsettings.OutputDirectory));
|
||||
//ServiceProvider
|
||||
// .ServiceCollection
|
||||
// .AddSingleton(new OmniContext(Appsettings.OmniDB, Appsettings.OutputDirectory));
|
||||
|
||||
OmniContext.Create(Appsettings.OmniDB, Appsettings.OutputDirectory);
|
||||
}
|
||||
|
||||
internal static event Action Exiting;
|
||||
|
||||
@@ -60,7 +60,6 @@
|
||||
<DependentUpon>ItemsGrid.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Models\AppLogger.cs" />
|
||||
<Compile Include="Models\ServiceProvider.cs" />
|
||||
<Compile Include="Models\Appsettings.cs" />
|
||||
<Compile Include="Models\CompilerServices.cs" />
|
||||
<Compile Include="ViewModels\DefaultsHeaderRow.cs" />
|
||||
|
||||
@@ -1,101 +0,0 @@
|
||||
namespace InspectionUI.Models
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Linq;
|
||||
|
||||
public interface IServiceCollection
|
||||
{
|
||||
IServiceCollection AddSingleton<T>(T instance);
|
||||
}
|
||||
|
||||
public class ServiceProvider : IServiceProvider, IServiceCollection
|
||||
{
|
||||
private static readonly ServiceProvider serviceProvider = new ServiceProvider();
|
||||
|
||||
private readonly ConcurrentDictionary<Type, object> services;
|
||||
|
||||
private ServiceProvider()
|
||||
{
|
||||
this.services = new ConcurrentDictionary<Type, object>();
|
||||
}
|
||||
|
||||
public IServiceCollection AddSingleton<T>(T instance)
|
||||
{
|
||||
services.AddOrUpdate(typeof(T), instance, (t, i) => instance);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public object GetService(Type serviceType)
|
||||
{
|
||||
return services.GetOrAdd(serviceType, default(object));
|
||||
}
|
||||
|
||||
public static IServiceCollection ServiceCollection
|
||||
{
|
||||
get => serviceProvider;
|
||||
}
|
||||
|
||||
public static T GetService<T>()
|
||||
{
|
||||
var serviceType = typeof(T);
|
||||
var serviceInstance = default(T);
|
||||
|
||||
if (serviceProvider.GetService(serviceType) is T existingInstance)
|
||||
{
|
||||
serviceInstance = existingInstance;
|
||||
}
|
||||
else if (CreateInstance(serviceType) is T newInstance)
|
||||
{
|
||||
serviceInstance = newInstance;
|
||||
}
|
||||
|
||||
return serviceInstance;
|
||||
}
|
||||
|
||||
private static object CreateInstance(Type instanceType)
|
||||
{
|
||||
var instance = default(object);
|
||||
var constructors = instanceType
|
||||
.GetConstructors()
|
||||
.OrderByDescending(x => x.GetParameters().Length);
|
||||
|
||||
foreach (var constructor in constructors)
|
||||
{
|
||||
var parameters = constructor.GetParameters();
|
||||
var parametersLength = parameters.Length;
|
||||
var createParameters = new object[parametersLength];
|
||||
|
||||
for (int i = 0; i < parametersLength; i++)
|
||||
{
|
||||
var parameterType = parameters[i].ParameterType;
|
||||
var parameter = serviceProvider.GetService(parameterType);
|
||||
|
||||
if (parameter is null)
|
||||
{
|
||||
parameter = CreateInstance(parameterType);
|
||||
}
|
||||
|
||||
createParameters[i] = parameter;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
instance = constructor.Invoke(createParameters);
|
||||
|
||||
if (instance != null)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
}
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,8 +13,8 @@
|
||||
this.Add(new ItemsGridHeaderVM());
|
||||
this.Add(new ItemsGridHeaderVM());
|
||||
|
||||
var pruefpunkte = ServiceProvider
|
||||
.GetService<OmniContext>()
|
||||
var pruefpunkte = OmniContext
|
||||
.Current
|
||||
.Auftrag
|
||||
.Pruefpunkte
|
||||
.Count;
|
||||
|
||||
@@ -13,8 +13,8 @@
|
||||
this.Add(new ItemsGridHeaderVM());
|
||||
this.Add(new ItemsGridHeaderVM { Value = "0.0" });
|
||||
|
||||
var pruefpunkte = ServiceProvider
|
||||
.GetService<OmniContext>()
|
||||
var pruefpunkte = OmniContext
|
||||
.Current
|
||||
.Auftrag
|
||||
.Pruefpunkte;
|
||||
|
||||
|
||||
@@ -13,8 +13,8 @@
|
||||
this.Add(new ItemsGridHeaderVM { Value = "SerialNr", Width = ItemsGridHeaderVM.Star });
|
||||
this.Add(new ItemsGridHeaderVM { Value = "Crr.F. %", Width = ItemsGridHeaderVM.Auto });
|
||||
|
||||
var pruefpunkte = ServiceProvider
|
||||
.GetService<OmniContext>()
|
||||
var pruefpunkte = OmniContext
|
||||
.Current
|
||||
.Auftrag
|
||||
.Pruefpunkte;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace InspectionUI.ViewModels
|
||||
{
|
||||
using InspectionUI.Models;
|
||||
using OmniPlus;
|
||||
|
||||
using System;
|
||||
using System.Windows.Input;
|
||||
@@ -88,7 +88,7 @@
|
||||
this.EnableButtons(false);
|
||||
|
||||
this.Errors = default(string);
|
||||
this.MetersPool = ServiceProvider.GetService<MetersPoolVM>();
|
||||
this.MetersPool = new MetersPoolVM(OmniContext.Current);
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(this.SuchNr))
|
||||
{
|
||||
|
||||
@@ -25,8 +25,8 @@
|
||||
this.Add(new ItemsGridCellVM());
|
||||
this.Add(new ItemsGridCellVM());
|
||||
|
||||
var pruefpunkte = ServiceProvider
|
||||
.GetService<OmniContext>()
|
||||
var pruefpunkte = OmniContext
|
||||
.Current
|
||||
.Auftrag
|
||||
.Pruefpunkte
|
||||
.Count;
|
||||
@@ -72,11 +72,6 @@
|
||||
base.Dispose();
|
||||
}
|
||||
|
||||
public Task SaveMeterStateAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
return this.StartNewTask(this.meter.SaveMeterState, cancellationToken);
|
||||
}
|
||||
|
||||
public Task LoadTestRunAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
return this.StartNewTask(this.meter.LoadTestRun, cancellationToken);
|
||||
@@ -84,10 +79,20 @@
|
||||
|
||||
public Task InitializeInspectionAsync(bool keepCorrection, CancellationToken cancellationToken)
|
||||
{
|
||||
if (keepCorrection)
|
||||
{
|
||||
cancellationToken.Register(this.meter.FinishInspection);
|
||||
}
|
||||
|
||||
this.uinr = 0;
|
||||
|
||||
void InitializeInspection()
|
||||
{
|
||||
if (!this.meter.IsConnected)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this.meter.InitializeForInspection(keepCorrection);
|
||||
|
||||
this.Set(this.meter.TestRun.CrrfBefore, "{0:0.0}", 3);
|
||||
@@ -102,6 +107,11 @@
|
||||
|
||||
void StartCalibration()
|
||||
{
|
||||
if (!this.meter.IsConnected)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this.meter.StartCalibration((ushort)pp.Rotations, (ushort)pp.Duration);
|
||||
|
||||
this.ShowRestTime(pp.Duration, this.uinr * 3 + 1);
|
||||
@@ -114,11 +124,17 @@
|
||||
{
|
||||
void StopCalibration()
|
||||
{
|
||||
if (!this.meter.IsConnected)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var response = this.meter.StopCalibration(pp, refm3s);
|
||||
|
||||
var index = this.uinr * 3 + 1;
|
||||
|
||||
this.Set(response.Item2, "{0}", index);
|
||||
this.Set(response.Item1, "{0:0.0000000000}", index + 1);
|
||||
this.Set(response.Item1, "{0:0.0000000}", index + 1);
|
||||
this.Set(response.Item3, "{0:0.00}", index + 2);
|
||||
}
|
||||
|
||||
@@ -129,6 +145,11 @@
|
||||
{
|
||||
void FinishInspection()
|
||||
{
|
||||
if (!this.meter.IsConnected)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this.meter.FinishInspection();
|
||||
|
||||
var crrf = this.meter.TestRun.CrrfAfter;
|
||||
|
||||
@@ -36,26 +36,24 @@
|
||||
|
||||
public void LoadMeters()
|
||||
{
|
||||
this.referenceMeter = ServiceProvider.GetService<ReferenceMeterVM>();
|
||||
this.referenceMeter = new ReferenceMeterVM(OmniContext.Current);
|
||||
this.Add(this.referenceMeter);
|
||||
|
||||
this.omniContext
|
||||
.LoadMetersAsync(Appsettings.COMPorts, Appsettings.PSNR)
|
||||
.ContinueWith(_ =>
|
||||
{
|
||||
foreach (var meter in this.omniContext.Meters)
|
||||
{
|
||||
this.Add(new MeterVM(meter));
|
||||
}
|
||||
this.omniContext.LoadMeters(Appsettings.COMPorts, Appsettings.PSNR);
|
||||
|
||||
this.NotifyPropertyChanged();
|
||||
});
|
||||
foreach (var meter in this.omniContext.Meters)
|
||||
{
|
||||
this.Add(new MeterVM(meter));
|
||||
}
|
||||
|
||||
this.NotifyPropertyChanged();
|
||||
}
|
||||
|
||||
public void RunInspection(bool keepCorrection = false, bool addCorrection = false)
|
||||
public void RunInspection(bool keepCorrection = false)
|
||||
{
|
||||
// show reference meter seconds
|
||||
// load meterVM in each task as state
|
||||
this.cancellationTokenSource = new CancellationTokenSource();
|
||||
|
||||
var cancellationToken = this.cancellationTokenSource.Token;
|
||||
var tasks = new List<Task>();
|
||||
var meters = this
|
||||
@@ -70,13 +68,6 @@
|
||||
|
||||
this.ContinueWhenAll(tasks);
|
||||
|
||||
foreach (var meterVM in meters)
|
||||
{
|
||||
tasks.Add(meterVM.SaveMeterStateAsync(cancellationToken));
|
||||
}
|
||||
|
||||
this.ContinueWhenAll(tasks);
|
||||
|
||||
foreach (var meterVM in meters)
|
||||
{
|
||||
tasks.Add(meterVM.InitializeInspectionAsync(keepCorrection, cancellationToken));
|
||||
@@ -162,9 +153,9 @@
|
||||
{
|
||||
this.DispatcherInvoke(() =>
|
||||
{
|
||||
this.Add(ServiceProvider.GetService<HeadersRowVM>());
|
||||
this.Add(ServiceProvider.GetService<DefaultsHeaderRow>());
|
||||
this.Add(ServiceProvider.GetService<DefaultsRowVM>());
|
||||
this.Add(new HeadersRowVM());
|
||||
this.Add(new DefaultsHeaderRow());
|
||||
this.Add(new DefaultsRowVM());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,10 +18,10 @@
|
||||
private int ppnr;
|
||||
private bool cancel;
|
||||
|
||||
public ReferenceMeterVM(OmniContext omniContext, ExchangeConnection signarR) : base()
|
||||
public ReferenceMeterVM(OmniContext omniContext) : base()
|
||||
{
|
||||
this.omniContext = omniContext;
|
||||
this.signarR = signarR;
|
||||
this.signarR = new ExchangeConnection();
|
||||
this.signarR.StateChanged += this.SignarR_StateChanged;
|
||||
this.signarR.Connect(Appsettings.HubURL);
|
||||
this.ppnr = 1;
|
||||
@@ -41,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
|
||||
@@ -95,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
|
||||
@@ -149,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
|
||||
@@ -193,14 +193,14 @@
|
||||
waitHandle.Wait(timeout * interval);
|
||||
waitHandle.Reset();
|
||||
|
||||
OmniPlusFormulas.OutDebugM3S(ref referenceV);
|
||||
// OmniPlusFormulas.OutDebugM3S(ref referenceV);
|
||||
|
||||
this.signarR.StopReferenceMessurement -= ReceiveFlow;
|
||||
timer.Elapsed -= TimerElapsed;
|
||||
|
||||
waitHandle.Wait(1000);
|
||||
|
||||
this.Set(referenceV, "{0:0.0000000000}", this.ppnr + 1);
|
||||
this.Set(referenceV, "{0:0.0000000}", this.ppnr + 1);
|
||||
this.Set(referenceV == 0 ? 0 : 100, "{0:0.00}", this.ppnr + 2);
|
||||
|
||||
return referenceV;
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
const int PULSES_PER_ROTATION = 8;
|
||||
|
||||
var fractionPart = (double)fraction / FRACTION_FACTOR;
|
||||
var mlPlain = intPart + fractionPart;
|
||||
var mlPulse = intPart + fractionPart;
|
||||
var mlr = mlPulse * PULSES_PER_ROTATION;
|
||||
|
||||
@@ -114,15 +113,14 @@
|
||||
|
||||
public static double MeterFlowM3S(double rotations, double mlr, double duration)
|
||||
{
|
||||
var seconds = duration * (1D / (short.MaxValue + 1));
|
||||
var m3s = rotations * mlr / seconds / 1000D / 1000D * 100;
|
||||
var m3s = rotations * mlr / duration / 1000D / 1000D * 100;
|
||||
|
||||
if (double.IsNaN(m3s) || double.IsInfinity(m3s))
|
||||
{
|
||||
return default(double);
|
||||
}
|
||||
|
||||
return rotations * mlr / seconds / 1000D / 1000D * 100;
|
||||
return m3s;
|
||||
}
|
||||
|
||||
public static double MeterFlowM3S(this OmniPlusTestPoint point, OmniPlusTest test)
|
||||
@@ -186,13 +184,5 @@
|
||||
|
||||
return crrf;
|
||||
}
|
||||
|
||||
public static void OutDebugM3S(ref double value)
|
||||
{
|
||||
if (true)
|
||||
{
|
||||
value = new Random().Next(95, 100) / 1005D;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,16 +11,21 @@
|
||||
private readonly ConcurrentDictionary<int, OmniMeter> meters;
|
||||
private readonly OmniDatabase database;
|
||||
private readonly string outputDirectory;
|
||||
|
||||
|
||||
public static void Create(String omniDB, String outputDirectory)
|
||||
{
|
||||
Current = new OmniContext(omniDB, outputDirectory);
|
||||
}
|
||||
|
||||
private int runId;
|
||||
|
||||
public OmniContext(string connectionString, string outputDirectory)
|
||||
private OmniContext(string connectionString, string outputDirectory)
|
||||
{
|
||||
this.outputDirectory = outputDirectory;
|
||||
this.database = new OmniDatabase(connectionString, outputDirectory);
|
||||
this.meters = new ConcurrentDictionary<int, OmniMeter>();
|
||||
|
||||
Current = this;
|
||||
//Current = this;
|
||||
}
|
||||
|
||||
public OmniAuftrag Auftrag { get; set; }
|
||||
@@ -77,36 +82,22 @@
|
||||
this.runId = this.database.GetNextRunId();
|
||||
}
|
||||
|
||||
public Task LoadMetersAsync(string portNames, string psnr)
|
||||
public void LoadMeters(string portNames, string psnr)
|
||||
{
|
||||
this.Dispose();
|
||||
|
||||
var tasks = new List<Task>();
|
||||
|
||||
var slotNr = 1;
|
||||
|
||||
foreach (var portName in portNames.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries))
|
||||
{
|
||||
var meter = new OmniMeter(psnr, slotNr, portName, this.outputDirectory);
|
||||
|
||||
this.meters.AddOrUpdate(slotNr, meter, (_, _1) => meter);
|
||||
meter.ConnectIrda();
|
||||
|
||||
tasks.Add(Task.Factory.StartNew(() => meter.ConnectIrda()));
|
||||
this.meters.AddOrUpdate(slotNr, meter, (_, _1) => meter);
|
||||
|
||||
slotNr++;
|
||||
}
|
||||
|
||||
return Task.Factory.ContinueWhenAll(tasks.ToArray(), _tasks =>
|
||||
{
|
||||
foreach (var task in _tasks)
|
||||
{
|
||||
if (task.Exception != null)
|
||||
{
|
||||
// TODO: Add logging.
|
||||
}
|
||||
}
|
||||
|
||||
tasks.Clear();
|
||||
});
|
||||
}
|
||||
|
||||
internal int UpdateTestRun(IDictionary<string, object> parameters, int id, byte slotNr)
|
||||
@@ -114,6 +105,6 @@
|
||||
return this.database.UpdateTestRun(parameters, id, slotNr);
|
||||
}
|
||||
|
||||
internal static OmniContext Current { get; private set; }
|
||||
public static OmniContext Current { get; private set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,6 +45,8 @@
|
||||
|
||||
public OmniPruefgang TestRun { get; private set; }
|
||||
|
||||
public Boolean IsConnected { get; set; }
|
||||
|
||||
public void ConnectIrda()
|
||||
{
|
||||
if (this.connection is null)
|
||||
@@ -64,6 +66,15 @@
|
||||
if (buildInfo.Status == Status.Completed)
|
||||
{
|
||||
this.MeterNr = buildInfo.Value;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(this.MeterNr))
|
||||
{
|
||||
this.MeterNr = new string('.', 12);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.IsConnected = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -87,6 +98,11 @@
|
||||
this.WriteToLog();
|
||||
}
|
||||
|
||||
public void SaveCorrection()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void InitializeForInspection(bool keepCorrection = false)
|
||||
{
|
||||
var systemParameters = this.connection.ViewSystemParameters();
|
||||
@@ -231,11 +247,16 @@
|
||||
var response = this.connection.ViewChamberCalibration();
|
||||
var rotations = response.Rotations;
|
||||
var duration = response.DurationSec;
|
||||
|
||||
this.NotifyStateChanged(rotations);
|
||||
this.NotifyStateChanged(duration);
|
||||
|
||||
var rs = $"{rotations}/{duration:0.0}";
|
||||
var mlr = OmniPlusFormulas.MilliliterPerRotation(this.defaults.IntPart, (ushort)this.defaults.Fraction, this.defaults.Factor);
|
||||
var m3s = OmniPlusFormulas.MeterFlowM3S(rotations, mlr, duration);
|
||||
|
||||
OmniPlusFormulas.OutDebugM3S(ref m3s);
|
||||
|
||||
this.NotifyStateChanged(mlr);
|
||||
this.NotifyStateChanged(m3s);
|
||||
|
||||
var acc = OmniPlusFormulas.AccuracyPercentage(m3s, refm3s);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user