Errors fixed.

Exchange Hub - added groups.
This commit is contained in:
Stoyan Zlatev
2024-01-03 16:11:11 +01:00
parent 17fc381303
commit 06be0002d6
13 changed files with 299 additions and 206 deletions
@@ -10,6 +10,8 @@
using OmniPlus;
using OmniPlus.Features;
using OmniPlus.Inspection;
using OMNIPruefung.ViewModels.Base;
using OMNIPruefung.ViewModels.Features;
using OMNIPruefung.ViewModels.Options;
@@ -331,22 +333,22 @@
{
this.results[pp] = new OmniPlusTest();
//if (this.IsRunning())
//{
// var rotations = pp.Rotations;
// var duration = pp.Duration;
// var activationResponse = connection.StartChamberCalibration(pp.Rotations, pp.Duration);
// this.Running = activationResponse.Succeeded && activationResponse.Control == ChamberCalibrationResponse.TEST_ACTIVATED;
if (this.IsRunning())
{
var rotations = pp.Rotations;
var duration = pp.Duration;
var activationResponse = connection.StartChamberCalibration(pp.Rotations, pp.Duration);
this.Running = activationResponse.Succeeded && activationResponse.Control == ChamberCalibrationResponse.TEST_ACTIVATED;
// 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}";
// }
//}
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;
}
@@ -354,7 +356,7 @@
return Task.Factory.StartNew(StartPPCalibration, cancellationToken);
}
internal Task StopPPCalibrationAsync(OmniPlusTestPoint pp, byte[] response, CancellationToken cancellationToken)
internal Task StopPPCalibrationAsync(OmniPlusTestPoint pp, CancellationToken cancellationToken)
{
cancellationToken.Register(this.Dispose);
@@ -362,8 +364,7 @@
{
if (this.IsRunning())
{
// var calibrationResult = connection.ViewChamberCalibration();
var calibrationResult = new ChamberCalibrationResponse(response);
var calibrationResult = connection.ViewChamberCalibration();
this.results[pp].Rotations = calibrationResult.Rotations;
this.results[pp].Duration = calibrationResult.Duration;
this.results[pp].MeterVolume = pp.VolumeM3(this.results[pp]);
@@ -3,6 +3,7 @@
using ExchangeHub;
using OmniPlus;
using OmniPlus.Inspection;
using OMNIPruefung.Models;
using OMNIPruefung.ViewModels.Base;
using OMNIPruefung.ViewModels.Options;
@@ -22,11 +23,11 @@
private readonly EOLSettings omnisettings;
private readonly ExchangeHubSettings hubsettings;
private readonly ExchangeConnection exchangeConnection;
private CancellationTokenSource cancellationTokenSource;
private CancellationToken cancellationToken;
private OmniPlusDatabase dbcontext;
private ExchangeConnection signalR;
private ManualResetEventSlim awaiter;
private ICollection<Task> tasks;
private TimersTimer timer;
@@ -35,24 +36,22 @@
public EOLContentVM() : base()
{
this.Header = "EOL";
this.CanStop = false;
this.CanStart = true;
this.Option = new EOLOptionVM(this);
this.Option.OptionSelected += this.NotifyOptionSelected;
this.OmniDefaults = new OmniPlusType();
this.tasks = new List<Task>();
this.omnisettings = new EOLSettings();
this.hubsettings = new ExchangeHubSettings();
this.OmniDefaults = new OmniPlusType();
this.tasks = new List<Task>();
this.exchangeConnection = new ExchangeConnection();
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.PrepareConnections);
this.CancelInspection = new Command(this.CancelInspectionHandler);
this.StartInspection = new Command(this.StartInspectionHandler);
this.Option.OptionSelected += this.NotifyOptionSelected;
this.PrepareConnections();
}
@@ -174,6 +173,8 @@
private void PrepareConnections()
{
this.exchangeConnection.Connect(this.hubsettings.ExchangeHubURL);
if (this.Size == 0 || this.Type is null)
{
this.Error = "Size und Type auswählen!";
@@ -256,9 +257,8 @@
try
{
this.signalR.SendStopReferenceMessurement();
this.signalR.NotifyStopQ();
this.awaiter?.Set();
this.exchangeConnection.Disconnect();
this.awaiter.Set();
this.cancellationTokenSource?.Cancel();
this.tasks.Clear();
@@ -292,26 +292,27 @@
this.InvokeAsync(() =>
{
//this.InvokeAsync((tasks, cancellationToken) =>
//{
// foreach (var meterVM in metersVM)
// {
// tasks.Add(meterVM.SetInputVolumeAsync(this.OmniDefaults, cancellationToken));
// }
//});
var results = new byte[][]
this.InvokeAsync((tasks, cancellationToken) =>
{
new byte[] { 0x01, 0x02, 0x04, 0x00, 0x6F, 0x85, 0x0D, 0x00, 0x01 },
new byte[] { 0x01, 0x02, 0x08, 0x00, 0x4F, 0xFA, 0x11, 0x00, 0x01 },
new byte[] { 0x01, 0x02, 0xE8, 0x03, 0xA1, 0xFB, 0x10, 0x00, 0x02 },
};
foreach (var meterVM in metersVM)
{
tasks.Add(meterVM.SetInputVolumeAsync(this.OmniDefaults, cancellationToken));
}
});
for (int i = 0; i < this.OmniDefaults.TestPoints.Count; i++)
foreach (var pp in this.OmniDefaults.TestPoints)
{
var pp = this.OmniDefaults.TestPoints[i];
if (this.cancellationTokenSource?.IsCancellationRequested == true)
{
break;
}
this.InvokeAsync((tasks, cancellationToken) =>
var rotations = pp.Rotations;
var duration = pp.Duration;
this.StartFlow(pp.VolumeM3H);
this.InvokeAsync((tasks, cancellationToken) =>
{
foreach (var meterVM in metersVM)
{
@@ -319,17 +320,28 @@
}
});
var result = results[i];
this.StartReferenceMessurement(duration);
this.WaitUntil((int)(duration * 1.2), true, false);
var referenceV = this.GetReferenceVolume();
if (this.cancellationTokenSource?.IsCancellationRequested == true)
{
break;
}
this.InvokeAsync((tasks, cancellationToken) =>
{
foreach (var meterVM in metersVM)
{
tasks.Add(meterVM.StopPPCalibrationAsync(pp, result, cancellationToken));
tasks.Add(meterVM.StopPPCalibrationAsync(pp, cancellationToken));
}
});
var referenceV = pp.VolumeM3H * 1;
if (this.cancellationTokenSource?.IsCancellationRequested == true)
{
break;
}
this.InvokeAsync((tasks, cancellationToken) =>
{
@@ -340,60 +352,8 @@
});
}
//foreach (var pp in this.OmniDefaults.TestPoints)
//{
// if (this.cancellationTokenSource?.IsCancellationRequested == true)
// {
// break;
// }
// var rotations = pp.Rotations;
// var duration = pp.Duration;
// this.StartFlow(pp.VolumeM3H);
// this.InvokeAsync((tasks, cancellationToken) =>
// {
// foreach (var meterVM in metersVM)
// {
// tasks.Add(meterVM.StartPPCalibrationAsync(pp, cancellationToken));
// }
// });
// this.StartReferenceMessurement(duration);
// this.WaitUntil((int)(duration * 1.2), true, false);
// var referenceV = this.GetReferenceVolume();
// if (this.cancellationTokenSource?.IsCancellationRequested == true)
// {
// break;
// }
// this.InvokeAsync((tasks, cancellationToken) =>
// {
// foreach (var meterVM in metersVM)
// {
// tasks.Add(meterVM.StopPPCalibrationAsync(pp, cancellationToken));
// }
// });
// if (this.cancellationTokenSource?.IsCancellationRequested == true)
// {
// break;
// }
// this.InvokeAsync((tasks, cancellationToken) =>
// {
// foreach (var meterVM in metersVM)
// {
// tasks.Add(meterVM.SetReferenceVolumeAsync(pp, referenceV, cancellationToken));
// }
// });
//}
//this.signalR.NotifyStopQ();
//this.signalR.NotifyStopRef();
this.exchangeConnection.SendStopReferenceMessurement(default(double));
this.exchangeConnection.SendStopFlow();
this.InvokeAsync((tasks, cancellationToken) =>
{
@@ -474,32 +434,22 @@
this.timer = null;
}
public override void Dispose()
{
foreach (var disposable in this.Nodes.Cast<IDisposable>())
{
disposable.Dispose();
}
this.signalR.Dispose();
}
private void StartFlow(double volumeM3H)
{
var received = false;
var volume = volumeM3H;
var timeout = 120; // seconds
void referenceVolumeReceived(double value)
void referenceVolumeReceived(double value, string _)
{
timeout = -1;
received = true;
volume = value;
}
this.signalR.StartQ += referenceVolumeReceived;
this.exchangeConnection.StartFlow += referenceVolumeReceived;
this.signalR.NotifyStartQ(volumeM3H);
this.exchangeConnection.SendStartFlow(volumeM3H);
this.State = "Warten auf Q(soll) ...";
@@ -516,7 +466,7 @@
timeout--;
this.State = $"{timeout} Sekunden verbleiben bis Q(soll) erreicht";
this.State = $"Warten auf Q({volumeM3H:0.0000}): {timeout} Sekunden verbleiben ...";
}
if (!this.canceled)
@@ -531,16 +481,16 @@
var reference = 0;
var timeout = 30; // seconds
void referenceVolumeReceived(int value)
void referenceVolumeReceived(int seconds, string _)
{
timeout = -1;
received = true;
reference = value;
reference = seconds;
}
this.signalR.StartRef += referenceVolumeReceived;
this.exchangeConnection.StartReferenceMessurement += referenceVolumeReceived;
this.signalR.SendStartReferenceMessurement(duration);
this.exchangeConnection.SendStartReferenceMessurement(duration);
this.State = "Warten bis RZ gestarted ...";
@@ -557,7 +507,7 @@
timeout--;
this.State = $"{timeout} Sekunden verbleiben ...";
this.State = $"Warten bis RZ gestarted: {timeout} Sekunden verbleiben ...";
}
if (!this.canceled)
@@ -572,18 +522,18 @@
var referenceV = 0D;
var timeout = 30; // seconds
void referenceVolumeReceived(double value)
void referenceVolumeReceived(double value, string _)
{
timeout = -1;
received = true;
referenceV = value;
}
this.signalR.StopRef += referenceVolumeReceived;
this.exchangeConnection.StopReferenceMessurement += referenceVolumeReceived;
this.signalR.SendStopReferenceMessurement();
this.exchangeConnection.SendStopReferenceMessurement();
this.State = "Warten RZ Ergebnis ...";
this.State = "Warten RZ-Ergebnis ...";
while (!received && timeout > 0)
{
@@ -598,7 +548,7 @@
timeout--;
this.State = $"{timeout} Sekunden verbleiben ...";
this.State = $"Warten RZ-Ergebnis: {timeout} Sekunden verbleiben ...";
}
@@ -25,8 +25,6 @@
this.Disconnect = new Command(this.DisconnectHubHandler);
this.hubsettings = new ExchangeHubSettings();
this.connection = new ExchangeConnection();
this.connection.OutputDir = this.hubsettings.ExchangeHubOutputDir;
this.connection.StateChanged += this.Connection_StateChanged;
this.NotifyPropertyChanged(nameof(this.LogContent));
}
@@ -57,7 +55,6 @@
set
{
this.hubsettings.ExchangeHubOutputDir = value;
this.connection.OutputDir = value;
this.NotifyPropertyChanged(nameof(this.OutputDir));
}
@@ -88,7 +85,7 @@
{
Task.Factory.StartNew(() =>
{
this.Connected = this.connection.Connect(this.URL);
this.connection.Connect(this.URL);
});
}
@@ -108,7 +105,7 @@
private void DisconnectHubHandler()
{
this.connection.Dispose();
this.connection.Disconnect();
this.Connected = false;
}
}
@@ -53,7 +53,10 @@
private void SetValue(string value)
{
this.bytes.Clear();
for (int i = 0; i < this.bytes.Length; i++)
{
this.bytes[i] = 0;
}
if (!string.IsNullOrWhiteSpace(value))
{
@@ -1,6 +1,6 @@
namespace OmniPlus.Features.Enums
{
public enum Status : byte
public enum Status
{
/// <summary>
/// Used by communication devices to indicate communication failure/timeout.
@@ -1,6 +0,0 @@
namespace OmniPlus.Features
{
internal static class FeatureExtensions
{
}
}
@@ -0,0 +1,113 @@
namespace OmniPlus.Features
{
using System;
internal static class FeaturesExtensions
{
public const int BYTE_BITS = 8;
private static readonly byte[] EmptyArray = new byte[0];
public static byte[] GetBits(this byte value)
{
var bits = new byte[BYTE_BITS];
for (byte i = 0; i < BYTE_BITS; i++)
{
bits[i] = (byte)(value >> i & 1);
}
return bits;
}
public static byte[] GetBits(this byte[] bytes)
{
var bytesL = bytes.Length;
var bitsL = bytesL * BYTE_BITS;
var bits = new byte[bitsL];
for (int i = 0; i < bytesL; i++)
{
for (int b = 0; b < BYTE_BITS; b++)
{
bits[i + b] = (byte)(bytes[i] >> b & 1);
}
}
return bits;
}
public static byte GetUint8(this byte x, int start, int length)
{
var src = x.GetBits();
var dst = new byte[8];
Array.Copy(src, start, dst, 0, length);
return dst.ToUint8();
}
public static byte[] Reverse(this byte[] bytes)
{
var length = bytes.Length / 2;
for (int i = 0; i < length; i++)
{
var last = length - i - 1;
var first = bytes[i];
bytes[i] = bytes[last];
bytes[last] = first;
}
return bytes;
}
public static void SetUint8(this ref byte x, int start, int length, byte value)
{
var src = value.GetBits();
var dst = x.GetBits();
Array.Copy(src, 0, dst, start, length);
x = dst.ToUint8();
}
public static byte[] Subarray(this byte[] bytes, int start, int length)
{
var subarray = EmptyArray;
if (bytes?.Length >= start + length)
{
subarray = new byte[length];
Buffer.BlockCopy(bytes, start, subarray, 0, length);
}
return subarray;
}
public static string ToASCIIString(this byte[] bytes, int start, int length)
{
var asciiString = string.Empty;
while (start >= 0 && start < bytes.Length)
{
asciiString += (char)bytes[start++];
}
return asciiString;
}
public static byte ToUint8(this byte[] bits)
{
var sum = default(byte);
for (byte i = 0; i < bits.Length; i++)
{
sum ^= (byte)(bits[i] << i);
}
return sum;
}
}
}
@@ -53,13 +53,13 @@
public byte FlowUnits
{
get => this.bytes[8].GetUint8(0, 4);
set => OmniPlusExtensions.SetUint8(ref this.bytes[8], 0, 4, value);
set => FeaturesExtensions.SetUint8(ref this.bytes[8], 0, 4, value);
}
public byte FlowRate
{
get => this.bytes[8].GetUint8(4, 4);
set => OmniPlusExtensions.SetUint8(ref this.bytes[8], 4, 4, value);
set => FeaturesExtensions.SetUint8(ref this.bytes[8], 4, 4, value);
}
public sbyte FactoryCorrection
@@ -83,13 +83,13 @@
public byte PulseWidth
{
get => this.bytes[12].GetUint8(0, 3);
set => OmniPlusExtensions.SetUint8(ref this.bytes[12], 0, 3, value);
set => FeaturesExtensions.SetUint8(ref this.bytes[12], 0, 3, value);
}
public byte PulseUpdate
{
get => this.bytes[12].GetUint8(3, 3);
set => OmniPlusExtensions.SetUint8(ref this.bytes[12], 3, 3, value);
set => FeaturesExtensions.SetUint8(ref this.bytes[12], 3, 3, value);
}
}
}
@@ -37,46 +37,5 @@
return double.MaxValue;
}
public static byte[] GetBits(this byte value)
{
var bits = new byte[BYTE_BITS];
for (byte i = 0; i < BYTE_BITS; i++)
{
bits[i] = (byte)(value >> i & 1);
}
return bits;
}
public static byte[] GetBits(this byte[] bytes)
{
var bytesL = bytes.Length;
var bitsL = bytesL * BYTE_BITS;
var bits = new byte[bitsL];
for (int i = 0; i < bytesL; i++)
{
for (int b = 0; b < BYTE_BITS; b++)
{
bits[i + b] = (byte)(bytes[i] >> b & 1);
}
}
return bits;
}
public static byte ToUint8(this byte[] bits)
{
var sum = default(byte);
for (byte i = 0; i < bits.Length; i++)
{
sum ^= (byte)(bits[i] << i);
}
return sum;
}
}
}
@@ -0,0 +1,45 @@
namespace OmniPlus.Inspection
{
using System;
public static class OmniPlusFormulas
{
public static double MlPerRotation(byte intPart, ushort fraction, short correctionFactor)
{
return (intPart + (double)fraction / ushort.MaxValue) * correctionFactor;
}
public static double GPM2M3H(double value)
{
return value * 3785.411784 / 1000 / 1000 * 60;
}
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];
if (Math.Abs(mid - max) <= 3 && Math.Max(mid, max) - min <= 6.5)
{
var avgMidMax = (mid + max) / 2;
if (100 - avgMidMax + min < 95)
{
return 95 - min;
}
else
{
return 100 - avgMidMax;
}
}
return double.MaxValue;
}
}
}
+2 -1
View File
@@ -77,7 +77,7 @@
<Compile Include="Features\Epoch20000101.cs" />
<Compile Include="Features\FactoryID.cs" />
<Compile Include="Features\FactorySeal.cs" />
<Compile Include="Features\FeatureExtensions.cs" />
<Compile Include="Features\FeaturesExtensions.cs" />
<Compile Include="Features\Features.cs" />
<Compile Include="Features\FeatureRequest.cs" />
<Compile Include="Features\FeatureResponse.cs" />
@@ -97,6 +97,7 @@
<Compile Include="Features\SystemParameters.cs" />
<Compile Include="Features\SystemTime.cs" />
<Compile Include="Features\VersionAndType.cs" />
<Compile Include="Inspection\OmniPlusFormulas.cs" />
<Compile Include="OmniPlusConnection.cs" />
<Compile Include="OmniPlusDatabase.cs" />
<Compile Include="Inspection\OmniPlusExtensions.cs" />