/// /// Copyright (c) 2019 Sensus Slovensko a.s. /// using System; using System.Collections.Generic; using log4net; using Config.Entities; using Results; using Results.Entities; using TBF.Resources; using TBF.UiBridge; namespace TBF.BenchControl.TestMethods.ManualEntry { public class ManualEntrySeq : Sequences.SequenceBase { private static readonly ILog log = LogManager.GetLogger(typeof(ManualEntrySeq)); System.Windows.Forms.Form modelessDlg; /// delegate void ManualEntryFormDlgt(ManualEntrySeq myRef, MeterTestRslt mtr, string prompt, IList items); /// void OpenManualEntryForm(ManualEntrySeq myRef, MeterTestRslt mtr, string prompt, IList items) { myRef.modelessDlg = new ManualEntryForm(mtr, prompt, items); modelessDlg.Show(); } /// /// Adjustment method sequence /// /// Test entity /// /// Event.Done . . . . . . . OK /// Event.UiCmdStop . . . . Stopped by the user using the on-screen button STOP /// Event.OpArgumentError . Target flow is out of range /// Event.Error . . . . . . Unspecified error /// public IList Execute(Test test, int repetitionNr, bool isLastRepetition, ManualEntryCfg cfg, DebugMode mode) { IList e; /// Events from currently running operations checkUiOp = new Operations.CheckUIOp(true); /// Runs in more then one state /// Start the test, initialize test results Bridge.OnTestSelected(this, new TestSelectedEventArgs(test, repetitionNr, inPath, benchPath, outPath, sensPath, heatMetersPath, 0)); string testName = Results.Utils.GetTestName(test.Name, test.Repeats, repetitionNr); /// /// Populate TestResult data entity with default data /// Results.Entities.TestRslt tstRslt = BatchRslts.GetTestRslt(testName, test.Part); if (tstRslt != null) { Results.Utils.GetCounterStates(tstRslt, Program.LocalSettings.Counters); UpdateTempPressDensAmb(tstRslt); /// Main results tstRslt.MethodClass = TbfComponents.FindComponent(test.Method).ClassName; tstRslt.StartTime = DateTime.Now; tstRslt.FlowSetTime = 0; tstRslt.TestTime = 0; tstRslt.PulsesMaster = 0; tstRslt.MassStartRaw = 0; tstRslt.MassStart = 0; tstRslt.MassEndRaw = 0; tstRslt.MassEnd = 0; tstRslt.MassOfEvapWater = 0; tstRslt.FlowMass = 0; tstRslt.FlowVolume = 0; tstRslt.VolumeMaster = 0; tstRslt.ConstMasterRaw = 0; tstRslt.ConstMasterCorr = 0; tstRslt.ConstMaster = 0; tstRslt.VolumeCTV = 0; tstRslt.ErrorMaster = 0; tstRslt.FlowMean = 0; tstRslt.FlowStart = 0; tstRslt.FlowEnd = 0; tstRslt.FlowMin = 0; tstRslt.FlowMax = 0; tstRslt.DiverterStart = 0; tstRslt.DiverterEnd = 0; long infoFlags = 0; tstRslt.ErrorFlags = (ErrorFlagsComp != null) ? ErrorFlagsComp.GetErrorFlags(tstRslt, false, false, 0, 0, out infoFlags) : 0; tstRslt.InfoFlags = infoFlags; for (int i = 0; i < BatchRslts.WMPositionsCount; i++) { if (!test.IsPartCompatible(Utils.PartNr(i + 1, BatchRslts.Batch.Compound))) continue; Results.Entities.MeterTestRslt meterRslt = BatchRslts.GetMeterTestRslt(testName, i, CompoundMeterId.Single); if (meterRslt != null) { meterRslt.RegReaderType = 0; meterRslt.PulsesPerLiter = 0; meterRslt.PulsesMeter = 0; meterRslt.PulsesMaster = 0; meterRslt.VolumeStart = 0; meterRslt.VolumeEnd = 0; meterRslt.VolumeMeter = 0; meterRslt.VolumeRef = 0; meterRslt.TestTime = 0; meterRslt.Error = 0; meterRslt.Passed = true; meterRslt.TestDone = true; tstRslt.TestDone = true; } } tstRslt.Components = Results.Entities.Components .UpdateList(BatchRslts.ComponentsList, new Results.Entities.Components((BenchInfo != null) ? BenchInfo.TestBenchId : 1, (BenchInfo != null) ? BenchInfo.TestBenchName : "testbench", inPath.Pump != null ? inPath.Pump.Name : string.Empty, outPath.FlowMeter != null ? outPath.FlowMeter.Name : string.Empty, outPath.Scale != null ? outPath.Scale.Name : string.Empty, outPath.RegulValve != null ? outPath.RegulValve.Name : string.Empty, outPath.Diverter != null ? outPath.Diverter.Name : string.Empty)); IList items = Results.ManualEntryItemSpec.FromStrArray(cfg.Items); foreach (var waterMeter in BatchRslts.Batch.WaterMeters) { if (waterMeter == null && waterMeter.Disabled) continue; MeterTestRslt mtr = waterMeter.GetMeterTestRslt(testName); if ((mtr != null) && (items.Count > 0)) { /// Show the modeless dialog with error indication string prompt = string.Format("{0} {1} {2}", cfg.Prompt, Strings.Water_Meter, waterMeter.WMPosition); Program.MainWnd.Invoke(new ManualEntryFormDlgt(OpenManualEntryForm), new object[] { this, mtr, prompt, items }); State.Create(string.Format("{0}({1}) : Entering data", test.Method, test.Name)) .AddOperation(checkUiOp) .EnterState(); do { e = StateMachine.WaitRunDevsRunOps(); if (e.Contains(Event.Error) || TestAndLogUiCmdStop(test, e)) break; } while (!(modelessDlg as GenericDevices.IHasCompleted).Completed); modelessDlg.Close(); if (e.Contains(Event.Error) || e.Contains(Event.UiCmdStop)) { /// Stop or error detected => force closing the modeless dialog modelessDlg.Close(); while (!(modelessDlg as GenericDevices.IHasCompleted).Completed) ; modelessDlg = null; /// Modeless dialog is closed now if (e.Contains(Event.Error)) { return new List { Event.Error }; } else { return new List { Event.UiCmdStop }; } } //------------------------------------------------ Bridge.OnActivity(this, Strings.Test_in_progress); //------------------------------------------------ } } tstRslt.EndTime = DateTime.Now; /// Update water meter error flags if (ErrorFlagsComp != null) { if (BatchRslts.Batch != null && BatchRslts.Batch.WaterMeters != null) { for (int i = 0; i < BatchRslts.WMPositionsCount; i++) { if (!BatchRslts.Batch.WaterMeters[i].Disabled) { long wmInfoFlags; BatchRslts.Batch.WaterMeters[i].ErrorFlags = ErrorFlagsComp.GetWMtrErrorFlags(BatchRslts.Batch.WaterMeters[i].MeterTestRslts, out wmInfoFlags); BatchRslts.Batch.WaterMeters[i].InfoFlags = wmInfoFlags; } } } } /// Update results Bridge.OnTestCompleted(this, new TestCompletedEventArgs(testName, tstRslt)); } /// Append the results to the CSV-file allResults.Info(TestResult2CsvLine(testName, test.Part)); return new List { Event.Done }; } } }