From 5586f58c6e57932dee4e944337eb9fdda4359f70 Mon Sep 17 00:00:00 2001 From: Milan Hanajik Date: Mon, 25 Feb 2019 16:15:26 +0100 Subject: [PATCH] iPerlCommunicationForm : Better try/catch, more logging, ver. 2.18.1152 --- .../CommCompletedEventArgs.cs | 13 +- .../iPerlCommunicationForm.cs | 180 +++++++++--------- TBF/Properties/AssemblyInfo.cs | 4 +- 3 files changed, 108 insertions(+), 89 deletions(-) diff --git a/TBF/BenchControl/TestMethods/iPerlCommunication/CommCompletedEventArgs.cs b/TBF/BenchControl/TestMethods/iPerlCommunication/CommCompletedEventArgs.cs index 44a015806..3aafcfd0d 100644 --- a/TBF/BenchControl/TestMethods/iPerlCommunication/CommCompletedEventArgs.cs +++ b/TBF/BenchControl/TestMethods/iPerlCommunication/CommCompletedEventArgs.cs @@ -1,5 +1,5 @@ /// -/// Copyright (c) 2015-2017 Sensus Metering Systems +/// Copyright (c) 2015-2019 Sensus Metering Systems /// Author: Milan Hanajík /// using System; @@ -24,5 +24,16 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication this.CommMessage = commMessage; this.CommErr = commErr; } + + public override string ToString() + { + return string.Format("Thread={0} WMNr0={1} IHead={2} WM={3} CommMsg={4} CommErr={5}", + ThreadId, + WMNr0, + (Ihead != null) ? Ihead.Name : "null", + Wm.WMPosition, + (CommMessage != null) ? CommMessage : "null", + CommErr); + } } } diff --git a/TBF/BenchControl/TestMethods/iPerlCommunication/iPerlCommunicationForm.cs b/TBF/BenchControl/TestMethods/iPerlCommunication/iPerlCommunicationForm.cs index 0ffc3aa9b..5dcfbde21 100644 --- a/TBF/BenchControl/TestMethods/iPerlCommunication/iPerlCommunicationForm.cs +++ b/TBF/BenchControl/TestMethods/iPerlCommunication/iPerlCommunicationForm.cs @@ -2187,100 +2187,108 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication void DoOnCommCompleted(object sender, CommCompletedEventArgs data) { - /// - /// Update the text message - /// - if (data.WMNr0 >= 0) messages[data.WMNr0].Text = data.CommMessage; + try + { + /// + /// Update the text message + /// + if (data.WMNr0 >= 0) messages[data.WMNr0].Text = data.CommMessage; - /// - /// Update head active/inactive switch - /// - if (data.WMNr0 >= 0 && data.CommErr == CommErr.HeadDisabledByUser) - { - /// iPerl head was disabled by the user - ckbState[data.WMNr0] = false; - checkBoxes[data.WMNr0].Checked = false; - checkBoxes[data.WMNr0].Enabled = false; - if (data.Ihead != null) data.Ihead.Disabled = true; - if (data.Wm != null) data.Wm.Disabled = true; - } - else if (data.WMNr0 >= 0 && data.CommErr == CommErr.None) - { - /// One RFID communication successful => iPerl cannot be disabled by the user anymore - ckbState[data.WMNr0] = true; - checkBoxes[data.WMNr0].Checked = true; - checkBoxes[data.WMNr0].Enabled = false; - } - - /// - /// Update opto-communication indication - /// - for (int i = 0; i < iperlHeads.Count; i++) - { - if (iperlHeads[i] == null || iperlHeads[i].Disabled) + /// + /// Update head active/inactive switch + /// + if (data.WMNr0 >= 0 && data.CommErr == CommErr.HeadDisabledByUser) { - counters[i].BackColor = DisabledColor; + /// iPerl head was disabled by the user + ckbState[data.WMNr0] = false; + checkBoxes[data.WMNr0].Checked = false; + checkBoxes[data.WMNr0].Enabled = false; + if (data.Ihead != null) data.Ihead.Disabled = true; + if (data.Wm != null) data.Wm.Disabled = true; + } + else if (data.WMNr0 >= 0 && data.CommErr == CommErr.None) + { + /// One RFID communication successful => iPerl cannot be disabled by the user anymore + ckbState[data.WMNr0] = true; + checkBoxes[data.WMNr0].Checked = true; + checkBoxes[data.WMNr0].Enabled = false; + } + + /// + /// Update opto-communication indication + /// + for (int i = 0; i < iperlHeads.Count; i++) + { + if (iperlHeads[i] == null || iperlHeads[i].Disabled) + { + counters[i].BackColor = DisabledColor; + } + else + { + switch (iperlHeads[i].CheckFlowDirection()) + { + case OptoHeadState.OptoAndDirOK: + counters[i].BackColor = OptoAndDirOKColor; + break; + + case OptoHeadState.DirNok: + counters[i].BackColor = DirNokColor; + break; + + default: + case OptoHeadState.OptoNok: + counters[i].BackColor = OptoNokColor; + break; + } + } + } + +#if !TURA_SPECIAL + /// + /// Branch + /// + lock (this) + { + completedCommCount++; + if (cfg.UseMuxBoards && completedCommCount < muxBrdOrGroup14Nrs.Count) return; + if (!cfg.UseMuxBoards && completedCommCount < 4) return; + completedCommCount = 0; + } +#endif + + if (currentGroup < lastGroup) + { + /// Go to the next step / next group + if (quido != null) + { + quido.SetOutputs((ushort)(16 - currentGroup - 1)); + Thread.Sleep(2000); + } + currentGroup++; + } + else if (currentActivityStep + 1 < multiTestParams.Count) + { + currentGroup = 0; + currentActivityStep++; + activityLabel.Text = multiTestParams[currentActivityStep].Activity; + if (quido != null) + { + quido.SetOutputs((ushort)(16 - currentGroup - 1)); + Thread.Sleep(2000); + } + currentGroup++; } else { - switch (iperlHeads[i].CheckFlowDirection()) - { - case OptoHeadState.OptoAndDirOK: - counters[i].BackColor = OptoAndDirOKColor; - break; - - case OptoHeadState.DirNok: - counters[i].BackColor = DirNokColor; - break; - - default: - case OptoHeadState.OptoNok: - counters[i].BackColor = OptoNokColor; - break; - } + /// Wait until all threads are finished + workerThreads[data.ThreadId].Join(2000); + NormalClose(); } } - -#if !TURA_SPECIAL - /// - /// Branch - /// - lock (this) + catch (Exception e) { - completedCommCount++; - if (cfg.UseMuxBoards && completedCommCount < muxBrdOrGroup14Nrs.Count) return; - if (!cfg.UseMuxBoards && completedCommCount < 4) return; - completedCommCount = 0; - } -#endif - - if (currentGroup < lastGroup) - { - /// Go to the next step / next group - if (cfg.UseMuxBoards && (quido != null)) - { - quido.SetOutputs((ushort)(16 - currentGroup - 1)); - Thread.Sleep(2000); - } - currentGroup++; - } - else if (currentActivityStep + 1 < multiTestParams.Count) - { - currentGroup = 0; - currentActivityStep++; - activityLabel.Text = multiTestParams[currentActivityStep].Activity; - if (cfg.UseMuxBoards && (quido != null)) - { - quido.SetOutputs((ushort)(16 - currentGroup - 1)); - Thread.Sleep(2000); - } - currentGroup++; - } - else - { - /// Wait until all threads are finished - workerThreads[data.ThreadId].Join(2000); - NormalClose(); + log.ErrorFormat("DoOnCommCompleted({0}) failed: {1}", data, e.Message); + log.FatalFormat("StackTrace : {0}{1}", Environment.NewLine, e.StackTrace); } } diff --git a/TBF/Properties/AssemblyInfo.cs b/TBF/Properties/AssemblyInfo.cs index 27b0ed6c2..86c1930ff 100644 --- a/TBF/Properties/AssemblyInfo.cs +++ b/TBF/Properties/AssemblyInfo.cs @@ -29,5 +29,5 @@ using System.Runtime.InteropServices; // Build Number // Revision // -[assembly: AssemblyVersion("2.18.1151.0")] -[assembly: AssemblyFileVersion("2.18.1151.0")] +[assembly: AssemblyVersion("2.18.1152.0")] +[assembly: AssemblyFileVersion("2.18.1152.0")]