From d4399c23ca8b0b74c22fd56a65e290b3dd199f8d Mon Sep 17 00:00:00 2001 From: Milan Hanajik Date: Mon, 24 Aug 2015 13:52:06 +0200 Subject: [PATCH] DebugMode 'FailureDuringOperation' added. Redrawing results and reading iPerl opto-port more robust with extra exception handling, version 1.5.96. --- .../BenchControl/ComponentBase.cs | 2 +- .../WaterMeters/iPerl/WaterMeter.cs | 30 ++-- TestBenchFramework/Entities/Enums.cs | 9 +- TestBenchFramework/Properties/AssemblyInfo.cs | 4 +- .../Screens/ResultsTabPageCtrl.cs | 137 ++++++++++-------- 5 files changed, 103 insertions(+), 79 deletions(-) diff --git a/TestBenchFramework/BenchControl/ComponentBase.cs b/TestBenchFramework/BenchControl/ComponentBase.cs index 770a11564..fd17f27d4 100644 --- a/TestBenchFramework/BenchControl/ComponentBase.cs +++ b/TestBenchFramework/BenchControl/ComponentBase.cs @@ -18,7 +18,7 @@ namespace TBF.BenchControl public string ParentName { get { return cfg.ParentName; } } public Generic.IComponentFactory Factory { get { return cfg.Factory; } } public int ItemNr { get { return cfg.ItemNr; } } - public Entities.DebugMode DebugLevel { get { return cfg.DebugLevel; } } + public Entities.DebugMode DebugLevel { get { return cfg.DebugLevel; } set { cfg.DebugLevel = value; } } public Entities.LogLevel LogLevel { get { return cfg.LogLevel; } } public IList Corrections { get { return cfg.Corrections; } } diff --git a/TestBenchFramework/BenchControl/WaterMeters/iPerl/WaterMeter.cs b/TestBenchFramework/BenchControl/WaterMeters/iPerl/WaterMeter.cs index 370e02d51..ce984f357 100644 --- a/TestBenchFramework/BenchControl/WaterMeters/iPerl/WaterMeter.cs +++ b/TestBenchFramework/BenchControl/WaterMeters/iPerl/WaterMeter.cs @@ -97,6 +97,7 @@ namespace TBF.BenchControl.WaterMeters.iPerl public Entities.MeterTestResult LastTestResult; public double NominalTestFlow; /// liter per hour + /// /// New calibration factor calculated from the original factor (argument) /// and results of the last test. @@ -123,6 +124,7 @@ namespace TBF.BenchControl.WaterMeters.iPerl } } + /// /// Q2 correction factor calculated from the last test (Q2). /// This factors should be used only for R800 meters. @@ -162,9 +164,6 @@ namespace TBF.BenchControl.WaterMeters.iPerl double volumeLtrEnd1; /// auxiliary buffer1 to keep the end volume before test stops double volumeLtrEnd2; /// auxiliary buffer2 to keep the end volume before test stops double volumeLtrEnd3; /// auxiliary buffer3 to keep the end volume before test stops - double volumeLtrEnd4; /// auxiliary buffer4 to keep the end volume before test stops - double volumeLtrEnd5; /// auxiliary buffer5 to keep the end volume before test stops - double volumeLtrEnd6; /// auxiliary buffer6 to keep the end volume before test stops /// /// Timestamp from the opto telegram @@ -179,9 +178,7 @@ namespace TBF.BenchControl.WaterMeters.iPerl double timestampSecEnd1; double timestampSecEnd2; double timestampSecEnd3; - double timestampSecEnd4; - double timestampSecEnd5; - double timestampSecEnd6; + private Boxes.IntBox pulses; private Boxes.IntBox refPulses; @@ -253,15 +250,28 @@ namespace TBF.BenchControl.WaterMeters.iPerl { if (DebugLevel == Entities.DebugMode.Normal) { - if (optoSerialPortParsingEnabled) + try { - ReadOptoSerialPort(); + if (optoSerialPortParsingEnabled) + ReadOptoSerialPort(); + else + FlushOptoSerialPort(); } - else + catch (Exception e) { - FlushOptoSerialPort(); + DebugLevel = Entities.DebugMode.FailureDuringOperation; + + log.FatalFormat("Redrawing results failed : {0}", e.Message); + if (e.InnerException != null) + { + log.FatalFormat("InnerMessage : {0}", e.InnerException.Message); + } + log.FatalFormat("StackTrace : {0}{1}", Environment.NewLine, e.StackTrace); } } + else if (DebugLevel == Entities.DebugMode.FailureDuringOperation) + { + } } public void RunDeviceAfter() diff --git a/TestBenchFramework/Entities/Enums.cs b/TestBenchFramework/Entities/Enums.cs index 5bd6945ea..20632e09e 100644 --- a/TestBenchFramework/Entities/Enums.cs +++ b/TestBenchFramework/Entities/Enums.cs @@ -68,12 +68,13 @@ namespace TBF.Entities { DetectedOff = -2, DetectedOn = -1, - Normal = 0, /// Normal operation - AutoDetect, /// The component (device) will be auto-detected - Off, /// The component is off + Normal = 0, /// Normal operation + AutoDetect, /// The component (device) will be auto-detected + FailureDuringOperation, /// Failure during operation -> disabled + Off, /// The component is off Record, Reply, - Simulate, /// Test bench simulation, this mode does not require any hardware + Simulate, /// Test bench simulation, this mode does not require any hardware Inherit, Count, } diff --git a/TestBenchFramework/Properties/AssemblyInfo.cs b/TestBenchFramework/Properties/AssemblyInfo.cs index a88f53250..f6e149404 100644 --- a/TestBenchFramework/Properties/AssemblyInfo.cs +++ b/TestBenchFramework/Properties/AssemblyInfo.cs @@ -29,5 +29,5 @@ using System.Runtime.InteropServices; // Build Number // Revision // -[assembly: AssemblyVersion("1.5.95.1")] -[assembly: AssemblyFileVersion("1.5.95.1")] +[assembly: AssemblyVersion("1.5.96.1")] +[assembly: AssemblyFileVersion("1.5.96.1")] diff --git a/TestBenchFramework/Screens/ResultsTabPageCtrl.cs b/TestBenchFramework/Screens/ResultsTabPageCtrl.cs index b448c54b9..618d6199f 100644 --- a/TestBenchFramework/Screens/ResultsTabPageCtrl.cs +++ b/TestBenchFramework/Screens/ResultsTabPageCtrl.cs @@ -135,80 +135,93 @@ namespace TBF.Screens /// void RedrawAll() { - /// - /// Determine whether combined meter results are displayed - /// - combined = ((testResults != null) && - (testResults.Count > 0) && - (testResults[0].MetersKind == Entities.MetersKind.Combined)); - this.SuspendLayout(); - /// Determine how many water meters were enabled for result evaluation and printing - int enabledWMsCount = 0; - bool[] wmIsEnabled = new bool[Program.WMsCount]; + try + { + /// + /// Determine whether combined meter results are displayed + /// + combined = ((testResults != null) && + (testResults.Count > 0) && + (testResults[0].MetersKind == Entities.MetersKind.Combined)); - if (combined) - { - enabledWMsCount = Program.CompoundWMsCount; - } - else - { - for (int mtr0 = 0; mtr0 < Program.WMsCount; mtr0++) + /// Determine how many water meters were enabled for result evaluation and printing + int enabledWMsCount = 0; + bool[] wmIsEnabled = new bool[Program.WMsCount]; + + if (combined) { - if (testResults != null) - { - for (int t = 0; t < testResults.Count; t++) - { - if ((testResults[t].Meters.Count > mtr0) && !testResults[t].Meters[mtr0].Disabled) - { - wmIsEnabled[mtr0] = true; - enabledWMsCount++; - break; - } - } - } + enabledWMsCount = Program.CompoundWMsCount; } - } - - int metersInOneGroup = Math.Max(1, Math.Min(enabledWMsCount, NrMetersInOneGroup)); - int nrGroups = Math.Max(1, (enabledWMsCount + NrMetersInOneGroup - 1) / metersInOneGroup); - - if (MetersArrangement == Forms.ResultsConfig.Meters.Horizontally) - { - flowLayoutPanel.FlowDirection = FlowDirection.LeftToRight; - lvWidth = flowLayoutPanel.Width / metersInOneGroup - 6; - lvHeight = flowLayoutPanel.Height / nrGroups - 6; - } - else - { - flowLayoutPanel.FlowDirection = FlowDirection.TopDown; - lvWidth = flowLayoutPanel.Width / nrGroups - 6; - lvHeight = flowLayoutPanel.Height / metersInOneGroup - 6; - } - flowLayoutPanel.Controls.Clear(); - flowLayoutPanel.WrapContents = true; - flowLayoutPanel.AutoScroll = true; - - bool first = true; - for (int mtr = 1; mtr <= (combined ? Program.CompoundWMsCount : Program.WMsCount); mtr++) - { - if (combined || (testResults != null && testResults.Count > 0 && wmIsEnabled[mtr - 1])) + else { - if (TestsArrangement == Forms.ResultsConfig.TestsAre.Rows) + for (int mtr0 = 0; mtr0 < Program.WMsCount; mtr0++) { - ListView lview = GetResultsTestsAreRows(mtr, mtr); - if (first) { firstListView = lview; first = false; } - if (lview != null) flowLayoutPanel.Controls.Add(lview); + if (testResults != null) + { + for (int t = 0; t < testResults.Count; t++) + { + if ((testResults[t].Meters.Count > mtr0) && !testResults[t].Meters[mtr0].Disabled) + { + wmIsEnabled[mtr0] = true; + enabledWMsCount++; + break; + } + } + } } - else + } + + int metersInOneGroup = Math.Max(1, Math.Min(enabledWMsCount, NrMetersInOneGroup)); + int nrGroups = Math.Max(1, (enabledWMsCount + NrMetersInOneGroup - 1) / metersInOneGroup); + + if (MetersArrangement == Forms.ResultsConfig.Meters.Horizontally) + { + flowLayoutPanel.FlowDirection = FlowDirection.LeftToRight; + lvWidth = flowLayoutPanel.Width / metersInOneGroup - 6; + lvHeight = flowLayoutPanel.Height / nrGroups - 6; + } + else + { + flowLayoutPanel.FlowDirection = FlowDirection.TopDown; + lvWidth = flowLayoutPanel.Width / nrGroups - 6; + lvHeight = flowLayoutPanel.Height / metersInOneGroup - 6; + } + flowLayoutPanel.Controls.Clear(); + flowLayoutPanel.WrapContents = true; + flowLayoutPanel.AutoScroll = true; + + bool first = true; + for (int mtr = 1; mtr <= (combined ? Program.CompoundWMsCount : Program.WMsCount); mtr++) + { + if (combined || (testResults != null && testResults.Count > 0 && wmIsEnabled[mtr - 1])) { - ListView lview = GetResultsTestsAreColumns(mtr, mtr); - if (first) { firstListView = lview; first = false; } - if (lview != null) flowLayoutPanel.Controls.Add(lview); + if (TestsArrangement == Forms.ResultsConfig.TestsAre.Rows) + { + ListView lview = GetResultsTestsAreRows(mtr, mtr); + if (first) { firstListView = lview; first = false; } + if (lview != null) flowLayoutPanel.Controls.Add(lview); + } + else + { + ListView lview = GetResultsTestsAreColumns(mtr, mtr); + if (first) { firstListView = lview; first = false; } + if (lview != null) flowLayoutPanel.Controls.Add(lview); + } } } } + catch (Exception e) + { + log.FatalFormat("Redrawing results failed : {0}", e.Message); + if (e.InnerException != null) + { + log.FatalFormat("InnerMessage : {0}", e.InnerException.Message); + } + log.FatalFormat("StackTrace : {0}{1}", Environment.NewLine, e.StackTrace); + } + this.ResumeLayout(false); }