From 2f3f67c82e5b2623b1deb2fa50fd2f9c42cee62d Mon Sep 17 00:00:00 2001 From: Milan Hanajik Date: Tue, 18 Dec 2018 12:37:49 +0100 Subject: [PATCH] IPerlHead : more logging when saving opto data, ver. 2.18.1103 --- .../iPerlCommunication/iPerlHead/IperlHead.cs | 112 +++++++++--------- TBF/Properties/AssemblyInfo.cs | 4 +- 2 files changed, 61 insertions(+), 55 deletions(-) diff --git a/TBF/BenchControl/TestMethods/iPerlCommunication/iPerlHead/IperlHead.cs b/TBF/BenchControl/TestMethods/iPerlCommunication/iPerlHead/IperlHead.cs index 09632f29d..80b5a908b 100644 --- a/TBF/BenchControl/TestMethods/iPerlCommunication/iPerlHead/IperlHead.cs +++ b/TBF/BenchControl/TestMethods/iPerlCommunication/iPerlHead/IperlHead.cs @@ -573,22 +573,21 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication.iPerlHead if (wmPosition.Length == 1) wmPosition = "0" + wmPosition; SensusTestInfo[] testInfos = SensusTestInfo.GetTestInfos(LogType); - string flowNr = null; + + optoDataLogFileName = null; + /// foreach (var ti in testInfos) { if ((testName != null) && (testName == ti.TestName)) { - flowNr = ti.PruefungsNrStr; + optoDataLogFileName = string.Format("{0}_{1}_{2}_{3}.txt", + (ConfigStruct != null) ? ConfigStruct.GetPcbNrString() : "UnknownPcbNr", + wmPosition, + ti.PruefungsNrStr, + StateMachine.CycleStartTimeStamp.ToString("HH_mm_ss")); break; } } - if (flowNr == null) flowNr = "99"; - - optoDataLogFileName = string.Format("{0}_{1}_{2}_{3}.txt", - (ConfigStruct != null) ? ConfigStruct.GetPcbNrString() : "UnknownPcbNr", - wmPosition, - flowNr, - StateMachine.CycleStartTimeStamp.ToString("HH_mm_ss")); StartParsingOptoSerialPort(); } @@ -660,57 +659,64 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication.iPerlHead /// void SaveOptoData() { - string directory = string.Format("C:\\TBF\\ProcessData\\{0}\\{1}\\{2}\\", - StateMachine.CycleStartTimeStamp.ToString("yy"), - StateMachine.CycleStartTimeStamp.ToString("MM"), - StateMachine.CycleStartTimeStamp.ToString("dd")); - string fullFileName = directory + optoDataLogFileName; - try + if (optoDataLogFileName != null) { - Directory.CreateDirectory(directory); + string directory = Path.Combine("C:\\TBF\\ProcessData", StateMachine.CycleStartTimeStamp.ToString("yy"), + StateMachine.CycleStartTimeStamp.ToString("MM"), + StateMachine.CycleStartTimeStamp.ToString("dd")); + string fullFileName = Path.Combine(directory, optoDataLogFileName); - double scalFact = ScalingFactor(); + log.WarnFormat("Saving {0} opto data to {1}", Name, fullFileName); - using (TextWriter optoLogFile = new StreamWriter(fullFileName)) - { - if (optoDataCount <= MaxOptoDataCount) + try + { + Directory.CreateDirectory(directory); + + double scalFact = ScalingFactor(); + + using (TextWriter optoLogFile = new StreamWriter(fullFileName)) { - /// Telegrams are stored continuously, save them. - optoLogFile.WriteLine(optoData[0].ToString(scalFact, null)); - for (int i = 1; i < optoDataCount; i++) + if (optoDataCount <= MaxOptoDataCount) { - optoLogFile.WriteLine(optoData[i].ToString(scalFact, optoData[i - 1])); + /// Telegrams are stored continuously, save them. + optoLogFile.WriteLine(optoData[0].ToString(scalFact, null)); + for (int i = 1; i < optoDataCount; i++) + { + optoLogFile.WriteLine(optoData[i].ToString(scalFact, optoData[i - 1])); + } } + else /// if (optoDataCount > MaxOptoDataCount) + { + /// Buffer overflow + /// First part of the buffer is saved as is + optoLogFile.WriteLine(optoData[0].ToString(scalFact, null)); + for (int i = 1; i < StartOptoDataCount; i++) + { + optoLogFile.WriteLine(optoData[i].ToString(scalFact, optoData[i - 1])); + } + + optoLogFile.WriteLine(" ..."); + + /// Second part of the buffer is an overflowed circular buffer + optoLogFile.WriteLine(optoData[(optoDataCount - MaxOptoDataCount) % EndOptoDataCount + StartOptoDataCount].ToString(scalFact, null)); + for (int i = optoDataCount - EndOptoDataCount + 1; i < optoDataCount; i++) + { + optoLogFile.WriteLine(optoData[(i - StartOptoDataCount) % EndOptoDataCount + StartOptoDataCount] + .ToString(scalFact, optoData[(i - 1 - StartOptoDataCount) % EndOptoDataCount + StartOptoDataCount])); + } + } + + log.WarnFormat("{0} opto data successfully saved: {1} lines", Name, optoDataCount); + + optoLogFile.Close(); } - else /// if (optoDataCount > MaxOptoDataCount) - { - /// Buffer overflow - /// First part of the buffer is saved as is - optoLogFile.WriteLine(optoData[0].ToString(scalFact, null)); - for (int i = 1; i < StartOptoDataCount; i++) - { - optoLogFile.WriteLine(optoData[i].ToString(scalFact, optoData[i - 1])); - } - - optoLogFile.WriteLine(" ..."); - - /// Second part of the buffer is an overflowed circular buffer - optoLogFile.WriteLine(optoData[(optoDataCount - MaxOptoDataCount) % EndOptoDataCount + StartOptoDataCount].ToString(scalFact, null)); - for (int i = optoDataCount - EndOptoDataCount + 1; i < optoDataCount; i++) - { - optoLogFile.WriteLine(optoData[(i - StartOptoDataCount) % EndOptoDataCount + StartOptoDataCount] - .ToString(scalFact, optoData[(i - 1 - StartOptoDataCount) % EndOptoDataCount + StartOptoDataCount])); - } - } - - optoLogFile.Close(); - } - } - catch (Exception exc) - { - File.Delete(fullFileName); - log.ErrorFormat(string.Format("Error writing into file {0}", fullFileName)); - log.ErrorFormat(string.Format("Exception message: {0}", exc.Message)); + } + catch (Exception exc) + { + File.Delete(fullFileName); + log.ErrorFormat(string.Format("Error writing into file {0}", fullFileName)); + log.ErrorFormat(string.Format("Exception message: {0}", exc.Message)); + } } } diff --git a/TBF/Properties/AssemblyInfo.cs b/TBF/Properties/AssemblyInfo.cs index b6f0019c5..5d3d7fdeb 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.1102.0")] -[assembly: AssemblyFileVersion("2.18.1102.0")] +[assembly: AssemblyVersion("2.18.1103.0")] +[assembly: AssemblyFileVersion("2.18.1103.0")]