omni_plus progress
This commit is contained in:
@@ -55,13 +55,13 @@ namespace OmniPlus.Features
|
||||
public byte FlowUnits
|
||||
{
|
||||
get => this.bytes[8].GetUint8(0, 4);
|
||||
set => this.bytes[8].SetUint8(0, 4, value);
|
||||
set => OmniPlusExtensions.SetUint8(ref this.bytes[8], 0, 4, value);
|
||||
}
|
||||
|
||||
public byte FlowRate
|
||||
{
|
||||
get => this.bytes[8].GetUint8(4, 4);
|
||||
set => this.bytes[8].SetUint8(4, 4, value);
|
||||
set => OmniPlusExtensions.SetUint8(ref this.bytes[8], 4, 4, value);
|
||||
}
|
||||
|
||||
public sbyte FactoryCorrection
|
||||
@@ -85,13 +85,13 @@ namespace OmniPlus.Features
|
||||
public byte PulseWidth
|
||||
{
|
||||
get => this.bytes[12].GetUint8(0, 3);
|
||||
set => this.bytes[12].SetUint8(0, 3, value);
|
||||
set => OmniPlusExtensions.SetUint8(ref this.bytes[12], 0, 3, value);
|
||||
}
|
||||
|
||||
public byte PulseUpdate
|
||||
{
|
||||
get => this.bytes[12].GetUint8(3, 3);
|
||||
set => this.bytes[12].SetUint8(3, 3, value);
|
||||
set => OmniPlusExtensions.SetUint8(ref this.bytes[12], 3, 3, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>OmniPlus</RootNamespace>
|
||||
<AssemblyName>OmniPlus</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<Deterministic>true</Deterministic>
|
||||
<TargetFrameworkProfile />
|
||||
@@ -90,6 +90,7 @@
|
||||
<Compile Include="Hanlers\StateChangedHandler.cs" />
|
||||
<Compile Include="OmniPlusConnectionsPool.cs" />
|
||||
<Compile Include="OmniPlusDatabase.cs" />
|
||||
<Compile Include="OmniPlusExchange.cs" />
|
||||
<Compile Include="OmniPlusExtensions.cs" />
|
||||
<Compile Include="OmniPlusConstants.cs" />
|
||||
<Compile Include="OmniPlusTest.cs" />
|
||||
|
||||
@@ -4,6 +4,8 @@ using OmniPlus.Features;
|
||||
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.ComponentModel;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@@ -11,8 +13,39 @@ using static OmniPlus.OmniPlusConstants;
|
||||
|
||||
namespace OmniPlus
|
||||
{
|
||||
public class OmniPlusConnectionsPool : IDisposable
|
||||
[Guid("B5979B1D-26D0-46E5-816A-5CF7CABF8899")]
|
||||
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
|
||||
public interface IOmniPlusConnectionsEvents
|
||||
{
|
||||
[DispId(1)]
|
||||
void GetV(double value);
|
||||
|
||||
[DispId(2)]
|
||||
void SetQ(double value);
|
||||
|
||||
[DispId(3)]
|
||||
void StateChanged(int column, int succeeded, string header, string value);
|
||||
}
|
||||
|
||||
[Guid("88B0CC86-4C61-4996-A9CA-BD413BEEBCFF")]
|
||||
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
|
||||
public interface IOmniPlusConnectionsPool : IDisposable
|
||||
{
|
||||
[DispId(1)]
|
||||
void InitializeInspection(params string[] portNames);
|
||||
|
||||
[DispId(2)]
|
||||
void StartInspection();
|
||||
}
|
||||
|
||||
[ComSourceInterfaces(typeof(IOmniPlusConnectionsEvents))]
|
||||
[ClassInterface(ClassInterfaceType.None)]
|
||||
[Guid("82BBFC66-E75F-4658-87BD-7CA85F213654")]
|
||||
[ProgId("OmniPlus.OmniPlusConnectionsPool")]
|
||||
public class OmniPlusConnectionsPool : IOmniPlusConnectionsPool
|
||||
{
|
||||
public event DoubleEventHandler GetV;
|
||||
public event DoubleEventHandler SetQ;
|
||||
public event OmniPlusStateChanged StateChanged;
|
||||
|
||||
private readonly ConcurrentDictionary<int, OmniPlusConnection> connections;
|
||||
@@ -22,6 +55,7 @@ namespace OmniPlus
|
||||
|
||||
private byte size;
|
||||
private string variant;
|
||||
private BackgroundWorker background;
|
||||
|
||||
public OmniPlusConnectionsPool(string dbConnectionString)
|
||||
{
|
||||
@@ -41,7 +75,7 @@ namespace OmniPlus
|
||||
{
|
||||
connectionKVP.Value?.Disconnect();
|
||||
|
||||
this.StateChanged?.Invoke(connectionKVP.Key, false, CONNECTED, X);
|
||||
this.StateChanged?.Invoke(connectionKVP.Key, -1, CONNECTED, X);
|
||||
}
|
||||
|
||||
// Clears collected connections and their meters.
|
||||
@@ -92,8 +126,8 @@ namespace OmniPlus
|
||||
this.meters.TryAdd(position, meter);
|
||||
this.connections.TryAdd(position, connection);
|
||||
|
||||
this.StateChanged?.Invoke(position, true, SLOT_NR, position.ToString());
|
||||
this.StateChanged?.Invoke(position, connected ? true : default(bool?), CONNECTED, connected ? OK : null);
|
||||
this.StateChanged?.Invoke(position, 1, SLOT_NR, position.ToString());
|
||||
this.StateChanged?.Invoke(position, connected ? 1 : -1, CONNECTED, connected ? OK : null);
|
||||
|
||||
position++;
|
||||
}
|
||||
@@ -101,7 +135,22 @@ namespace OmniPlus
|
||||
this.database.LoadOmniPlusType(this.size, this.variant, this.omniType);
|
||||
}
|
||||
|
||||
public void NotifyQ(double q)
|
||||
=> this.SetQ?.Invoke(q);
|
||||
|
||||
public void NotifyV(double v)
|
||||
=> this.GetV?.Invoke(v);
|
||||
|
||||
public void StartInspection()
|
||||
{
|
||||
this.background = new BackgroundWorker();
|
||||
|
||||
this.background.DoWork += this.StartInspection;
|
||||
|
||||
this.background.RunWorkerAsync();
|
||||
}
|
||||
|
||||
private void StartInspection(object sender, EventArgs args)
|
||||
{
|
||||
var connectionsCount = this.connections.Count;
|
||||
var tasks = new Task[connectionsCount];
|
||||
@@ -115,7 +164,7 @@ namespace OmniPlus
|
||||
|
||||
foreach (var point in this.omniType.TestPoints)
|
||||
{
|
||||
// TODO: Request and wait for flow.
|
||||
this.SetM3(point.VolumeM3H);
|
||||
|
||||
tasks = new Task[connectionsCount];
|
||||
|
||||
@@ -126,8 +175,7 @@ namespace OmniPlus
|
||||
|
||||
tasks.ContinueWhenAll();
|
||||
|
||||
// TODO: Request and wait for volume.
|
||||
var volumeMessured = 0.1D;
|
||||
var volumeMessured = this.GetM3();
|
||||
|
||||
foreach (var position in this.connections.Keys)
|
||||
{
|
||||
@@ -154,8 +202,8 @@ namespace OmniPlus
|
||||
{
|
||||
if (this.TryGetOmni(position, out var connection, out var meter))
|
||||
{
|
||||
this.StateChanged?.Invoke(position, null, FIRMWARE, TBD);
|
||||
this.StateChanged?.Invoke(position, null, BUILD_INFO, TBD);
|
||||
this.StateChanged?.Invoke(position, 0, FIRMWARE, TBD);
|
||||
this.StateChanged?.Invoke(position, 0, BUILD_INFO, TBD);
|
||||
|
||||
var systemParameters = connection.ViewSystemParameters();
|
||||
meter.AddSystemParameters(systemParameters);
|
||||
@@ -167,13 +215,13 @@ namespace OmniPlus
|
||||
|
||||
meter.CanCalibrate = connection.SetInputVolume(this.omniType.InputVolume).Succeeded;
|
||||
|
||||
this.StateChanged?.Invoke(position, meter.FirmwareInRange, FIRMWARE, meter.Firmware);
|
||||
this.StateChanged?.Invoke(position, !string.IsNullOrWhiteSpace(meter.BuildInfo), BUILD_INFO, meter.BuildInfo);
|
||||
this.StateChanged?.Invoke(position, meter.FirmwareInRange ? 1 : -1, FIRMWARE, meter.Firmware);
|
||||
this.StateChanged?.Invoke(position, !string.IsNullOrWhiteSpace(meter.BuildInfo) ? 1 : -1, BUILD_INFO, meter.BuildInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.StateChanged?.Invoke(position, null, FIRMWARE, null);
|
||||
this.StateChanged?.Invoke(position, null, BUILD_INFO, null);
|
||||
this.StateChanged?.Invoke(position, 0, FIRMWARE, null);
|
||||
this.StateChanged?.Invoke(position, 0, BUILD_INFO, null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -183,7 +231,7 @@ namespace OmniPlus
|
||||
|
||||
if (this.TryGetOmni(position, out var connection, out var meter) && meter.Initialized && meter.CanCalibrate)
|
||||
{
|
||||
this.StateChanged?.Invoke(position, null, header, TBD);
|
||||
this.StateChanged?.Invoke(position, 0, header, TBD);
|
||||
|
||||
var activationResponse = connection.StartChamberCalibration(point.Rotations, point.Duration);
|
||||
|
||||
@@ -208,27 +256,27 @@ namespace OmniPlus
|
||||
|
||||
if (!calibrationResult.Succeeded)
|
||||
{
|
||||
this.StateChanged?.Invoke(position, false, header, $"CC: {calibrationResult.Status}");
|
||||
this.StateChanged?.Invoke(position, -1, header, $"CC: {calibrationResult.Status}");
|
||||
}
|
||||
else if (calibrationResult.Control != ChamberCalibrationResponse.TEST_COMPLETED)
|
||||
{
|
||||
this.StateChanged?.Invoke(position, false, header, $"CC: {calibrationResult.Control}");
|
||||
this.StateChanged?.Invoke(position, -1, header, $"CC: {calibrationResult.Control}");
|
||||
}
|
||||
else // process calibration
|
||||
{
|
||||
var volume = meter.AddCalibrationResult(point, calibrationResult);
|
||||
|
||||
this.StateChanged?.Invoke(position, null, header, $"{volume:0.0000}m³");
|
||||
this.StateChanged?.Invoke(position, 0, header, $"{volume:0.0000}m³");
|
||||
}
|
||||
}
|
||||
else // activation failed
|
||||
{
|
||||
this.StateChanged?.Invoke(position, false, header, $"AC: {activationResponse.Status}");
|
||||
this.StateChanged?.Invoke(position, -1, header, $"AC: {activationResponse.Status}");
|
||||
}
|
||||
}
|
||||
else // not connected
|
||||
{
|
||||
this.StateChanged?.Invoke(position, null, header, null);
|
||||
this.StateChanged?.Invoke(position, 0, header, null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -240,11 +288,11 @@ namespace OmniPlus
|
||||
{
|
||||
var difference = meter.AddCalibrationVolume(point, volume);
|
||||
|
||||
this.StateChanged?.Invoke(position, null, header, $"{difference:0.00}%");
|
||||
this.StateChanged?.Invoke(position, 0, header, $"{difference:0.00}%");
|
||||
}
|
||||
else // not connected
|
||||
{
|
||||
this.StateChanged?.Invoke(position, null, header, null);
|
||||
this.StateChanged?.Invoke(position, 0, header, null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -254,11 +302,11 @@ namespace OmniPlus
|
||||
{
|
||||
var correctionFactor = meter.GetCorrectionFactor();
|
||||
|
||||
this.StateChanged?.Invoke(position, meter.CanCalibrate, CORRECTION, $"{correctionFactor:0.00}%");
|
||||
this.StateChanged?.Invoke(position, meter.CanCalibrate ? 1 : -1, CORRECTION, $"{correctionFactor:0.00}%");
|
||||
}
|
||||
else // not connected
|
||||
{
|
||||
this.StateChanged?.Invoke(position, null, CORRECTION, null);
|
||||
this.StateChanged?.Invoke(position, 0, CORRECTION, null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -277,8 +325,8 @@ namespace OmniPlus
|
||||
|
||||
if (canContinue)
|
||||
{
|
||||
var systemTimeReset = connection.SetSystemTime();
|
||||
canContinue = systemTimeReset.Succeeded;
|
||||
//var systemTimeReset = connection.SetSystemTime();
|
||||
//canContinue = systemTimeReset.Succeeded;
|
||||
}
|
||||
|
||||
if (canContinue)
|
||||
@@ -343,7 +391,7 @@ namespace OmniPlus
|
||||
};
|
||||
timer.Elapsed += (_, _1) =>
|
||||
{
|
||||
this.StateChanged?.Invoke(position, null, header, $"{seconds++}/{duration}");
|
||||
this.StateChanged?.Invoke(position, 0, header, $"{seconds++}/{duration}");
|
||||
};
|
||||
|
||||
timer.Start();
|
||||
@@ -352,5 +400,59 @@ namespace OmniPlus
|
||||
|
||||
timer.Stop();
|
||||
}
|
||||
|
||||
private bool SetM3(double volumeM3)
|
||||
{
|
||||
var received = false;
|
||||
var wait = 60000;
|
||||
var sleep = 1000;
|
||||
|
||||
void setm3(double v)
|
||||
{
|
||||
received = v >= 0;
|
||||
}
|
||||
|
||||
this.SetQ += setm3;
|
||||
this.SetQ?.Invoke(volumeM3);
|
||||
|
||||
while (!received && wait >= 0)
|
||||
{
|
||||
Thread.Sleep(sleep);
|
||||
|
||||
wait -= sleep;
|
||||
}
|
||||
|
||||
this.SetQ -= setm3;
|
||||
|
||||
return received;
|
||||
}
|
||||
|
||||
private double GetM3()
|
||||
{
|
||||
var value = default(double);
|
||||
var received = false;
|
||||
var wait = 60000;
|
||||
var sleep = 1000;
|
||||
|
||||
void getm3(double v)
|
||||
{
|
||||
value = v;
|
||||
received = true;
|
||||
}
|
||||
|
||||
this.GetV += getm3;
|
||||
this.GetV?.Invoke(0);
|
||||
|
||||
while (!received && wait >= 0)
|
||||
{
|
||||
Thread.Sleep(sleep);
|
||||
|
||||
wait -= sleep;
|
||||
}
|
||||
|
||||
this.GetV -= getm3;
|
||||
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
USE [AuftragKopie];
|
||||
|
||||
IF OBJECT_ID(N'OmniTestStates') IS NOT NULL BEGIN DROP TABLE [OmniTestStates] END
|
||||
IF OBJECT_ID(N'OmniTestPoints') IS NOT NULL BEGIN DROP TABLE [OmniTestPoints] END
|
||||
IF OBJECT_ID(N'OmniTestTypes') IS NOT NULL BEGIN DROP TABLE [OmniTestTypes] END
|
||||
IF OBJECT_ID(N'OmniTestStates') IS NOT NULL DROP TABLE [OmniTestStates];
|
||||
IF OBJECT_ID(N'OmniTestPoints') IS NOT NULL DROP TABLE [OmniTestPoints];
|
||||
IF OBJECT_ID(N'OmniTestTypes') IS NOT NULL DROP TABLE [OmniTestTypes];
|
||||
|
||||
CREATE TABLE [OmniTestTypes] (
|
||||
[Id] TINYINT NOT NULL IDENTITY(1, 1),
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
namespace OmniPlus
|
||||
{
|
||||
public delegate void DoubleEventHandler(double value);
|
||||
}
|
||||
@@ -357,7 +357,7 @@ namespace OmniPlus
|
||||
return sum;
|
||||
}
|
||||
|
||||
public static byte GetUint8(this ref byte x, int start, int length)
|
||||
public static byte GetUint8(this byte x, int start, int length)
|
||||
{
|
||||
var src = x.GetBits();
|
||||
var dst = new byte[8];
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace OmniPlus
|
||||
{
|
||||
public delegate void OmniPlusStateChanged(int column, bool? succeeded, string header, string value);
|
||||
public delegate void OmniPlusStateChanged(int column, int succeeded, string header, string value);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user