2074 lines
76 KiB
C#
2074 lines
76 KiB
C#
using ByteArrayStyle;
|
|
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.Hardware.WaterMeter.Genesis.GenesisCore;
|
|
using Xylem.Common.Hardware.WaterMeter.Genesis.Registers;
|
|
using Xylem.Common.Hardware.WaterMeter.WaterMeterCore;
|
|
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, IDisposable
|
|
{
|
|
#region Const Layout
|
|
|
|
private const int LblPositionLeft = 5;
|
|
private const int LblPositionTop = 20;
|
|
private const int LblPositionSize = 70;
|
|
private const int LblPositionHieght = 70;
|
|
private const int LblPositionSpace = 15;
|
|
private const int SizeOfMeter = 140;
|
|
|
|
#endregion
|
|
#region Prop
|
|
private enum Mode
|
|
{
|
|
AutoRefresh,
|
|
View,
|
|
}
|
|
private Mode currentMode = Mode.View;
|
|
private ILogger _logger;
|
|
private Dictionary<int, LegacyCalibrationResult> CalibrationIsDone = new Dictionary<int, LegacyCalibrationResult>();
|
|
public MeterBatch batch;
|
|
//private System.Windows.Forms.Timer RefeshTimer = new System.Windows.Forms.Timer();
|
|
//private System.Windows.Forms.Timer RefeshTimerWatch = new System.Windows.Forms.Timer();
|
|
|
|
private GenesisMeter.Alarm TestBenchReleAlarms = 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<int, GenesisMeter.Alarm> WarningMetersAlarms = new ConcurrentDictionary<int, GenesisMeter.Alarm>();
|
|
private ConcurrentDictionary<int, GenesisMeter.Alarm> ErrorMetersAlarms = new ConcurrentDictionary<int, GenesisMeter.Alarm>();
|
|
|
|
public string MeterDn = "-";
|
|
public double RefPulseValence = 0.0;
|
|
public double PredictedQFlow = 0.0;
|
|
public double PredictedTs = 0.0;
|
|
public double RefError = 0.0;
|
|
|
|
public int CurrentPulse = 0;
|
|
public double CurrentRefVolume = 0.0;
|
|
public int RemainingPulse = 0;
|
|
public string Period = "-";
|
|
public double RefFlowrate = 0.0;
|
|
public double RefTestTime = 0.0;
|
|
public double RefFlowUncorrected = 0.0;
|
|
|
|
public double MeterDefaultCorrection = 0.0;
|
|
|
|
private TestSetupContainer TestsetuptContainer;
|
|
|
|
|
|
private DataTable dtBatch;
|
|
#region busy
|
|
public bool IsBusy { get; private set; }
|
|
|
|
private int? ProgreessTotal = null;
|
|
private int? ProgreessCurrent = null;
|
|
|
|
private Dictionary<int, double> slotErrorFrameDic = new Dictionary<int, double>();
|
|
private Dictionary<string, Tuple<Label, string>> lableValueCollection;
|
|
private bool isFlyingStartStop = true;
|
|
|
|
public bool IsFlyingStartStop { get; private set; }
|
|
|
|
private double StoreRefVolume, StoretestTimeRef;
|
|
private Stopwatch stopWatch = new Stopwatch();
|
|
private Dictionary<int, string> rowIndex = new Dictionary<int, string>();
|
|
#endregion
|
|
#endregion
|
|
#region ctor
|
|
public ctlBatch()
|
|
{
|
|
|
|
_logger = NLogHelper.CreateOrGetMultiLogger("ctlBatch", "", "Batch", "", "");
|
|
_logger.Info($"start construct ctlBatch");
|
|
//RefeshTimerWatch.Enabled = true;
|
|
//RefeshTimerWatch.Interval = 5000;
|
|
//RefeshTimerWatch.Tick += RefeshTimerWatch_Tick;
|
|
InitializeComponent();
|
|
lableValueCollection = new Dictionary<string, Tuple<Label, string>>();
|
|
intiLableValueCollection();
|
|
|
|
this.grbInfo.SuspendLayout();
|
|
this.SuspendLayout();
|
|
this.Disposed += CtlBatch_Disposed;
|
|
_logger.Info($"construct ctlBatch end");
|
|
}
|
|
|
|
private void CtlBatch_Disposed(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
|
|
Close();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.Error(ex, $"error at CtlBatch_Disposed");
|
|
}
|
|
}
|
|
#endregion
|
|
#region busy
|
|
|
|
private void setBusy(bool val, string action = "", bool hideToExternal = false)
|
|
{
|
|
try
|
|
{
|
|
if (!hideToExternal)
|
|
{
|
|
IsBusy = val;
|
|
}
|
|
|
|
if (val)
|
|
{
|
|
TryInvoke(new Action(() =>
|
|
{
|
|
pnlBussy.Visible = true;
|
|
timProgress.Enabled = true;
|
|
lblAction.Text = action;
|
|
pnlBussy.Size = this.Size;
|
|
pnlBussy.Location = new Point(0, 0);
|
|
|
|
|
|
lblAction.Left = (this.ClientSize.Width - lblAction.Width) / 2;
|
|
lblAction.Top = ((this.ClientSize.Height - lblAction.Height) / 2) - (lblBussyHealine.Height * 4);
|
|
lblBussyHealine.Left = (this.ClientSize.Width - lblBussyHealine.Width) / 2;
|
|
lblBussyHealine.Top = (this.ClientSize.Height - lblBussyHealine.Height) / 2 - (lblBussyHealine.Height * 2);
|
|
|
|
|
|
}));
|
|
|
|
}
|
|
else
|
|
{
|
|
ProgreessTotal = null;
|
|
ProgreessCurrent = 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 setProgreess(string text, int total = 0, int current = 0)
|
|
{
|
|
try
|
|
{
|
|
ProgreessTotal = total;
|
|
ProgreessCurrent = current;
|
|
TryInvoke(new Action(() => { lblProgress.Text = $"{text} ({current}/{total})"; }));
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.Error(ex, $"error at setProgreess(text={text},total={total},current={current}");
|
|
}
|
|
|
|
|
|
}
|
|
|
|
private bool 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
|
|
{
|
|
if (AvoidDisposedTimer(sender))
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (IsBusy)
|
|
{
|
|
if (ProgreessTotal.HasValue && ProgreessCurrent.HasValue && !ProgreessTotal.Value.Equals(0) && !ProgreessCurrent.Value.Equals(0))
|
|
{
|
|
try
|
|
{
|
|
TryInvoke(new Action(() => { probarBussy.Value = (int)Math.Round(((double)ProgreessCurrent.Value / (double)ProgreessTotal.Value) * 100, 0); }));
|
|
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
//throw;
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
var current = probarBussy.Value;
|
|
if (current + 1 > 100)
|
|
{
|
|
current = 0;
|
|
}
|
|
TryInvoke(new Action(() => { probarBussy.Value = current + 1; }));
|
|
}
|
|
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.Error(ex, "timProgress_Tick");
|
|
}
|
|
}
|
|
#endregion
|
|
#region refresh
|
|
private void RefeshTimerWatch_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 = (int)(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 RefeshTimerWatch_Tick()");
|
|
}
|
|
|
|
}
|
|
|
|
private void RefeshTimer_Tick(object sender, EventArgs e)
|
|
{
|
|
|
|
|
|
//try
|
|
//{
|
|
// if (this.AvoidDisposedTimer(sender))
|
|
// return;
|
|
// this.UpdateBatch();
|
|
//}
|
|
//catch (Exception ex)
|
|
//{
|
|
// _logger.Error(ex, $"error at RefeshTimer_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 = (int)refTestTime >= pgbEndTime.Maximum ? pgbEndTime.Maximum : (int)refTestTime;
|
|
pnlEndTime.Visible = true;
|
|
}));
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.Error(ex, $"error at updateTotalProgress(refTestTime={refTestTime}");
|
|
}
|
|
|
|
}
|
|
|
|
#endregion
|
|
#region infoLables
|
|
|
|
private void intiLableValueCollection()
|
|
{
|
|
addInfoLbls("MeterDn", "MID", 0, MeterDn);
|
|
addInfoLbls("PulseValence", "Impulswertigkeit", 1, doubleToStringFormat(RefPulseValence, 2));
|
|
addInfoLbls("PredictedQFlow", "Q soll[m³/ h]", 2, doubleToStringFormat(PredictedQFlow, 6));
|
|
addInfoLbls("PredictedTs", "T soll[s]", 3, doubleToStringFormat(PredictedTs, 1));
|
|
addInfoLbls("RefError", "RZ Fehler[%]", 4, doubleToStringFormat(RefError, 3));
|
|
addInfoLbls("CurrentPulse", "Impulse", 6, CurrentPulse.ToString());
|
|
addInfoLbls("CurrentRefVolume", "RZ Volumen m³", 7, doubleToStringFormat(CurrentRefVolume, 6));
|
|
addInfoLbls("RemainingPulse", "Verbleib.Imp", 8, RemainingPulse.ToString());
|
|
addInfoLbls("Period", "Periodendauer", 9, Period);
|
|
addInfoLbls("RefFlow", "Ref Q", 11, doubleToStringFormat(RefFlowrate, 6));
|
|
addInfoLbls("RefFlowUncorrected", "unkor. Ref Q", 12, doubleToStringFormat(RefFlowUncorrected, 6));
|
|
}
|
|
private void addInfoLbls(string Name, string Text, int index, string Value)
|
|
{
|
|
|
|
var tmpLblText = new System.Windows.Forms.Label();
|
|
var tmpLblValue = new System.Windows.Forms.Label();
|
|
this.grbInfo.Controls.Add(tmpLblText);
|
|
this.grbInfo.Controls.Add(tmpLblValue);
|
|
|
|
tmpLblText.AutoSize = true;
|
|
tmpLblText.Location = new System.Drawing.Point(LblPositionLeft, LblPositionTop * (index + 1));
|
|
tmpLblText.Name = $"lblInfo{Name}Text";
|
|
tmpLblText.Size = new System.Drawing.Size(LblPositionSize, LblPositionHieght);
|
|
tmpLblText.TabIndex = index;
|
|
tmpLblText.Text = Text;
|
|
|
|
tmpLblValue.AutoSize = true;
|
|
tmpLblValue.Location = new System.Drawing.Point(LblPositionLeft + LblPositionSize + LblPositionSpace,
|
|
LblPositionTop * (index + 1));
|
|
tmpLblValue.Name = $"lblInfo{Name}Value";
|
|
tmpLblValue.Size = new System.Drawing.Size(LblPositionSize, LblPositionHieght);
|
|
tmpLblValue.TabIndex = index + 1;
|
|
tmpLblValue.Text = Value.ToString();
|
|
|
|
|
|
lableValueCollection.Add(Name, new Tuple<Label, string>(tmpLblValue, Value));
|
|
|
|
|
|
}
|
|
public void updateLableCollection()
|
|
{
|
|
|
|
lableValueCollection["MeterDn"] = new Tuple<Label, string>(lableValueCollection["MeterDn"].Item1, MeterDn);
|
|
lableValueCollection["PulseValence"] =
|
|
new Tuple<Label, string>(lableValueCollection["PulseValence"].Item1, doubleToStringFormat(RefPulseValence, 2));
|
|
lableValueCollection["PredictedQFlow"] =
|
|
new Tuple<Label, string>(lableValueCollection["PredictedQFlow"].Item1, doubleToStringFormat(PredictedQFlow, 6));
|
|
lableValueCollection["PredictedTs"] =
|
|
new Tuple<Label, string>(lableValueCollection["PredictedTs"].Item1, doubleToStringFormat(PredictedTs, 1));
|
|
lableValueCollection["RefError"] =
|
|
new Tuple<Label, string>(lableValueCollection["RefError"].Item1, doubleToStringFormat(RefError, 3));
|
|
lableValueCollection["CurrentPulse"] =
|
|
new Tuple<Label, string>(lableValueCollection["CurrentPulse"].Item1, CurrentPulse.ToString());
|
|
lableValueCollection["CurrentRefVolume"] =
|
|
new Tuple<Label, string>(lableValueCollection["CurrentRefVolume"].Item1, doubleToStringFormat(CurrentRefVolume, 6));
|
|
lableValueCollection["RemainingPulse"] =
|
|
new Tuple<Label, string>(lableValueCollection["RemainingPulse"].Item1, RemainingPulse.ToString());
|
|
lableValueCollection["Period"] = new Tuple<Label, string>(lableValueCollection["Period"].Item1, Period);
|
|
lableValueCollection["RefFlow"] = new Tuple<Label, string>(lableValueCollection["RefFlow"].Item1, doubleToStringFormat(RefFlowrate, 6));
|
|
lableValueCollection["RefFlowUncorrected"] =
|
|
new Tuple<Label, string>(lableValueCollection["RefFlowUncorrected"].Item1, doubleToStringFormat(RefFlowUncorrected, 6));
|
|
|
|
TryInvoke(new Action(() =>
|
|
{
|
|
foreach (var item in lableValueCollection)
|
|
{
|
|
item.Value.Item1.Text = item.Value.Item2;
|
|
}
|
|
}));
|
|
|
|
}
|
|
|
|
#endregion
|
|
#region dataGridview
|
|
private Color? getErrorColor(double meterError, int 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, bool Value)
|
|
{
|
|
TryInvoke(new Action(() =>
|
|
{
|
|
dgvBatch.Rows[rowIndex.First(k => k.Value == Row).Key].Visible = Value;
|
|
}));
|
|
}
|
|
private void updateCellToInput(string Row, int Slot, bool 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, int 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();
|
|
TypeConverter converter = TypeDescriptor.GetConverter(typeof(T));
|
|
if (converter != null)
|
|
{
|
|
return (T)converter.ConvertFrom(value);
|
|
}
|
|
}
|
|
return default(T);
|
|
}
|
|
|
|
private void setColor(string Row, int 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 (this.dgvBatch.InvokeRequired)
|
|
{
|
|
setColor(Row, Slot, c);
|
|
|
|
}
|
|
else
|
|
{
|
|
currentCell.Style.BackColor = c;
|
|
}
|
|
}));
|
|
}
|
|
}
|
|
private void updateCell(string Row, int Slot, double Value, int digits = 2, Color? c = null)
|
|
{
|
|
updateCell(Row, Slot, doubleToStringFormat(Value, digits), c);
|
|
}
|
|
private void updateCell(string Row, int 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<int, 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(bool 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 bool _useRequest = false;
|
|
private bool _rawLogging = true;
|
|
private bool _isAdjustment = false;
|
|
|
|
private bool _checkAllChannels = true;
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="useRequest"></param>
|
|
/// <param name="rawLogging"></param>
|
|
/// <param name="checkAllChannels"></param>
|
|
/// <param name="manualAdjustment">Obsolet</param>
|
|
/// <param name="ControlSrt"></param>
|
|
public void PrepareBatch(string ControlSrt = "JustToCheckUpdate")
|
|
{
|
|
try
|
|
{
|
|
|
|
_logger.Trace($"PrepareBatch ControlSrt : {ControlSrt} ");
|
|
batch = new MeterBatch();
|
|
_useRequest = true;
|
|
_rawLogging = true;
|
|
_checkAllChannels = TestsetuptContainer.AllChanelsRequired;
|
|
|
|
//TryInvoke(new Action(() =>
|
|
//{
|
|
// this.RefeshTimer.Enabled = true;
|
|
//}));
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.Error(ex, $"error at ControlSrt : {ControlSrt}");
|
|
}
|
|
}
|
|
public void AddAllMeters()
|
|
{
|
|
foreach (var item in TestsetuptContainer.meterTestSettings)
|
|
{
|
|
if (item != null && (item.FlowAdjustment || item.FlowTesting))
|
|
{
|
|
AddMeter(item.SerialNr, item.Slot, true);
|
|
}
|
|
}
|
|
|
|
}
|
|
public void AddMeter(string serialNumber, int slot, bool 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.RequestProtocol.AdditionalRetryTimeoutMs = 100;
|
|
meter.SkipPreparationForTestBench = SkipPrepearation;
|
|
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, int slot)
|
|
{
|
|
if (TestsetuptContainer == null)
|
|
{
|
|
TestsetuptContainer = new TestSetupContainer();
|
|
TestsetuptContainer.AllChanelsRequired = true;
|
|
TestsetuptContainer.meterTestSettings = new MeterTestSettings[10];
|
|
}
|
|
|
|
if (!TestsetuptContainer.meterTestSettings.Any(f => f != null && f.Slot == slot))
|
|
{
|
|
TestsetuptContainer.meterTestSettings[slot] = new MeterTestSettings() { SerialNr = serialNumber, Slot = slot, FlowAdjustment = true, FlowTesting = true };
|
|
}
|
|
AddMeter(serialNumber, slot, false);
|
|
}
|
|
|
|
public void RemoveMeter(int slot)
|
|
{
|
|
try
|
|
{
|
|
setBusy(true, $"Entferne EP. {slot}");
|
|
Task.Factory.StartNew(() =>
|
|
{
|
|
var meterToRemove = batch.ListOfMeters.Where(a => a.Slot == slot).First();
|
|
if (meterToRemove != null)
|
|
{
|
|
batch.RemoveMeter(meterToRemove);
|
|
}
|
|
|
|
}).ContinueWith(delegate
|
|
{
|
|
setBusy(false);
|
|
});
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.Error(ex, $"error at RemoveMeter(slot={slot}");
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public void MeterDone(int slot, bool Succeed)
|
|
{
|
|
try
|
|
{
|
|
setBusy(true, $"Set {slot} LCD");
|
|
Task.Factory.StartNew(() =>
|
|
{
|
|
//FF-55-00-00
|
|
var meter = batch.ListOfMeters.First(f => f.Slot == slot);
|
|
if (meter == null)
|
|
{
|
|
return;
|
|
}
|
|
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,true);
|
|
|
|
}
|
|
|
|
|
|
meter.WriteLog($"MeterIsDone {state}");
|
|
|
|
}).ContinueWith(delegate
|
|
{
|
|
setBusy(false);
|
|
});
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.Error(ex, $"error at MeterDone(slot={slot},Succeed={Succeed})");
|
|
}
|
|
}
|
|
|
|
|
|
public void SetErrorFrame(int 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(int slot, string message)
|
|
{
|
|
|
|
try
|
|
{
|
|
Task.Factory.StartNew(() =>
|
|
{
|
|
var meter = batch.ListOfMeters.First(f => f.Slot == slot);
|
|
if (meter == null)
|
|
{
|
|
return;
|
|
}
|
|
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, bool isAdjustment = false, bool IsFlyingStartStop = true)
|
|
{
|
|
try
|
|
{
|
|
_logger.Trace($"Start PrepareMeters(meterDn={meterDn},refPulseValence={refPulseValence},predictedQFlow ={predictedQFlow},predictedTs={predictedTs},refError={refError},isAdjustment={isAdjustment},IsFlyingStartStop={IsFlyingStartStop}");
|
|
WarningMetersAlarms = new ConcurrentDictionary<int, GenesisMeter.Alarm>();
|
|
ErrorMetersAlarms = new ConcurrentDictionary<int, GenesisMeter.Alarm>();
|
|
setBusy(true, $"Bereite Zähler vor");
|
|
Task.Factory.StartNew(() =>
|
|
{
|
|
|
|
initAction(meterDn, refPulseValence, predictedQFlow, predictedTs, refError, isFlyingStartStop);
|
|
|
|
|
|
_isAdjustment = isAdjustment;
|
|
var listOfTasks = new List<Task>();
|
|
var listOfTasksInit = new List<Task>();
|
|
|
|
|
|
if (isAdjustment)
|
|
{
|
|
CalibrationIsDone = new Dictionary<int, 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}");
|
|
|
|
var settings = TestsetuptContainer.meterTestSettings.First(f => f != null && f.Slot == meter.Slot);
|
|
|
|
if (isAdjustment && !settings.FlowAdjustment)
|
|
{
|
|
continue;
|
|
}
|
|
if (!isAdjustment && !settings.FlowTesting)
|
|
{
|
|
continue;
|
|
}
|
|
if (!(meter is GenesisMeter genmeter))
|
|
{
|
|
continue;
|
|
}
|
|
//((GenesisMeter)meter).SkipPrepearationForTestBench = true;
|
|
_logger.Debug($"Add Meter To Grid {meter.Slot}");
|
|
|
|
TryInvoke(new Action(() =>
|
|
{
|
|
AddMeterToGrid(meter.Slot, meter.SerialNumber, genmeter.PcbId, isFlyingStartStop);
|
|
}));
|
|
|
|
|
|
if (!_useRequest)
|
|
{
|
|
continue;
|
|
}
|
|
if (isAdjustment)
|
|
{
|
|
CalibrationIsDone.Add(meter.Slot, LegacyCalibrationResult.Pending);
|
|
}
|
|
if (!((GenesisMeter)meter).IsLoggedOn)
|
|
{
|
|
listOfTasks.Add(new Task(() =>
|
|
{
|
|
var r = ((GenesisMeter)meter).Login();
|
|
//if (r)
|
|
//{
|
|
// var alarms = ((GenesisMeter)meter).GetAlarms();
|
|
// WarningMetersAlarms.AddOrUpdate(meter.Slot, alarms, (key, oldValue) => alarms);
|
|
// ((GenesisMeter)meter).ResetAlarm(TestBenchReleAlarms);
|
|
|
|
//}
|
|
}));
|
|
}
|
|
|
|
listOfTasksInit.Add(new Task(() =>
|
|
{
|
|
var r = ((GenesisMeter)meter).Login();
|
|
if (_useRequest)
|
|
{
|
|
_logger.Debug($"Prepare Meters for Measurement/Adjustment");
|
|
if (isAdjustment)
|
|
{
|
|
((GenesisMeter)meter).InitCalibration();
|
|
}
|
|
else
|
|
{
|
|
((GenesisMeter)meter).InitMeasurement();
|
|
}
|
|
// Reboot, HighPeresur
|
|
//ReadOut Alarms, Show and reset
|
|
_logger.Debug($"Start CheckMetersAreReadyForTest");
|
|
|
|
}
|
|
}));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
listOfTasks.ForEach(t => t.Start());
|
|
Task.WaitAll(listOfTasks.ToArray());
|
|
listOfTasksInit.ForEach(t => t.Start());
|
|
Task.WaitAll(listOfTasksInit.ToArray());
|
|
TryInvoke(new Action(() =>
|
|
{
|
|
UpdateBatch();
|
|
}));
|
|
setBusy(false, "", true);
|
|
//CheckMetersAreReadyForTestStatic();
|
|
|
|
}).ContinueWith(delegate
|
|
{
|
|
|
|
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)
|
|
{
|
|
((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 = TestsetuptContainer.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 = TestsetuptContainer.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 = TestsetuptContainer.meterTestSettings.First(f => f != null && f.Slot == item.Slot);
|
|
|
|
if (_isAdjustment && !settings.FlowAdjustment)
|
|
{
|
|
continue;
|
|
}
|
|
if (!_isAdjustment && !settings.FlowTesting)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_isAdjustment)
|
|
{
|
|
int retrys = 0;
|
|
while (item.GetCalibrationState() != MeasurementStates.IsCompleted && retrys < nrOfRetrys)
|
|
{
|
|
if (retrys == (nrOfRetrys / 2))
|
|
{
|
|
item.StopCalibration();
|
|
}
|
|
Thread.Sleep(100);
|
|
retrys = retrys + 1;
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
int retrys = 0;
|
|
//remove channel filter 0
|
|
var onlyChnl = _checkAllChannels ? null : (int?)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");
|
|
}
|
|
}
|
|
bool ICtlBatch.IsBusy()
|
|
{
|
|
return IsBusy;
|
|
}
|
|
|
|
|
|
private MeasurementResults? GetMeasurementResult(int Slot, int 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(int Slot, int 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(TestBenchReleAlarms))
|
|
{
|
|
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(int 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 = TestsetuptContainer.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(int Slot, string SerialNumber, string PcbId, bool IsFlyingStartStop)
|
|
{
|
|
try
|
|
{
|
|
|
|
//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 += RefeshTimer_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, bool isFlyingStartStop = true)
|
|
{
|
|
TryInvoke(new Action(() =>
|
|
{
|
|
initDt();
|
|
pnlEndTime.Visible = false;
|
|
pnlCalibration.Visible = false;
|
|
IsFlyingStartStop = isFlyingStartStop;
|
|
Clear();
|
|
intiLableValueCollection();
|
|
MeterDn = meterDn;
|
|
RefPulseValence = refPulseValence;
|
|
PredictedTs = predictedTs;
|
|
RefError = refError;
|
|
currentMode = Mode.AutoRefresh;
|
|
//this.RefeshTimer.Interval = 10000;
|
|
//this.RefeshTimer.Tick += new EventHandler(this.RefeshTimer_Tick);
|
|
//this.RefeshTimer.Enabled = true;
|
|
pgbUpdate.Maximum = 10000;
|
|
|
|
|
|
|
|
updateLableCollection();
|
|
ExpertMode(cbxExpert.Checked);
|
|
// dgvBatch.Size = new Size(SizeOfMeter, dgvBatch.Size.Height);
|
|
pgbEndTime.Maximum = (int)predictedTs;
|
|
}));
|
|
|
|
}
|
|
|
|
public void Init(string meterDn = "-", double refPulseValence = 0, double predictedQFlow = 0, double predictedTs = 0, double refError = 0, bool isFlyingStartStop = true)
|
|
{
|
|
try
|
|
{
|
|
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, int currentPulse = 0, double currentRefVolume = 0, int remainingPulse = 0, string period = "-", bool 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;
|
|
updateLableCollection();
|
|
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
|
|
{
|
|
this.stopWatch.Reset();
|
|
var listOfStates = new List<MeasurementStates>();
|
|
foreach (var item in batch.ListOfMeters)
|
|
{
|
|
try
|
|
{
|
|
if (item is GenesisMeter)
|
|
{
|
|
var settings = TestsetuptContainer.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 : (int?)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, false);
|
|
|
|
}
|
|
else
|
|
{
|
|
interResult.Add(_meter.GetMainMeasurementResult(CurrentRefVolume, testtime, false));
|
|
}
|
|
}
|
|
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
|
|
{
|
|
this.currentMode = ctlBatch.Mode.AutoRefresh;
|
|
}
|
|
|
|
TryInvoke(new Action(() =>
|
|
{
|
|
//this.RefeshTimer.Enabled = true;
|
|
}));
|
|
|
|
this.stopWatch.Start();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.Error(ex, $"error on UpdateBatch {ex.Message} ");
|
|
}
|
|
|
|
}
|
|
|
|
public void Clear()
|
|
{
|
|
try
|
|
{
|
|
grbInfo.Controls.Clear();
|
|
lableValueCollection.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<bool, int>>>();
|
|
TryInvoke(new Action(() =>
|
|
{
|
|
pnlCalibration.Visible = false;
|
|
}));
|
|
foreach (var basemeter in batch.ListOfMeters)
|
|
{
|
|
var settings = TestsetuptContainer.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<bool, int>>(() =>
|
|
{
|
|
try
|
|
{
|
|
var genesis = (GenesisMeter)basemeter;
|
|
genesis.ReLogin();
|
|
genesis.BuildAndCheckCalibFactorsAllChannels(StoreRefVolume, StoretestTimeRef, calfactor);
|
|
|
|
//genesis.SetCalibFactorsAllChannels(true);
|
|
genesis.SetCalibFactorsAllChannels(false);
|
|
|
|
return new Tuple<bool, int>(true, basemeter.Slot);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.Error(ex, "Calibration went wrong");
|
|
return new Tuple<bool, int>(false, basemeter.Slot);
|
|
}
|
|
});
|
|
|
|
taskList.Add(calibrationTask);
|
|
}
|
|
}
|
|
|
|
|
|
setBusy(true, "Speicher Zielwert Justage");
|
|
taskList.ForEach(ct => ct.Start());
|
|
|
|
var t = new Task(() =>
|
|
{
|
|
DateTimeOffset till = DateTimeOffset.UtcNow;
|
|
Task.WaitAll(taskList.ToArray());
|
|
|
|
bool 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 (RefeshTimerWatch != null)
|
|
//{
|
|
// RefeshTimerWatch.Enabled = false;
|
|
// RefeshTimerWatch = null;
|
|
//}
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region helper
|
|
|
|
private string doubleToStringFormat(double Value, int digits = 2)
|
|
{
|
|
var text = "-";
|
|
if (Value != double.NaN)
|
|
{
|
|
text = string.Format("{0:N" + digits.ToString() + "}", Value);
|
|
}
|
|
return text;
|
|
|
|
}
|
|
|
|
public void TryInvoke(Delegate d)
|
|
{
|
|
if (this.IsHandleCreated)
|
|
{
|
|
Invoke(d);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
void ICtlBatch.Dispose(bool fromCode)
|
|
{
|
|
Dispose(fromCode);
|
|
}
|
|
|
|
private void ctlBatch_Resize(object sender, EventArgs e)
|
|
{
|
|
//181
|
|
dgvBatch.Width = this.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(bool 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<bool>>();
|
|
foreach (var basemeter in batch.ListOfMeters)
|
|
{
|
|
if (basemeter is GenesisMeter)
|
|
{
|
|
|
|
var calibrationTask = new Task<bool>(() =>
|
|
{
|
|
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($"DirectStart={container.DirectStart}");
|
|
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());
|
|
TestsetuptContainer = vbContainer;
|
|
}
|
|
}
|
|
|
|
public void PrepareBatch(bool useRequest, bool rawLogging, bool checkAllChannels, bool manualAdjustment, string ControlSrt)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
}
|
|
}
|