2171 lines
78 KiB
C#
2171 lines
78 KiB
C#
using ByteArrayStyle;
|
|
using Newtonsoft.Json;
|
|
using NLog;
|
|
using System;
|
|
using System.Collections.Concurrent;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Diagnostics;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Runtime.InteropServices;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using Xylem.Common.CommonCore.Configuration;
|
|
using Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore;
|
|
using Xylem.Common.Hardware.WaterMeter.Genesis.Registers;
|
|
using Xylem.Common.Hardware.WaterMeter.WaterMeterCore;
|
|
using Xylem.Common.Logic.SoftwareAccessHelper;
|
|
using Xylem.Common.Metrology.Measurements;
|
|
using Xylem.Common.Metrology.Measurements.Consts;
|
|
using Xylem.Common.Utils.Logging;
|
|
using XylemCommonUiLegacyGenCtl.DataPackage;
|
|
using XylemCommonUiLegacyGenCtl.Enums;
|
|
|
|
namespace XylemCommonUiLegacyGenCtl
|
|
{
|
|
[Guid("034A00BD-AAAA-4DF7-97F3-43D0CBF8A805"),
|
|
ComVisible(true),
|
|
ClassInterface(ClassInterfaceType.None),
|
|
ComSourceInterfaces(typeof(ICtlBatch))]
|
|
public partial class ctlBatch : UserControl, ICtlBatch
|
|
{
|
|
#region Const Layout
|
|
|
|
private const Int32 LblPositionLeft = 5;
|
|
private const Int32 LblPositionTop = 20;
|
|
private const Int32 LblPositionSize = 70;
|
|
private const Int32 LblPositionHeight = 70;
|
|
private const Int32 LblPositionSpace = 15;
|
|
private const Int32 SizeOfMeter = 140;
|
|
|
|
#endregion
|
|
#region Prop
|
|
private enum Mode
|
|
{
|
|
AutoRefresh,
|
|
View,
|
|
}
|
|
|
|
/// <summary>
|
|
/// State for state machine
|
|
/// </summary>
|
|
private enum BatchState
|
|
{
|
|
Idle,
|
|
Init,
|
|
Error,
|
|
PrepareGui,
|
|
PrepareMeasurement,
|
|
MeasurementActive,
|
|
MeasurementCompleted
|
|
}
|
|
|
|
private BatchState _currentState;
|
|
private BatchState _backupState;
|
|
private Mode currentMode = Mode.View;
|
|
private ILogger _logger;
|
|
private Dictionary<Int32, LegacyCalibrationResult> CalibrationIsDone = new Dictionary<Int32, LegacyCalibrationResult>();
|
|
public MeterBatch batch;
|
|
//private System.Windows.Forms.Timer RefreshTimer = new System.Windows.Forms.Timer();
|
|
//private System.Windows.Forms.Timer RefreshTimerWatch = new System.Windows.Forms.Timer();
|
|
|
|
private GenesisMeter.Alarm TestBenchRelatedAlarms = GenesisMeter.Alarm.EMPTY_PIPE &
|
|
GenesisMeter.Alarm.REBOOT &
|
|
GenesisMeter.Alarm.HIGH_PRESSURE &
|
|
GenesisMeter.Alarm.HIGH_TEMPERATURE &
|
|
GenesisMeter.Alarm.LOW_PRESSURE &
|
|
GenesisMeter.Alarm.LOW_TEMPERATURE;
|
|
|
|
private ConcurrentDictionary<Int32, GenesisMeter.Alarm> WarningMetersAlarms = new ConcurrentDictionary<Int32, GenesisMeter.Alarm>();
|
|
private ConcurrentDictionary<Int32, GenesisMeter.Alarm> ErrorMetersAlarms = new ConcurrentDictionary<Int32, GenesisMeter.Alarm>();
|
|
|
|
public String MeterDn = "-";
|
|
public Double RefPulseValence;
|
|
public Double PredictedQFlow;
|
|
public Double PredictedTs;
|
|
public Double RefError;
|
|
|
|
public Int32 CurrentPulse;
|
|
public Double CurrentRefVolume;
|
|
public Int32 RemainingPulse;
|
|
public String Period = "-";
|
|
public Double RefFlowrate;
|
|
public Double RefTestTime;
|
|
public Double RefFlowUncorrected;
|
|
|
|
public Double MeterDefaultCorrection;
|
|
|
|
private TestSetupContainer TestSetupContainer;
|
|
|
|
|
|
private DataTable dtBatch;
|
|
#region busy
|
|
public Boolean IsBusy { get; private set; }
|
|
|
|
private Int32? ProgressTotal;
|
|
private Int32? ProgressCurrent;
|
|
|
|
private Dictionary<Int32, Double> slotErrorFrameDic = new Dictionary<Int32, Double>();
|
|
private Dictionary<Int32, String> slotLut = new Dictionary<Int32, String>();
|
|
private Dictionary<Int32, Boolean> slotPreadjustment = new Dictionary<Int32, Boolean>();
|
|
private Dictionary<String, Tuple<Label, String>> labelValueCollection;
|
|
|
|
public Boolean IsFlyingStartStop { get; private set; }
|
|
|
|
|
|
private Double StoreRefVolume, StoreTestTimeRef;
|
|
private Stopwatch stopWatch = new Stopwatch();
|
|
private Dictionary<Int32, String> rowIndex = new Dictionary<Int32, String>();
|
|
#endregion
|
|
#endregion
|
|
#region ctor
|
|
public ctlBatch()
|
|
{
|
|
|
|
_logger = NLogHelper.CreateOrGetMultiLogger("ctlBatch", "", "Batch", "", "");
|
|
_logger.Info($"start construct ctlBatch");
|
|
//RefreshTimerWatch.Enabled = true;
|
|
//RefreshTimerWatch.Interval = 5000;
|
|
//RefreshTimerWatch.Tick += RefreshTimerWatch_Tick;
|
|
InitializeComponent();
|
|
labelValueCollection = new Dictionary<String, Tuple<Label, String>>();
|
|
InitLabelValueCollection();
|
|
|
|
grbInfo.SuspendLayout();
|
|
SuspendLayout();
|
|
Disposed += CtlBatch_Disposed;
|
|
//kick off the state machine
|
|
_currentState = BatchState.Init;
|
|
_backupState = BatchState.Idle;
|
|
_logger.Info($"construct ctlBatch end");
|
|
}
|
|
|
|
|
|
private void CtlBatch_Disposed(Object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
base.Dispose();
|
|
Close();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.Error(ex, $"error at CtlBatch_Disposed");
|
|
}
|
|
}
|
|
#endregion
|
|
#region StateMachine
|
|
/// <summary>
|
|
/// State machine for control batch
|
|
/// </summary>
|
|
/// <remarks date="2021-Feb-16" author="Thomas Wiedebusch">
|
|
/// - Initial.
|
|
/// </remarks>
|
|
private void CtlBatchStateMachine()
|
|
{
|
|
if (_currentState == _backupState)
|
|
{
|
|
Thread.Sleep(1);
|
|
}
|
|
else
|
|
{
|
|
// this loop calls the function and assigns the return states on success and error
|
|
// remind backup state to avoid repeated execution and side effects
|
|
_backupState = _currentState;
|
|
switch (_currentState)
|
|
{
|
|
case BatchState.Idle:
|
|
break;
|
|
|
|
case BatchState.Init:
|
|
break;
|
|
|
|
case BatchState.Error:
|
|
break;
|
|
|
|
case BatchState.PrepareGui:
|
|
break;
|
|
|
|
case BatchState.PrepareMeasurement:
|
|
break;
|
|
|
|
case BatchState.MeasurementActive:
|
|
break;
|
|
|
|
case BatchState.MeasurementCompleted:
|
|
break;
|
|
|
|
default:
|
|
_currentState = BatchState.Idle;
|
|
break;
|
|
|
|
}
|
|
}// lock repeated execution of identical state
|
|
}
|
|
#endregion
|
|
|
|
#region busy
|
|
|
|
private void setBusy(Boolean val, String action = "", Boolean hideToExternal = false)
|
|
{
|
|
try
|
|
{
|
|
if (!hideToExternal)
|
|
{
|
|
IsBusy = val;
|
|
}
|
|
|
|
if (val)
|
|
{
|
|
TryInvoke(new Action(() =>
|
|
{
|
|
pnlBussy.Visible = true;
|
|
timProgress.Enabled = true;
|
|
lblAction.Text = action;
|
|
pnlBussy.Size = Size;
|
|
pnlBussy.Location = new Point(0, 0);
|
|
|
|
|
|
lblAction.Left = (ClientSize.Width - lblAction.Width) / 2;
|
|
lblAction.Top = ((ClientSize.Height - lblAction.Height) / 2) - (lblBussyHealine.Height * 4);
|
|
lblBussyHealine.Left = (ClientSize.Width - lblBussyHealine.Width) / 2;
|
|
lblBussyHealine.Top = (ClientSize.Height - lblBussyHealine.Height) / 2 - (lblBussyHealine.Height * 2);
|
|
|
|
|
|
}));
|
|
|
|
}
|
|
else
|
|
{
|
|
ProgressTotal = null;
|
|
ProgressCurrent = null;
|
|
TryInvoke(new Action(() => { pnlBussy.Visible = false; timProgress.Enabled = false; lblAction.Text = action; lblProgress.Text = ""; }));
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.Error(ex, $"error at setBusy(val={val},action={action}");
|
|
}
|
|
}
|
|
private void setProgress(String text, Int32 total = 0, Int32 current = 0)
|
|
{
|
|
try
|
|
{
|
|
ProgressTotal = total;
|
|
ProgressCurrent = current;
|
|
TryInvoke(new Action(() => { lblProgress.Text = $@"{text} ({current}/{total})"; }));
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.Error(ex, $"error at setProgress(text={text},total={total},current={current}");
|
|
}
|
|
|
|
|
|
}
|
|
|
|
private Boolean AvoidDisposedTimer(Object sender)
|
|
{
|
|
if (Disposing || Disposing)
|
|
{
|
|
if (sender is System.Windows.Forms.Timer)
|
|
{
|
|
((System.Windows.Forms.Timer)(sender)).Enabled = false;
|
|
((System.Windows.Forms.Timer)(sender)).Dispose();
|
|
}
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
private void timProgress_Tick(Object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
CtlBatchStateMachine();
|
|
if (AvoidDisposedTimer(sender))
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (IsBusy)
|
|
{
|
|
if (ProgressTotal.HasValue && ProgressCurrent.HasValue && !ProgressTotal.Value.Equals(0) && !ProgressCurrent.Value.Equals(0))
|
|
{
|
|
try
|
|
{
|
|
TryInvoke(new Action(() => { probarBusy.Value = (Int32)Math.Round(
|
|
ProgressCurrent.Value / (Double)ProgressTotal.Value * 100, 0); }));
|
|
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
_logger.Error(exception, @"Timer routine progress");
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
var current = probarBusy.Value;
|
|
if (current + 1 > 100)
|
|
{
|
|
current = 0;
|
|
}
|
|
TryInvoke(new Action(() => { probarBusy.Value = current + 1; }));
|
|
}
|
|
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.Error(ex, "timProgress_Tick");
|
|
}
|
|
}
|
|
#endregion
|
|
#region refresh
|
|
private void RefreshTimerWatch_Tick(Object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
if (AvoidDisposedTimer(sender))
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (currentMode == Mode.AutoRefresh)
|
|
{
|
|
|
|
TryInvoke(new Action(() => { pgbUpdate.Visible = true; }));
|
|
|
|
if (stopWatch != null && stopWatch.IsRunning)
|
|
{
|
|
var progress = (Int32)(stopWatch.ElapsedMilliseconds);
|
|
progress = progress > pgbUpdate.Maximum ? pgbUpdate.Maximum : progress;
|
|
|
|
TryInvoke(new Action(() => { pgbUpdate.Value = progress; }));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
|
|
TryInvoke(new Action(() => { pgbUpdate.Visible = false; }));
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.Error(ex, $"error at RefreshTimerWatch_Tick()");
|
|
}
|
|
|
|
}
|
|
|
|
private void RefreshTimer_Tick(Object sender, EventArgs e)
|
|
{
|
|
|
|
|
|
//try
|
|
//{
|
|
// if (this.AvoidDisposedTimer(sender))
|
|
// return;
|
|
// this.UpdateBatch();
|
|
//}
|
|
//catch (Exception ex)
|
|
//{
|
|
// _logger.Error(ex, $"error at RefreshTimer_Tick()");
|
|
//}
|
|
}
|
|
|
|
private void updateTotalProgress(Double refTestTime)
|
|
{
|
|
try
|
|
{
|
|
if (PredictedTs > 0 && refTestTime > 0)
|
|
{
|
|
var timeLeft = PredictedTs - refTestTime;
|
|
|
|
TryInvoke(new Action(() =>
|
|
{
|
|
lblEndTime.Text = DateTime.Now.AddSeconds(timeLeft).ToString("HH:mm:ss");
|
|
pgbEndTime.Value = (Int32)refTestTime >= pgbEndTime.Maximum ? pgbEndTime.Maximum : (Int32)refTestTime;
|
|
pnlEndTime.Visible = true;
|
|
}));
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.Error(ex, $"error at updateTotalProgress(refTestTime={refTestTime}");
|
|
}
|
|
|
|
}
|
|
|
|
#endregion
|
|
#region infoLables
|
|
|
|
private void InitLabelValueCollection()
|
|
{
|
|
AddInfoLabels("MeterDn", "MID", 0, MeterDn);
|
|
AddInfoLabels("PulseValence", "Impulswertigkeit", 1, doubleToStringFormat(RefPulseValence));
|
|
AddInfoLabels("PredictedQFlow", "Q soll[m³/ h]", 2, doubleToStringFormat(PredictedQFlow, 6));
|
|
AddInfoLabels("PredictedTs", "T soll[s]", 3, doubleToStringFormat(PredictedTs, 1));
|
|
AddInfoLabels("RefError", "RZ Fehler[%]", 4, doubleToStringFormat(RefError, 3));
|
|
AddInfoLabels("CurrentPulse", "Impulse", 6, CurrentPulse.ToString());
|
|
AddInfoLabels("CurrentRefVolume", "RZ Volumen m³", 7, doubleToStringFormat(CurrentRefVolume, 6));
|
|
AddInfoLabels("RemainingPulse", "Verbleib.Imp", 8, RemainingPulse.ToString());
|
|
AddInfoLabels("Period", "Periodendauer", 9, Period);
|
|
AddInfoLabels("RefFlow", "Ref Q", 11, doubleToStringFormat(RefFlowrate, 6));
|
|
AddInfoLabels("RefFlowUncorrected", "unkor. Ref Q", 12, doubleToStringFormat(RefFlowUncorrected, 6));
|
|
}
|
|
private void AddInfoLabels(String name, String text, Int32 index, String value)
|
|
{
|
|
|
|
var tmpLblText = new Label();
|
|
var tmpLblValue = new Label();
|
|
grbInfo.Controls.Add(tmpLblText);
|
|
grbInfo.Controls.Add(tmpLblValue);
|
|
|
|
tmpLblText.AutoSize = true;
|
|
tmpLblText.Location = new Point(LblPositionLeft, LblPositionTop * (index + 1));
|
|
tmpLblText.Name = $"lblInfo{name}text";
|
|
tmpLblText.Size = new Size(LblPositionSize, LblPositionHeight);
|
|
tmpLblText.TabIndex = index;
|
|
tmpLblText.Text = text;
|
|
|
|
tmpLblValue.AutoSize = true;
|
|
tmpLblValue.Location = new Point(LblPositionLeft + LblPositionSize + LblPositionSpace,
|
|
LblPositionTop * (index + 1));
|
|
tmpLblValue.Name = $"lblInfo{name}value";
|
|
tmpLblValue.Size = new Size(LblPositionSize, LblPositionHeight);
|
|
tmpLblValue.TabIndex = index + 1;
|
|
tmpLblValue.Text = value;
|
|
|
|
|
|
labelValueCollection.Add(name, new Tuple<Label, String>(tmpLblValue, value));
|
|
|
|
|
|
}
|
|
public void updateLabelCollection()
|
|
{
|
|
|
|
labelValueCollection["MeterDn"] = new Tuple<Label, String>(labelValueCollection["MeterDn"].Item1, MeterDn);
|
|
labelValueCollection["PulseValence"] =
|
|
new Tuple<Label, String>(labelValueCollection["PulseValence"].Item1, doubleToStringFormat(RefPulseValence));
|
|
labelValueCollection["PredictedQFlow"] =
|
|
new Tuple<Label, String>(labelValueCollection["PredictedQFlow"].Item1, doubleToStringFormat(PredictedQFlow, 6));
|
|
labelValueCollection["PredictedTs"] =
|
|
new Tuple<Label, String>(labelValueCollection["PredictedTs"].Item1, doubleToStringFormat(PredictedTs, 1));
|
|
labelValueCollection["RefError"] =
|
|
new Tuple<Label, String>(labelValueCollection["RefError"].Item1, doubleToStringFormat(RefError, 3));
|
|
labelValueCollection["CurrentPulse"] =
|
|
new Tuple<Label, String>(labelValueCollection["CurrentPulse"].Item1, CurrentPulse.ToString());
|
|
labelValueCollection["CurrentRefVolume"] =
|
|
new Tuple<Label, String>(labelValueCollection["CurrentRefVolume"].Item1, doubleToStringFormat(CurrentRefVolume, 6));
|
|
labelValueCollection["RemainingPulse"] =
|
|
new Tuple<Label, String>(labelValueCollection["RemainingPulse"].Item1, RemainingPulse.ToString());
|
|
labelValueCollection["Period"] = new Tuple<Label, String>(labelValueCollection["Period"].Item1, Period);
|
|
labelValueCollection["RefFlow"] = new Tuple<Label, String>(labelValueCollection["RefFlow"].Item1, doubleToStringFormat(RefFlowrate, 6));
|
|
labelValueCollection["RefFlowUncorrected"] =
|
|
new Tuple<Label, String>(labelValueCollection["RefFlowUncorrected"].Item1, doubleToStringFormat(RefFlowUncorrected, 6));
|
|
|
|
TryInvoke(new Action(() =>
|
|
{
|
|
foreach (var item in labelValueCollection)
|
|
{
|
|
item.Value.Item1.Text = item.Value.Item2;
|
|
}
|
|
}));
|
|
|
|
}
|
|
|
|
#endregion
|
|
#region dataGridview
|
|
private Color? getErrorColor(Double meterError, Int32 slot)
|
|
{
|
|
Color? ret = Color.Green;
|
|
var errorFrame = slotErrorFrameDic.FirstOrDefault(e => e.Key.Equals(slot)).Value;
|
|
if (errorFrame <= Math.Abs(meterError))
|
|
{
|
|
ret = Color.LightYellow;
|
|
}
|
|
if (double.IsNaN(meterError) || double.IsNaN(errorFrame))
|
|
{
|
|
ret = Color.Yellow;
|
|
}
|
|
return ret;
|
|
}
|
|
private void updateRowVisible(String Row, Boolean Value)
|
|
{
|
|
TryInvoke(new Action(() =>
|
|
{
|
|
dgvBatch.Rows[rowIndex.First(k => k.Value == Row).Key].Visible = Value;
|
|
}));
|
|
}
|
|
private void updateCellToInput(String Row, Int32 Slot, Boolean Value)
|
|
{
|
|
if (dgvBatch != null && dgvBatch.Rows.Count > rowIndex.First(k => k.Value == Row).Key && dgvBatch.Rows[rowIndex.First(k => k.Value == Row).Key].Cells.Count > Slot)
|
|
{
|
|
TryInvoke(new Action(() =>
|
|
{
|
|
dgvBatch.Rows[rowIndex.First(k => k.Value == Row).Key].Cells[Slot].ReadOnly = Value;
|
|
}));
|
|
}
|
|
}
|
|
private T getCellValue<T>(String Row, Int32 Slot)
|
|
{
|
|
if (dgvBatch != null && dgvBatch.Rows.Count > rowIndex.First(k => k.Value == Row).Key
|
|
&& dgvBatch.Rows[rowIndex.First(k => k.Value == Row).Key].Cells.Count > Slot)
|
|
{
|
|
var currentRowIndex = rowIndex.First(k => k.Value == Row).Key;
|
|
var value = dtBatch.Rows[currentRowIndex][Slot].ToString();
|
|
var converter = TypeDescriptor.GetConverter(typeof(T));
|
|
return (T)converter.ConvertFrom(value);
|
|
}
|
|
return default(T);
|
|
}
|
|
|
|
private void setColor(String Row, Int32 Slot, Color c)
|
|
{
|
|
if (dgvBatch != null && dgvBatch.Rows.Count > rowIndex.First(k => k.Value == Row).Key && dgvBatch.Rows[rowIndex.First(k => k.Value == Row).Key].Cells.Count > Slot)
|
|
{
|
|
TryInvoke(new Action(() =>
|
|
{
|
|
var currentRowIndex = rowIndex.First(k => k.Value == Row).Key;
|
|
var currentCell = dgvBatch.Rows[currentRowIndex].Cells[Slot];
|
|
if (dgvBatch.InvokeRequired)
|
|
{
|
|
setColor(Row, Slot, c);
|
|
|
|
}
|
|
else
|
|
{
|
|
currentCell.Style.BackColor = c;
|
|
}
|
|
}));
|
|
}
|
|
}
|
|
private void updateCell(String Row, Int32 Slot, Double Value, Int32 digits = 2, Color? c = null)
|
|
{
|
|
updateCell(Row, Slot, doubleToStringFormat(Value, digits), c);
|
|
}
|
|
private void updateCell(String Row, Int32 Slot, String Value, Color? c = null)
|
|
{
|
|
if (dgvBatch != null && dgvBatch.Rows.Count > rowIndex.First(k => k.Value == Row).Key && dgvBatch.Rows[rowIndex.First(k => k.Value == Row).Key].Cells.Count > Slot)
|
|
{
|
|
TryInvoke(new Action(() =>
|
|
{
|
|
var currentRowIndex = rowIndex.First(k => k.Value == Row).Key;
|
|
dtBatch.Rows[currentRowIndex][Slot] = Value;
|
|
if (c.HasValue)
|
|
{
|
|
dgvBatch.Rows[currentRowIndex].Cells[Slot].Style.BackColor = c.Value;
|
|
}
|
|
else
|
|
{
|
|
dgvBatch.Rows[currentRowIndex].Cells[Slot].Style.BackColor = Color.Empty;
|
|
}
|
|
}));
|
|
}
|
|
|
|
}
|
|
private void initDt()
|
|
{
|
|
rowIndex = new Dictionary<Int32, String>();
|
|
rowIndex.Add(rowIndex.Count, "Einbauplatz");
|
|
rowIndex.Add(rowIndex.Count, "Seriennummer");
|
|
rowIndex.Add(rowIndex.Count, "PcbId");
|
|
rowIndex.Add(rowIndex.Count, "Status");
|
|
rowIndex.Add(rowIndex.Count, "Fehler [%]");
|
|
rowIndex.Add(rowIndex.Count, "Druchfluss [m³/h]");
|
|
rowIndex.Add(rowIndex.Count, "Volumen [m³]");
|
|
rowIndex.Add(rowIndex.Count, "Zeit [S]");
|
|
rowIndex.Add(rowIndex.Count, "Fehlergrenze [%]");
|
|
rowIndex.Add(rowIndex.Count, "Zielwert Justage [%]");
|
|
|
|
rowIndex.Add(rowIndex.Count, "Pfad 1 Fehler [%]");
|
|
rowIndex.Add(rowIndex.Count, "Pfad 1 Druchfluss [m³/h]");
|
|
rowIndex.Add(rowIndex.Count, "Pfad 1 Volumen [m³]");
|
|
rowIndex.Add(rowIndex.Count, "Pfad 1 Zeit [S]");
|
|
|
|
rowIndex.Add(rowIndex.Count, "Pfad 2 Fehler [%]");
|
|
rowIndex.Add(rowIndex.Count, "Pfad 2 Druchfluss [m³/h]");
|
|
rowIndex.Add(rowIndex.Count, "Pfad 2 Volumen [m³]");
|
|
rowIndex.Add(rowIndex.Count, "Pfad 2 Zeit [S]");
|
|
|
|
rowIndex.Add(rowIndex.Count, "Pfad 3 Fehler [%]");
|
|
rowIndex.Add(rowIndex.Count, "Pfad 3 Druchfluss [m³/h]");
|
|
rowIndex.Add(rowIndex.Count, "Pfad 3 Volumen [m³]");
|
|
rowIndex.Add(rowIndex.Count, "Pfad 3 Zeit [S]");
|
|
|
|
|
|
dtBatch = new DataTable();
|
|
dtBatch.Columns.Add("RowHeader");
|
|
dtBatch.Columns.Add("1");
|
|
dtBatch.Columns.Add("2");
|
|
dtBatch.Columns.Add("3");
|
|
dtBatch.Columns.Add("4");
|
|
dtBatch.Columns.Add("5");
|
|
dtBatch.Columns.Add("6");
|
|
dtBatch.Columns.Add("7");
|
|
dtBatch.Columns.Add("8");
|
|
dtBatch.Columns.Add("9");
|
|
dtBatch.Columns.Add("10");
|
|
|
|
foreach (var item in rowIndex)
|
|
{
|
|
dtBatch.Rows.Add();
|
|
dtBatch.Rows[dtBatch.Rows.Count - 1][0] = item.Value;
|
|
}
|
|
|
|
dgvBatch.DataSource = dtBatch;
|
|
foreach (var item in dgvBatch.Columns)
|
|
{
|
|
if (item is DataGridViewColumn)
|
|
{
|
|
var dt = (DataGridViewColumn)item;
|
|
dt.ReadOnly = true;
|
|
if (dt.Name != "RowHeader")
|
|
{
|
|
dt.Visible = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
private void ExpertMode(Boolean visible)
|
|
{
|
|
updateRowVisible("Pfad 1 Fehler [%]", visible);
|
|
updateRowVisible("Pfad 1 Druchfluss [m³/h]", visible);
|
|
updateRowVisible("Pfad 1 Volumen [m³]", visible);
|
|
updateRowVisible("Pfad 1 Zeit [S]", visible);
|
|
updateRowVisible("Pfad 2 Fehler [%]", visible);
|
|
updateRowVisible("Pfad 2 Druchfluss [m³/h]", visible);
|
|
updateRowVisible("Pfad 2 Volumen [m³]", visible);
|
|
updateRowVisible("Pfad 2 Zeit [S]", visible);
|
|
updateRowVisible("Pfad 3 Fehler [%]", visible);
|
|
updateRowVisible("Pfad 3 Druchfluss [m³/h]", visible);
|
|
updateRowVisible("Pfad 3 Volumen [m³]", visible);
|
|
updateRowVisible("Pfad 3 Zeit [S]", visible);
|
|
}
|
|
#endregion
|
|
#region ictlBatch & Mainwork
|
|
|
|
|
|
|
|
private Boolean _useRequest;
|
|
private Boolean _rawLogging = true;
|
|
private Boolean _isAdjustment;
|
|
|
|
private Boolean _checkAllChannels = true;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="ControlSrt"></param>
|
|
public void PrepareBatch(String ControlSrt = "JustToCheckUpdate")
|
|
{
|
|
try
|
|
{
|
|
|
|
_logger.Trace($"PrepareBatch ControlSrt : {ControlSrt} ");
|
|
batch = new MeterBatch();
|
|
_useRequest = true;
|
|
_rawLogging = true;
|
|
_checkAllChannels = TestSetupContainer.AllChanelsRequired;
|
|
|
|
//TryInvoke(new Action(() =>
|
|
//{
|
|
// this.RefeshTimer.Enabled = true;
|
|
//}));
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.Error(ex, $"error at ControlSrt : {ControlSrt}");
|
|
}
|
|
}
|
|
public void AddAllMeters()
|
|
{
|
|
setBusy(true, "alle Zähler hinzufügen");
|
|
|
|
|
|
foreach (var item in TestSetupContainer.meterTestSettings)
|
|
{
|
|
|
|
if (item != null && (item.FlowAdjustment || item.FlowTesting))
|
|
{
|
|
if (!batch.ListOfMeters.Any(f => f.Slot == item.Slot))
|
|
{
|
|
|
|
var meter = new GenesisMeter();
|
|
meter.SerialNumber = item.SerialNr;
|
|
meter.CurrentActionText = "FlowTest";
|
|
meter.SetupFromConfigFile(item.Slot, false, _useRequest, true);
|
|
meter.LogRawData(_rawLogging);
|
|
|
|
batch.AddMeter(meter);
|
|
meter.Login();
|
|
meter.EnableAutoLogon();
|
|
meter.WriteLog("Add from AddAllMeters");
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
setBusy(false);
|
|
|
|
}
|
|
public void AddMeter(String serialNumber, Int32 slot, Boolean SkipPrepearation)
|
|
{
|
|
try
|
|
{
|
|
setBusy(true, $"Füge {serialNumber} hinzu");
|
|
Task.Factory.StartNew(() =>
|
|
{
|
|
|
|
if (batch.ListOfMeters.Any(f => f.Slot == slot))
|
|
{
|
|
batch.RemoveMeter(batch.ListOfMeters.First(f => f.Slot == slot));
|
|
}
|
|
var meter = new GenesisMeter();
|
|
meter.SerialNumber = serialNumber;
|
|
meter.CurrentActionText = "FlowTest";
|
|
meter.SetupFromConfigFile(slot, false, _useRequest, true);
|
|
meter.LogRawData(_rawLogging);
|
|
|
|
meter.EnableAutoLogon();
|
|
batch.AddMeter(meter);
|
|
|
|
}).ContinueWith(delegate
|
|
{
|
|
setBusy(false);
|
|
});
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.Error(ex, $"error at AddMeter(serialNumber={serialNumber},slot={slot}");
|
|
}
|
|
|
|
}
|
|
|
|
public void AddMeter(String serialNumber, Int32 slot)
|
|
{
|
|
if (TestSetupContainer == null)
|
|
{
|
|
TestSetupContainer = new TestSetupContainer();
|
|
TestSetupContainer.AllChanelsRequired = true;
|
|
TestSetupContainer.meterTestSettings = new MeterTestSettings[10];
|
|
}
|
|
|
|
if (!TestSetupContainer.meterTestSettings.Any(f => f != null && f.Slot == slot))
|
|
{
|
|
TestSetupContainer.meterTestSettings[slot] = new MeterTestSettings() { SerialNr = serialNumber, Slot = slot, FlowAdjustment = true, FlowTesting = true };
|
|
}
|
|
AddMeter(serialNumber, slot, true);
|
|
}
|
|
|
|
public void RemoveMeter(Int32 slot)
|
|
{
|
|
try
|
|
{
|
|
setBusy(true, $"Entferne EP. {slot}");
|
|
Task.Factory.StartNew(() =>
|
|
{
|
|
var meterToRemove = batch.ListOfMeters.First(a => a.Slot == slot);
|
|
batch.RemoveMeter(meterToRemove);
|
|
|
|
}).ContinueWith(delegate
|
|
{
|
|
setBusy(false);
|
|
});
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.Error(ex, $"error at RemoveMeter(slot={slot}");
|
|
}
|
|
}
|
|
public String LutCrc(Int32 slot)
|
|
{
|
|
if (!slotLut.ContainsKey(slot))
|
|
{
|
|
return "";
|
|
}
|
|
return slotLut[slot];
|
|
}
|
|
public Boolean MeterHasPreadjustment(Int32 slot)
|
|
{
|
|
if (!slotPreadjustment.ContainsKey(slot))
|
|
{
|
|
return false;
|
|
}
|
|
return slotPreadjustment[slot];
|
|
}
|
|
public void MeterDoneWithDetails(Int32 slot, Boolean Succeed)
|
|
{
|
|
if (!slotLut.ContainsKey(slot))
|
|
{
|
|
slotLut.Add(slot, "");
|
|
}
|
|
else
|
|
{
|
|
slotLut[slot] = "";
|
|
}
|
|
if (!slotPreadjustment.ContainsKey(slot))
|
|
{
|
|
slotPreadjustment.Add(slot, false);
|
|
}
|
|
else
|
|
{
|
|
slotPreadjustment[slot] = false;
|
|
}
|
|
|
|
|
|
MeterDone(slot, Succeed);
|
|
var meter = batch.ListOfMeters.First(f => f.Slot == slot);
|
|
if (meter is GenesisMeter gen)
|
|
{
|
|
slotLut[slot] = gen.LutCrc;
|
|
try
|
|
{
|
|
var responseJson = LocalWebRequest.GetRequest($"{ServiceUrls.MeterInfoForTestBench()}{gen.PcbId}");
|
|
var a = JsonConvert.DeserializeObject<String[]>(responseJson);
|
|
var SerialNumber = a[0];
|
|
if (!string.IsNullOrEmpty(SerialNumber))
|
|
{
|
|
slotPreadjustment[slot] = int.TryParse(a[4], out _);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.Error(ex, $"error at meter done web request (PcbId={gen.PcbId}");
|
|
|
|
throw;
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
public void MeterDone(Int32 slot, Boolean Succeed)
|
|
{
|
|
try
|
|
{
|
|
setBusy(true, $"Set {slot} LCD");
|
|
Task.Factory.StartNew(() =>
|
|
{
|
|
//FF-55-00-00
|
|
var meter = batch.ListOfMeters.First(f => f.Slot == slot);
|
|
var state = Xylem.Common.Hardware.WaterMeter.WaterMeterCore.Consts.DisplayCodes.FlowTested;
|
|
|
|
if (!Succeed)
|
|
{
|
|
if (meter is GenesisMeter gen)
|
|
{
|
|
if (gen.IsLoggedOn)
|
|
{
|
|
var displayState = gen.ReadRegister(Register.Genesisflow.TriggerIdle);
|
|
|
|
var displayStateString = ByteStyler.ToString(displayState);
|
|
|
|
if (displayStateString.Substring(0, 2) != "FF")
|
|
{
|
|
state = Xylem.Common.Hardware.WaterMeter.WaterMeterCore.Consts.DisplayCodes.FlowTestFailed;
|
|
|
|
}
|
|
else
|
|
{
|
|
gen.WriteLog($"meter not active because display code has an error on code:{displayStateString}");
|
|
//skip set
|
|
return;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
meter.SetProcessState(state);
|
|
|
|
if (meter is GenesisMeter genMeter)
|
|
{
|
|
if (!genMeter.IsLoggedOn)
|
|
{
|
|
genMeter.Login();
|
|
|
|
}
|
|
genMeter.WriteRegister(Register.Genesisflow.SampleRate, 2);
|
|
genMeter.WriteRegister(Register.Genesisflow.LedMode, 0);
|
|
meter.WriteLog($"MeterIsDone {state} {genMeter.LutCrc }");
|
|
}
|
|
else
|
|
{
|
|
meter.WriteLog($"MeterIsDone {state} ");
|
|
}
|
|
|
|
|
|
|
|
|
|
}).ContinueWith(delegate
|
|
{
|
|
setBusy(false);
|
|
});
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.Error(ex, $"error at MeterDone(slot={slot},Succeed={Succeed})");
|
|
}
|
|
}
|
|
|
|
|
|
public void SetErrorFrame(Int32 slot, Double errorFrame = 0.0)
|
|
{
|
|
try
|
|
{
|
|
setBusy(true, $"Setze Fehlergrenze");
|
|
updateCell("Fehlergrenze [%]", slot, errorFrame);
|
|
|
|
if (slotErrorFrameDic.ContainsKey(slot))
|
|
{
|
|
slotErrorFrameDic.Remove(slot);
|
|
}
|
|
slotErrorFrameDic.Add(slot, errorFrame);
|
|
setBusy(false);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.Error(ex, $"error at SetErrorFrame(slot={slot},errorFrame={errorFrame}");
|
|
}
|
|
}
|
|
|
|
public void LogMeter(Int32 slot, String message)
|
|
{
|
|
|
|
try
|
|
{
|
|
Task.Factory.StartNew(() =>
|
|
{
|
|
var meter = batch.ListOfMeters.First(f => f.Slot == slot);
|
|
meter.WriteLog(message);
|
|
});
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.Error(ex, $"error at LogMeter(slot={slot},message={message}");
|
|
}
|
|
}
|
|
|
|
public void PrepareMeters(String meterDn = "-", Double refPulseValence = 0.0, Double predictedQFlow = 0.0,
|
|
Double predictedTs = 0.0, Double refError = 0.0, Boolean isAdjustment = false, Boolean isFlyingStartStop = true)
|
|
{
|
|
try
|
|
{
|
|
IsFlyingStartStop = isFlyingStartStop;
|
|
_logger.Trace($"Start PrepareMeters(meterDn={meterDn},refPulseValence={refPulseValence}," +
|
|
$"predictedQFlow ={predictedQFlow},predictedTs={predictedTs},refError={refError}," +
|
|
$"isAdjustment={isAdjustment},IsFlyingStartStop={IsFlyingStartStop}");
|
|
WarningMetersAlarms = new ConcurrentDictionary<Int32, GenesisMeter.Alarm>();
|
|
ErrorMetersAlarms = new ConcurrentDictionary<Int32, GenesisMeter.Alarm>();
|
|
setBusy(true, $"Bereite Zähler vor");
|
|
|
|
initAction(meterDn, refPulseValence, predictedQFlow, predictedTs, refError, isFlyingStartStop);
|
|
_isAdjustment = isAdjustment;
|
|
|
|
if (isAdjustment)
|
|
{
|
|
CalibrationIsDone = new Dictionary<Int32, LegacyCalibrationResult>();
|
|
}
|
|
|
|
foreach (var meter in batch.ListOfMeters)
|
|
{
|
|
_logger.Trace($"Meter {meter.Slot} Start PrepareMeters(meterDn={meterDn}," +
|
|
$"refPulseValence={refPulseValence},predictedQFlow ={predictedQFlow}," +
|
|
$"predictedTs={predictedTs},refError={refError},isAdjustment={isAdjustment}," +
|
|
$"IsFlyingStartStop={IsFlyingStartStop}");
|
|
|
|
if (!(meter is GenesisMeter genesisMeter))
|
|
{
|
|
continue;
|
|
}
|
|
//todo : roland check SkipPrepearationForTestBench
|
|
//((GenesisMeter)meter).SkipPrepearationForTestBench = true;
|
|
_logger.Debug($"Add Meter To Grid {meter.Slot}");
|
|
|
|
|
|
AddMeterToGrid(meter.Slot, meter.SerialNumber, genesisMeter.PcbId, isFlyingStartStop);
|
|
|
|
if (isAdjustment)
|
|
{
|
|
CalibrationIsDone.Add(meter.Slot, LegacyCalibrationResult.Pending);
|
|
}
|
|
|
|
if (_useRequest)
|
|
{
|
|
var r = ((GenesisMeter)meter).ReLogin();
|
|
((GenesisMeter)meter).WriteLog("Prepare meter for Measurement/Adjustment ");
|
|
_logger.Debug($"Prepare Meters for Measurement/Adjustment");
|
|
if (isAdjustment)
|
|
{
|
|
((GenesisMeter)meter).InitCalibration();
|
|
}
|
|
else
|
|
{
|
|
((GenesisMeter)meter).InitMeasurement();
|
|
}
|
|
//// Reboot, HighPressure
|
|
////ReadOut Alarms, Show and reset
|
|
//_logger.Debug($"Start CheckMetersAreReadyForTest");
|
|
}
|
|
}
|
|
|
|
TryInvoke(new Action(() =>
|
|
{
|
|
UpdateBatch();
|
|
}));
|
|
|
|
CheckMetersAreReadyForTest();
|
|
setBusy(false);
|
|
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.Error(ex, $"error at PrepareMeters(meterDn={meterDn},refPulseValence={refPulseValence}," +
|
|
$"predictedQFlow ={predictedQFlow},predictedTs={predictedTs},refError={refError}," +
|
|
$"isAdjustment={isAdjustment},IsFlyingStartStop={IsFlyingStartStop}");
|
|
}
|
|
|
|
}
|
|
|
|
private void CheckMetersAreReadyForTestStatic()
|
|
{
|
|
var listOfTasks = new List<Task>();
|
|
|
|
foreach (var meter in batch.ListOfMeters)
|
|
{
|
|
listOfTasks.Add(new Task(() =>
|
|
{
|
|
if (!(meter is GenesisMeter))
|
|
{
|
|
return;
|
|
}
|
|
var i = 1;
|
|
|
|
var sleepTimeS = 1;
|
|
_logger.Debug($" Meter {meter.Slot} CheckMetersAreReadyForTest loops {i};delay {sleepTimeS}S");
|
|
((GenesisMeter)meter).StartMeasurement();
|
|
var MeterReadyForTest = false;
|
|
|
|
|
|
|
|
while (i <= 7 && !MeterReadyForTest)
|
|
{
|
|
((GenesisMeter)meter).RequestIntermediateMeasurementState(0);
|
|
Thread.Sleep(i * 2000);
|
|
i = i + 1;
|
|
try
|
|
{
|
|
var state = ((GenesisMeter)meter).GetMeasurementState(0);
|
|
|
|
|
|
if (state != MeasurementStates.IsWaitingForStartData && state != MeasurementStates.NotStarted)
|
|
{
|
|
|
|
var r = ((GenesisMeter)meter).GetMainMeasurementResult(null, null, true);
|
|
|
|
if (r.DutVolumeCm != 0)
|
|
{
|
|
_logger.Info($" Meter {meter.Slot} Meter has progress (Volume{r.DutVolumeCm})");
|
|
|
|
MeterReadyForTest = true;
|
|
break;
|
|
}
|
|
|
|
|
|
}
|
|
_logger.Info($" Meter {meter.Slot} Meter no update display; loops left {i}; state {state}");
|
|
|
|
}
|
|
catch (Exception)
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
TryInvoke(new Action(() =>
|
|
{
|
|
updateCell($"Status", meter.Slot, $"Warte auf Zählerstand wechsel ", Color.LightYellow);
|
|
}));
|
|
|
|
}
|
|
((GenesisMeter)meter).StopMeasurement();
|
|
|
|
if (!MeterReadyForTest)
|
|
{
|
|
//todo event remove meter
|
|
_logger.Info($" Meter {meter.Slot} Meter has NO! progress");
|
|
TryInvoke(new Action(() =>
|
|
{
|
|
updateCell($"Status", meter.Slot, $"Zählerstand wechsel nicht erfasst", Color.LightPink);
|
|
}));
|
|
}
|
|
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
listOfTasks.ForEach(t => t.Start());
|
|
Task.WaitAll(listOfTasks.ToArray());
|
|
|
|
|
|
}
|
|
|
|
|
|
private void CheckMetersAreReadyForTest()
|
|
{
|
|
_logger.Trace($"CheckMetersAreReadyForTest");
|
|
TryInvoke(new Action(() =>
|
|
{
|
|
lblAction.Text = "Warte auf Zählerstand wechsel von allen Zählern";
|
|
|
|
}));
|
|
|
|
|
|
var listOfTasks = new List<Task>();
|
|
|
|
foreach (var meter in batch.ListOfMeters)
|
|
{
|
|
|
|
|
|
if (!(meter is GenesisMeter))
|
|
{
|
|
if (!(meter is GenesisMeter))
|
|
{
|
|
continue;
|
|
}
|
|
}
|
|
|
|
TryInvoke(new Action(() =>
|
|
{
|
|
|
|
updateCell($"Status", meter.Slot, $"Warte auf Zählerstand wechsel", Color.LightYellow);
|
|
}));
|
|
|
|
|
|
listOfTasks.Add(new Task(() =>
|
|
{
|
|
var i = 120;
|
|
|
|
var sleepTimeS = 5;
|
|
_logger.Debug($" Meter {meter.Slot} CheckMetersAreReadyForTest loops {i};delay {sleepTimeS}S");
|
|
((GenesisMeter)meter).StartMeasurement();
|
|
var MeterReadyForTest = false;
|
|
while (i >= 0)
|
|
{
|
|
Thread.Sleep(sleepTimeS * 1000);
|
|
try
|
|
{
|
|
var r = ((GenesisMeter)meter).GetMainMeasurementResult(null, null, true);
|
|
i = i - sleepTimeS;
|
|
if (r.DutVolumeCm != 0)
|
|
{
|
|
_logger.Info($" Meter {meter.Slot} Meter has progress {r.DutVolumeCm}");
|
|
TryInvoke(new Action(() =>
|
|
{
|
|
// updateCell($"Status", meter.Slot, $"Zählerstand wechsel erfasst Von:{r.DutStartRecord.GetVolumeCm()} Auf: {r.DutStopRecord.GetVolumeCm()}", Color.LimeGreen);
|
|
}));
|
|
MeterReadyForTest = true;
|
|
break;
|
|
}
|
|
else
|
|
{
|
|
_logger.Info($" Meter {meter.Slot} Meter no update display {r.DutVolumeCm}; loops left {i}");
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
TryInvoke(new Action(() =>
|
|
{
|
|
updateCell($"Status", meter.Slot, $"Warte auf Zählerstand wechsel ", Color.LightYellow);
|
|
}));
|
|
|
|
}
|
|
((GenesisMeter)meter).StopMeasurement();
|
|
|
|
if (MeterReadyForTest)
|
|
{
|
|
_logger.Info($" Meter {meter.Slot} Meter has NO! progress");
|
|
TryInvoke(new Action(() =>
|
|
{
|
|
updateCell($"Status", meter.Slot, $"Zählerstand wechsel nicht erfasst", Color.LightPink);
|
|
}));
|
|
}
|
|
|
|
}));
|
|
|
|
|
|
|
|
}
|
|
listOfTasks.ForEach(t => t.Start());
|
|
Task.WaitAll(listOfTasks.ToArray());
|
|
|
|
}
|
|
|
|
public void StartMeasurement()
|
|
{
|
|
try
|
|
{
|
|
|
|
|
|
foreach (var item in batch.ListOfMeters)
|
|
{
|
|
var settings = TestSetupContainer.meterTestSettings.First(f => f != null && f.Slot == item.Slot);
|
|
|
|
if (_isAdjustment && settings.FlowAdjustment)
|
|
{
|
|
item.StartCalibration();
|
|
}
|
|
if (!_isAdjustment && settings.FlowTesting)
|
|
{
|
|
item.StartMeasurement();
|
|
}
|
|
}
|
|
|
|
|
|
currentMode = Mode.AutoRefresh;
|
|
//this.RefeshTimer.Enabled = true;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.Error(ex, "StartMeasurement");
|
|
}
|
|
}
|
|
public void SetLoggerActionText(String ActionText)
|
|
{
|
|
foreach (var item in batch.ListOfMeters)
|
|
{
|
|
if (item is GenesisMeter gm)
|
|
{
|
|
gm.CurrentActionText = $"{ActionText}";
|
|
}
|
|
}
|
|
}
|
|
|
|
public void StopMeasurement()
|
|
{
|
|
try
|
|
{
|
|
var nrOfRetrys = 40;
|
|
|
|
foreach (var item in batch.ListOfMeters)
|
|
{
|
|
var settings = TestSetupContainer.meterTestSettings.First(f => f != null && f.Slot == item.Slot);
|
|
|
|
if (_isAdjustment && !settings.FlowAdjustment)
|
|
{
|
|
continue;
|
|
}
|
|
if (!_isAdjustment && !settings.FlowTesting)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
if (_isAdjustment)
|
|
{
|
|
item.StopCalibration();
|
|
}
|
|
else
|
|
{
|
|
item.StopMeasurement();
|
|
}
|
|
}
|
|
|
|
foreach (var item in batch.ListOfMeters)
|
|
{
|
|
if (item is GenesisMeter gm)
|
|
{
|
|
gm.CurrentActionText = $"FlowTest";
|
|
}
|
|
var settings = TestSetupContainer.meterTestSettings.First(f => f != null && f.Slot == item.Slot);
|
|
|
|
if (_isAdjustment && !settings.FlowAdjustment)
|
|
{
|
|
continue;
|
|
}
|
|
if (!_isAdjustment && !settings.FlowTesting)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_isAdjustment)
|
|
{
|
|
Int32 retrys = 0;
|
|
while (item.GetCalibrationState() != MeasurementStates.IsCompleted && retrys < nrOfRetrys)
|
|
{
|
|
if (retrys == (nrOfRetrys / 2))
|
|
{
|
|
item.StopCalibration();
|
|
}
|
|
Thread.Sleep(100);
|
|
retrys = retrys + 1;
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
Int32 retrys = 0;
|
|
//remove channel filter 0
|
|
var onlyChnl = _checkAllChannels ? null : (Int32?)0;
|
|
|
|
while (item.GetMeasurementState(onlyChnl) != MeasurementStates.IsCompleted && retrys < nrOfRetrys)
|
|
{
|
|
if (retrys == (nrOfRetrys / 2))
|
|
{
|
|
item.StopMeasurement();
|
|
}
|
|
Thread.Sleep(100);
|
|
retrys = retrys + 1;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.Error(ex, "StopMeasurement");
|
|
}
|
|
}
|
|
Boolean ICtlBatch.IsBusy()
|
|
{
|
|
return IsBusy;
|
|
}
|
|
|
|
|
|
private MeasurementResults? GetMeasurementResult(Int32 Slot, Int32 Chnnl, Double refVolQm, Double refTimeS)
|
|
{
|
|
try
|
|
{
|
|
var meter = batch.ListOfMeters.First(f => f.Slot == Slot);
|
|
|
|
MeasurementResults result = new MeasurementResults();
|
|
|
|
if (Chnnl != 0 && meter is GenesisMeter)
|
|
{
|
|
result = ((GenesisMeter)meter).GetAllMeasurementResults(refVolQm, refTimeS)
|
|
.FirstOrDefault(f => f.Channel == Chnnl);
|
|
return result;
|
|
}
|
|
|
|
if (((GenesisMeter)meter).AllChannelsRequired)
|
|
{
|
|
if (meter == null || meter.GetMeasurementState() != MeasurementStates.IsCompleted)
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
|
|
result = refTimeS == 0.0 ? meter.GetMainMeasurementResult(refVolQm, null) : meter.GetMainMeasurementResult(refVolQm, refTimeS);
|
|
return result;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.Error(ex, $"error on GetResults Slot={Slot},Chnnl={Chnnl},refVolQm={refVolQm},refTimeS={refTimeS}");
|
|
return null;
|
|
}
|
|
|
|
}
|
|
|
|
public Results GetResults(Int32 Slot, Int32 Chnnl, Double refVolQm, Double refTimeS)
|
|
{
|
|
try
|
|
{
|
|
//todo remove
|
|
var result = GetMeasurementResult(Slot, Chnnl, refVolQm, refTimeS);
|
|
if (!result.HasValue)
|
|
{
|
|
_logger.Warn($"No Result found for GetResults(Slot={Slot},Chnnl={Chnnl},refVolQm={refVolQm},refTimeS={refTimeS})");
|
|
return new Results();
|
|
}
|
|
|
|
_logger.Debug($"Result request by caller for Slot={Slot} and Channel={Chnnl} with refVolQm={refVolQm} and refTimeS={refTimeS} are:");
|
|
_logger.Debug($"AccuDutOverflowTimeS = {result.Value.AccuDutOverflowTimeS}");
|
|
_logger.Debug($"AccuDutOverflowVolumeCm = {result.Value.AccuDutOverflowVolumeCm}");
|
|
_logger.Debug($"DeviationDutToRefPer = {result.Value.DeviationDutToRefPer}");
|
|
_logger.Debug($"DeviationDutToRefRel = {result.Value.DeviationDutToRefRel}");
|
|
_logger.Debug($"DutFlowRateCmPh = {result.Value.DutFlowRateCmPh}");
|
|
_logger.Debug($"DutTimeS = {result.Value.DutTimeS}");
|
|
_logger.Debug($"DutVolumeCm = {result.Value.DutVolumeCm}");
|
|
_logger.Debug($"RefTimeS = {result.Value.RefTimeS}");
|
|
_logger.Debug($"RefVolumeCm = {result.Value.RefVolumeCm}");
|
|
_logger.Debug($"ScaleFactorRefToDut = {result.Value.ScaleFactorRefToDut}");
|
|
_logger.Debug($"Start Record: TimeS={result.Value.DutStartRecord.GetTimeS()}, VolumeCm={result.Value.DutStartRecord.GetVolumeCm()}");
|
|
_logger.Debug($"End Record: TimeS={result.Value.DutStopRecord.GetTimeS()}, VolumeCm={result.Value.DutStopRecord.GetVolumeCm()}");
|
|
var sbError = string.Empty;
|
|
if (ErrorMetersAlarms.ContainsKey(Slot) && ErrorMetersAlarms[Slot].HasFlag(TestBenchRelatedAlarms))
|
|
{
|
|
var MeterAlarms = ErrorMetersAlarms[Slot].GetHashCode();
|
|
sbError = $"ErrorCode{MeterAlarms}";
|
|
}
|
|
|
|
return new Results(result.Value, sbError);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.Error(ex, $"error on GetResults Slot={Slot},Chnnl={Chnnl},refVolQm={refVolQm},refTimeS={refTimeS}");
|
|
return new Results();
|
|
}
|
|
|
|
}
|
|
public LegacyCalibrationResult GetCalibrationResult(Int32 slot)
|
|
{
|
|
try
|
|
{
|
|
if (CalibrationIsDone == null && !CalibrationIsDone.Any())
|
|
{
|
|
throw new ApplicationException("No Calibration is running");
|
|
}
|
|
if (!CalibrationIsDone.ContainsKey(slot))
|
|
{
|
|
throw new ApplicationException($"No Calibration is running on slot {slot}");
|
|
}
|
|
return CalibrationIsDone[slot];
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.Error(ex, $"error on GetCalibrationIsDone");
|
|
return LegacyCalibrationResult.CheckAllMeters;
|
|
}
|
|
|
|
}
|
|
public LegacyCalibrationResult GetCalibrationIsDone()
|
|
{
|
|
try
|
|
{
|
|
if (CalibrationIsDone.Any(any => any.Value == LegacyCalibrationResult.Pending))
|
|
{
|
|
return LegacyCalibrationResult.Pending;
|
|
}
|
|
if (CalibrationIsDone.All(all => all.Value == LegacyCalibrationResult.Good))
|
|
{
|
|
return LegacyCalibrationResult.Good;
|
|
}
|
|
if (CalibrationIsDone.Any(any => any.Value == LegacyCalibrationResult.BadAbort))
|
|
{
|
|
return LegacyCalibrationResult.BadAbort;
|
|
}
|
|
|
|
|
|
return LegacyCalibrationResult.CheckAllMeters;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.Error(ex, $"error on GetCalibrationIsDone");
|
|
return LegacyCalibrationResult.CheckAllMeters;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public void StartStoreCalibrationAuto(Double refVolume, Double testTimeRef, Double AdjustmentPerc = 0)
|
|
{
|
|
MeterDefaultCorrection = AdjustmentPerc;
|
|
StartStoreCalibration(refVolume, testTimeRef);
|
|
btnOk_Click(null, EventArgs.Empty);
|
|
}
|
|
public void StartStoreCalibration(Double refVolume, Double testTimeRef)
|
|
{
|
|
try
|
|
{
|
|
|
|
pnlEndTime.Visible = false;
|
|
|
|
StoreRefVolume = refVolume;
|
|
StoreTestTimeRef = testTimeRef;
|
|
UpdateBatch();
|
|
pnlCalibration.Visible = true;
|
|
foreach (var basemeter in batch.ListOfMeters)
|
|
{
|
|
var settings = TestSetupContainer.meterTestSettings.First(f => f != null && f.Slot == basemeter.Slot);
|
|
if (settings.FlowAdjustment)
|
|
{
|
|
updateCellToInput("Zielwert Justage [%]", basemeter.Slot, false);
|
|
updateCell("Zielwert Justage [%]", basemeter.Slot, (Double)settings.FlowAdjustmentTarget, 2, Color.Beige);
|
|
}
|
|
}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.Error(ex, $"error on StartStoreCalibration refVolume={refVolume},testTimeRef={testTimeRef}");
|
|
}
|
|
}
|
|
|
|
|
|
public void AddMeterToGrid(Int32 Slot, String SerialNumber, String PcbId, Boolean isFlyingStartStop)
|
|
{
|
|
try
|
|
{
|
|
IsFlyingStartStop = isFlyingStartStop;
|
|
//var totalWidth = dgvBatch.Columns.GetColumnsWidth(DataGridViewElementStates.None) + 40;
|
|
//dgvBatch.Size = new Size(totalWidth, dgvBatch.Size.Height);
|
|
|
|
updateCell("Einbauplatz", Slot, Slot.ToString());
|
|
updateCell("Seriennummer", Slot, SerialNumber);
|
|
updateCell("PcbId", Slot, PcbId);
|
|
|
|
TryInvoke(new Action(() =>
|
|
{
|
|
dgvBatch.Columns[Slot].Visible = true;
|
|
}));
|
|
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.Error(ex, $"error on AddMeterToGrid Slot={Slot},SerialNumber={SerialNumber}," +
|
|
$"IsFlyingStartStop={IsFlyingStartStop}");
|
|
}
|
|
|
|
}
|
|
public void ShowTest()
|
|
{
|
|
setBusy(false);
|
|
ManualUpdate();
|
|
|
|
TryInvoke(new Action(() =>
|
|
{
|
|
pnlEndTime.Visible = true;
|
|
}));
|
|
}
|
|
|
|
//private void TimerSetting()
|
|
//{
|
|
// switch (currentMode)
|
|
// {
|
|
// case Mode.AutoRefresh:
|
|
// RefeshTimer = new System.Windows.Forms.Timer();
|
|
// RefeshTimer.Interval = 10000;
|
|
// RefeshTimer.Tick += RefreshTimer_Tick;
|
|
// RefeshTimer.Enabled = true;
|
|
// break;
|
|
// case Mode.View:
|
|
// RefeshTimer.Enabled = false;
|
|
// break;
|
|
|
|
// }
|
|
//}
|
|
private void initAction(String meterDn = "-", Double refPulseValence = 0, Double predictedQFlow = 0,
|
|
Double predictedTs = 0, Double refError = 0, Boolean isFlyingStartStop = true)
|
|
{
|
|
TryInvoke(new Action(() =>
|
|
{
|
|
initDt();
|
|
pnlEndTime.Visible = false;
|
|
pnlCalibration.Visible = false;
|
|
IsFlyingStartStop = isFlyingStartStop;
|
|
Clear();
|
|
InitLabelValueCollection();
|
|
MeterDn = meterDn;
|
|
RefPulseValence = refPulseValence;
|
|
PredictedTs = predictedTs;
|
|
RefError = refError;
|
|
currentMode = Mode.AutoRefresh;
|
|
//this.RefreshTimer.Interval = 10000;
|
|
//this.RefreshTimer.Tick += new EventHandler(this.RefreshTimer_Tick);
|
|
//this.RefreshTimer.Enabled = true;
|
|
pgbUpdate.Maximum = 10000;
|
|
|
|
|
|
|
|
updateLabelCollection();
|
|
ExpertMode(cbxExpert.Checked);
|
|
// dgvBatch.Size = new Size(SizeOfMeter, dgvBatch.Size.Height);
|
|
pgbEndTime.Maximum = (Int32)predictedTs;
|
|
}));
|
|
|
|
}
|
|
|
|
public void Init(String meterDn = "-", Double refPulseValence = 0, Double predictedQFlow = 0, Double predictedTs = 0,
|
|
Double refError = 0, Boolean isFlyingStartStop = true)
|
|
{
|
|
try
|
|
{
|
|
IsFlyingStartStop = isFlyingStartStop;
|
|
setBusy(true, "lade Prüfpunkt");
|
|
initAction(meterDn, refPulseValence, predictedQFlow, predictedTs, refError, IsFlyingStartStop);
|
|
setBusy(false);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.Error(ex, $"error on Init meterDn={meterDn},refPulseValence={refPulseValence}," +
|
|
$"predictedQFlow={predictedQFlow},predictedTs={predictedTs}," +
|
|
$"refError={refError},IsFlyingStartStop={IsFlyingStartStop}");
|
|
}
|
|
}
|
|
|
|
public void SetBatchInfos(Double refFlowrate = 0, Double refTestTime = 0, Double refFlowUncorrected = 0, Int32 currentPulse = 0, Double currentRefVolume = 0, Int32 remainingPulse = 0, String period = "-", Boolean forceMeterUpdate = false)
|
|
{
|
|
try
|
|
{
|
|
|
|
CurrentPulse = currentPulse;
|
|
CurrentRefVolume = currentRefVolume;
|
|
if (refTestTime > 9 && currentRefVolume == 0 && refFlowrate != 0)
|
|
{
|
|
CurrentRefVolume = (refTestTime / 3600) * refFlowrate;
|
|
}
|
|
RemainingPulse = remainingPulse;
|
|
Period = period;
|
|
RefFlowrate = refFlowrate;
|
|
RefTestTime = refTestTime;
|
|
RefFlowUncorrected = refFlowUncorrected;
|
|
updateLabelCollection();
|
|
updateTotalProgress(refTestTime);
|
|
|
|
// if (forceMeterUpdate)
|
|
// {
|
|
UpdateBatch();
|
|
// }
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.Error(ex, $"error on SetBatchInfos refFlowrate={refFlowrate},refTestTime={refTestTime},refFlowUncorrected={refFlowUncorrected},currentPulse={currentPulse},currentRefVolume={currentRefVolume},remainingPulse={remainingPulse},period={period}");
|
|
}
|
|
|
|
}
|
|
private void UpdateBatch()
|
|
{
|
|
try
|
|
{
|
|
stopWatch.Reset();
|
|
var listOfStates = new List<MeasurementStates>();
|
|
foreach (var item in batch.ListOfMeters)
|
|
{
|
|
try
|
|
{
|
|
if (item is GenesisMeter)
|
|
{
|
|
var settings = TestSetupContainer.meterTestSettings.First(f => f != null && f.Slot == item.Slot);
|
|
|
|
if ((_isAdjustment && !settings.FlowAdjustment) || (!_isAdjustment && !settings.FlowTesting))
|
|
{
|
|
updateCell($"Status", item.Slot, "-", Color.Gray);
|
|
continue;
|
|
}
|
|
|
|
var _meter = (GenesisMeter)item;
|
|
var onlyChnl = _checkAllChannels ? null : (Int32?)0;
|
|
var ProcessStatus = item.GetMeasurementState(onlyChnl);
|
|
listOfStates.Add(ProcessStatus);
|
|
var textState = "-";
|
|
var statusColor = Color.Empty;
|
|
switch (ProcessStatus)
|
|
{
|
|
case MeasurementStates.IsCompleted:
|
|
textState = "Messung beendet";
|
|
statusColor = Color.Green;
|
|
break;
|
|
case MeasurementStates.IsRunning:
|
|
case MeasurementStates.IsWaitingForIntermediateData:
|
|
textState = "Messung läuft";
|
|
|
|
break;
|
|
case MeasurementStates.NotStarted:
|
|
default:
|
|
textState = "nicht gestartet";
|
|
break;
|
|
case MeasurementStates.IsWaitingForStartData:
|
|
case MeasurementStates.IsWaitingForEndData:
|
|
textState = "warte auf Daten";
|
|
statusColor = Color.Yellow;
|
|
break;
|
|
}
|
|
|
|
updateCell($"Status", _meter.Slot, textState, statusColor);
|
|
Double? testTime = null;
|
|
if (IsFlyingStartStop)
|
|
{
|
|
testTime = RefTestTime;
|
|
}
|
|
|
|
if (ProcessStatus != MeasurementStates.NotStarted)
|
|
{
|
|
var interResult = new List<MeasurementResults>();
|
|
if (ProcessStatus == MeasurementStates.IsRunning || ProcessStatus == MeasurementStates.IsWaitingForIntermediateData)
|
|
{
|
|
if (_checkAllChannels)
|
|
{
|
|
interResult = _meter.GetAllMeasurementResults(CurrentRefVolume, testTime, true);
|
|
|
|
}
|
|
else
|
|
{
|
|
interResult.Add(_meter.GetMainMeasurementResult(CurrentRefVolume, testTime, true));
|
|
}
|
|
}
|
|
else if (ProcessStatus == MeasurementStates.IsCompleted)
|
|
{
|
|
if (_checkAllChannels)
|
|
{
|
|
interResult = _meter.GetAllMeasurementResults(CurrentRefVolume, testTime);
|
|
|
|
}
|
|
else
|
|
{
|
|
interResult.Add(_meter.GetMainMeasurementResult(CurrentRefVolume, testTime));
|
|
}
|
|
}
|
|
if (interResult != null && interResult.Any())
|
|
{
|
|
|
|
|
|
foreach (var channelResult in interResult)
|
|
{
|
|
|
|
var prefix = "";
|
|
if (channelResult.Channel > 0)
|
|
{
|
|
prefix = $"Pfad {channelResult.Channel} ";
|
|
}
|
|
updateCell($"{prefix}Druchfluss [m³/h]", _meter.Slot, channelResult.DutFlowRateCmPh ?? 0, 4);
|
|
updateCell($"{prefix}Volumen [m³]", _meter.Slot, Math.Abs(channelResult.DutVolumeCm), 4);
|
|
updateCell($"{prefix}Zeit [S]", _meter.Slot, channelResult.DutTimeS);
|
|
if (channelResult.DeviationDutToRefPer.HasValue)
|
|
{
|
|
updateCell($"{prefix}Fehler [%]", _meter.Slot,
|
|
channelResult.DeviationDutToRefPer.Value, 2,
|
|
getErrorColor(channelResult.DeviationDutToRefPer.Value, _meter.Slot));
|
|
}
|
|
else
|
|
{
|
|
updateCell($"{prefix}Fehler [%]", _meter.Slot,
|
|
"NaN",
|
|
getErrorColor(100, _meter.Slot));
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
_logger.Error(e, $"error on UpdateBatch for meter {e.Message} ");
|
|
}
|
|
}
|
|
|
|
if (listOfStates.All(a => a.Equals(MeasurementStates.IsCompleted)))
|
|
{
|
|
currentMode = Mode.View;
|
|
TryInvoke(new Action(() =>
|
|
{
|
|
//this.RefeshTimer.Enabled = false;
|
|
//this.pnlEndTime.Visible = false;
|
|
}));
|
|
}
|
|
else
|
|
{
|
|
currentMode = Mode.AutoRefresh;
|
|
}
|
|
|
|
TryInvoke(new Action(() =>
|
|
{
|
|
//this.RefeshTimer.Enabled = true;
|
|
}));
|
|
|
|
stopWatch.Start();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.Error(ex, $"error on UpdateBatch {ex.Message} ");
|
|
}
|
|
|
|
}
|
|
|
|
public void Clear()
|
|
{
|
|
try
|
|
{
|
|
grbInfo.Controls.Clear();
|
|
labelValueCollection.Clear();
|
|
MeterDn = string.Empty;
|
|
RefPulseValence = 0.0;
|
|
PredictedTs = 0.0;
|
|
RefError = 0.0;
|
|
//RefeshTimer = new System.Windows.Forms.Timer();
|
|
//RefeshTimer.Interval = 50000;
|
|
//RefeshTimer.Enabled = false;
|
|
currentMode = Mode.View;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.Error(ex, $"error on Clear()");
|
|
}
|
|
|
|
|
|
}
|
|
|
|
private void ManualUpdate()
|
|
{
|
|
try
|
|
{
|
|
|
|
|
|
setBusy(true, "Update");
|
|
Task.Factory.StartNew(() =>
|
|
{
|
|
|
|
foreach (var item in batch.ListOfMeters)
|
|
{
|
|
if (item is GenesisMeter)
|
|
{
|
|
// ((GenesisMeter)item).();
|
|
}
|
|
|
|
}
|
|
Thread.Sleep(1000);
|
|
UpdateBatch();
|
|
|
|
}).ContinueWith(delegate
|
|
{
|
|
setBusy(false);
|
|
});
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.Error(ex, $"error on ManuleUpdate()");
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
#region GUI
|
|
|
|
private void btnPlus1_Click(Object sender, EventArgs e)
|
|
{
|
|
nudFactor.Value = nudFactor.Value + 1;
|
|
}
|
|
|
|
private void btnPlus01_Click(Object sender, EventArgs e)
|
|
{
|
|
nudFactor.Value = nudFactor.Value + (Decimal)0.1;
|
|
}
|
|
|
|
private void btnMinus01_Click(Object sender, EventArgs e)
|
|
{
|
|
nudFactor.Value = nudFactor.Value - (Decimal)0.1;
|
|
}
|
|
|
|
private void btnMinus1_Click(Object sender, EventArgs e)
|
|
{
|
|
nudFactor.Value = nudFactor.Value - 1;
|
|
}
|
|
|
|
private void btnOk_Click(Object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
var taskList = new List<Task<Tuple<Boolean, Int32>>>();
|
|
TryInvoke(new Action(() =>
|
|
{
|
|
pnlCalibration.Visible = false;
|
|
}));
|
|
foreach (var baseMeter in batch.ListOfMeters)
|
|
{
|
|
var settings = TestSetupContainer.meterTestSettings.First(f => f != null && f.Slot == baseMeter.Slot);
|
|
if (!settings.FlowAdjustment)
|
|
{
|
|
continue;
|
|
}
|
|
var calFactor = getCellValue<Double>("Zielwert Justage [%]", baseMeter.Slot);
|
|
if (baseMeter is GenesisMeter)
|
|
{
|
|
|
|
var calibrationTask = new Task<Tuple<Boolean, Int32>>(() =>
|
|
{
|
|
try
|
|
{
|
|
var genesis = (GenesisMeter)baseMeter;
|
|
genesis.QuickLogin();
|
|
genesis.BuildAndCheckCalibFactorsAllChannels(StoreRefVolume, StoreTestTimeRef, calFactor);
|
|
|
|
//genesis.SetCalibFactorsAllChannels(true);
|
|
genesis.SetCalibFactorsAllChannels(false);
|
|
|
|
return new Tuple<Boolean, Int32>(true, baseMeter.Slot);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.Error(ex, "Calibration went wrong");
|
|
return new Tuple<Boolean, Int32>(false, baseMeter.Slot);
|
|
}
|
|
});
|
|
|
|
taskList.Add(calibrationTask);
|
|
}
|
|
}
|
|
|
|
|
|
setBusy(true, "Speicher Zielwert Justage");
|
|
taskList.ForEach(ct => ct.Start());
|
|
|
|
var t = new Task(() =>
|
|
{
|
|
Task.WaitAll(taskList.ToArray());
|
|
|
|
Boolean overallResult = true;
|
|
foreach (var item in taskList)
|
|
{
|
|
if (item.Result.Item1)
|
|
{
|
|
setColor("Zielwert Justage [%]", item.Result.Item2, Color.Green);
|
|
setColor("Seriennummer", item.Result.Item2, Color.Green);
|
|
CalibrationIsDone[item.Result.Item2] = LegacyCalibrationResult.Good;
|
|
}
|
|
else
|
|
{
|
|
setColor("Zielwert Justage [%]", item.Result.Item2, Color.LightYellow);
|
|
setColor("Seriennummer", item.Result.Item2, Color.LightYellow);
|
|
CalibrationIsDone[item.Result.Item2] = LegacyCalibrationResult.BadRetry;
|
|
overallResult = false;
|
|
}
|
|
|
|
}
|
|
setBusy(false);
|
|
if (overallResult == false)
|
|
{
|
|
var r = MessageBox.Show(@"Calibration went wrong", @"Retry", MessageBoxButtons.AbortRetryIgnore);
|
|
|
|
foreach (var changesta in CalibrationIsDone.ToList())
|
|
{
|
|
if (changesta.Value != LegacyCalibrationResult.Good)
|
|
{
|
|
switch (r)
|
|
{
|
|
case DialogResult.Abort:
|
|
CalibrationIsDone[changesta.Key] = LegacyCalibrationResult.BadAbort;
|
|
break;
|
|
case DialogResult.Ignore:
|
|
CalibrationIsDone[changesta.Key] = LegacyCalibrationResult.BadIgnor;
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
}
|
|
);
|
|
t.Start();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.Error(ex, $"error on btnOk_Click()");
|
|
}
|
|
}
|
|
private void btnUpdate_Click(Object sender, EventArgs e)
|
|
{
|
|
ManualUpdate();
|
|
//if (RefeshTimer.Enabled)
|
|
//{
|
|
// RefeshTimer.Stop();
|
|
// RefeshTimer.Start();
|
|
//}
|
|
}
|
|
|
|
private void cbxExpert_CheckedChanged(Object sender, EventArgs e)
|
|
{
|
|
dgvBatch.ClearSelection();
|
|
ExpertMode(cbxExpert.Checked);
|
|
}
|
|
|
|
private void nudFactor_ValueChanged(Object sender, EventArgs e)
|
|
{
|
|
foreach (var basemeter in batch.ListOfMeters)
|
|
{
|
|
updateCell("Zielwert Justage [%]", basemeter.Slot, nudFactor.Value.ToString(), Color.Beige);
|
|
}
|
|
}
|
|
|
|
private void ctlBatch_ControlRemoved(Object sender, ControlEventArgs e)
|
|
{
|
|
Close();
|
|
}
|
|
|
|
private void Close()
|
|
{
|
|
if (stopWatch != null)
|
|
{
|
|
stopWatch.Stop();
|
|
stopWatch = null;
|
|
}
|
|
|
|
//if (RefeshTimer != null)
|
|
//{
|
|
// RefeshTimer.Enabled = false;
|
|
// RefeshTimer = null;
|
|
//}
|
|
//if (RefreshTimerWatch != null)
|
|
//{
|
|
// RefreshTimerWatch.Enabled = false;
|
|
// RefreshTimerWatch = null;
|
|
//}
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region helper
|
|
|
|
private String doubleToStringFormat(Double Value, Int32 digits = 2)
|
|
{
|
|
var text = "-";
|
|
if (Value != double.NaN)
|
|
{
|
|
text = string.Format("{0:N" + digits + "}", Value);
|
|
}
|
|
return text;
|
|
|
|
}
|
|
|
|
public void TryInvoke(Delegate d)
|
|
{
|
|
if (IsHandleCreated)
|
|
{
|
|
Invoke(d);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
void ICtlBatch.Dispose(Boolean fromCode)
|
|
{
|
|
Dispose(fromCode);
|
|
}
|
|
|
|
private void ctlBatch_Resize(Object sender, EventArgs e)
|
|
{
|
|
//181
|
|
dgvBatch.Width = Width - 181;
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// Clean up any resources being used.
|
|
/// </summary>
|
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
|
protected override void Dispose(Boolean disposing)
|
|
{
|
|
if (batch != null)
|
|
{
|
|
batch.RemoveAllMeters();
|
|
batch.Dispose();
|
|
}
|
|
|
|
|
|
if (disposing && (components != null))
|
|
{
|
|
components.Dispose();
|
|
}
|
|
base.Dispose(disposing);
|
|
}
|
|
|
|
public String GetVersion()
|
|
{
|
|
var taskList = new List<Task<Boolean>>();
|
|
foreach (var basemeter in batch.ListOfMeters)
|
|
{
|
|
if (basemeter is GenesisMeter)
|
|
{
|
|
|
|
var calibrationTask = new Task<Boolean>(() =>
|
|
{
|
|
try
|
|
{
|
|
var genesis = (GenesisMeter)basemeter;
|
|
genesis.PushProgress("LegacyGenCtl", Assembly.GetExecutingAssembly().GetName().Version.ToString());
|
|
return true;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.Error(ex, "PushProgress went wrong");
|
|
return false;
|
|
}
|
|
});
|
|
|
|
|
|
taskList.Add(calibrationTask);
|
|
}
|
|
}
|
|
|
|
taskList.ForEach(ct => ct.Start());
|
|
Task.WaitAll(taskList.ToArray());
|
|
|
|
return Assembly.GetExecutingAssembly().GetName().Version.ToString();
|
|
}
|
|
|
|
|
|
public void SetTestSetupContainer(dynamic vbContainer)
|
|
{
|
|
if (vbContainer is TestSetupContainer container)
|
|
{
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
sb.AppendLine($"WatingForDecision={container.WatingForDecision}");
|
|
sb.AppendLine($"TempSouce={container.TempSouce}");
|
|
sb.AppendLine($"MeterSize={container.MeterSize}");
|
|
sb.AppendLine($"DelayInSBeforStart={container.DelayInSBeforStart}");
|
|
sb.AppendLine($"AllChanelsRequired={container.AllChanelsRequired}");
|
|
sb.AppendLine($"ProductionMode={container.ProductionMode}");
|
|
|
|
foreach (var item in container.meterTestSettings)
|
|
{
|
|
if (item == null)
|
|
{
|
|
continue;
|
|
}
|
|
sb.AppendLine($"Slot={item.Slot}");
|
|
sb.AppendLine($"SerialNr={item.SerialNr}");
|
|
sb.AppendLine($"FlowTesting={item.FlowTesting}");
|
|
sb.AppendLine($"PreAdjustment={item.PreAdjustment}");
|
|
sb.AppendLine($"FlowAdjustment={item.FlowAdjustment}");
|
|
sb.AppendLine($"FlowAdjustmentTarget={item.FlowAdjustmentTarget}");
|
|
}
|
|
_logger.Info($"SetTestSetupContainer ({sb}) ");
|
|
//MessageBox.Show(sb.ToString());
|
|
TestSetupContainer = vbContainer;
|
|
}
|
|
}
|
|
|
|
public void PrepareBatch(Boolean useRequest, Boolean rawLogging, Boolean checkAllChannels, Boolean manualAdjustment, String ControlSrt)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
}
|
|
}
|