From 38cbcb6430821869adcef76042cc6633fba195f0 Mon Sep 17 00:00:00 2001 From: Milan Hanajik Date: Wed, 2 Dec 2015 18:03:37 +0100 Subject: [PATCH] iPerl opto data logging format changed, version 1.6.153. --- .../BenchControl/Sequences/MainSeq.cs | 2 + .../BenchControl/StateMachine.cs | 24 +++ .../WaterMeters/iPerl/OptoTelegram.cs | 151 ------------------ .../WaterMeters/iPerl/OptoTelegramRaw.cs | 11 +- .../WaterMeters/iPerl/WaterMeter.cs | 36 +++-- TestBenchFramework/Properties/AssemblyInfo.cs | 4 +- TestBenchFramework/TBF.csproj | 1 - 7 files changed, 65 insertions(+), 164 deletions(-) delete mode 100644 TestBenchFramework/BenchControl/WaterMeters/iPerl/OptoTelegram.cs diff --git a/TestBenchFramework/BenchControl/Sequences/MainSeq.cs b/TestBenchFramework/BenchControl/Sequences/MainSeq.cs index b07a971ae..d69a8965f 100644 --- a/TestBenchFramework/BenchControl/Sequences/MainSeq.cs +++ b/TestBenchFramework/BenchControl/Sequences/MainSeq.cs @@ -423,6 +423,8 @@ namespace TBF.BenchControl.Sequences if (selection == Selection.Cycle) { + StateMachine.CycleStartTimeStamp = DateTime.Now; + TimeEstimateTotal = 0; for (int i = simultWithPurgingCount; i < StateMachine.Tests.Count - simultWithEvacuationCount; i++) { diff --git a/TestBenchFramework/BenchControl/StateMachine.cs b/TestBenchFramework/BenchControl/StateMachine.cs index 55735669c..4e43cfe26 100644 --- a/TestBenchFramework/BenchControl/StateMachine.cs +++ b/TestBenchFramework/BenchControl/StateMachine.cs @@ -75,6 +75,28 @@ namespace TBF.BenchControl static IList states; /// list of states + static DateTime cycleStartTimeStamp; + public static DateTime CycleStartTimeStamp + { + get { return cycleStartTimeStamp; } + set + { + cycleStartTimeStamp = value; + CycleStartYY = (cycleStartTimeStamp.Year % 100).ToString("D2"); + CycleStartMM = cycleStartTimeStamp.Month.ToString("D2"); + CycleStartDD = cycleStartTimeStamp.Day.ToString("D2"); + CycleStartHH_MI_SS = string.Format("{0}_{1}_{2}", + cycleStartTimeStamp.Hour.ToString("D2"), + cycleStartTimeStamp.Minute.ToString("D2"), + cycleStartTimeStamp.Second.ToString("D2")); + } + } + + public static string CycleStartYY; + public static string CycleStartMM; + public static string CycleStartDD; + public static string CycleStartHH_MI_SS; + public static IList DefaultValvesOpen { @@ -538,6 +560,8 @@ namespace TBF.BenchControl static void Worker() { startDateTime = DateTime.Now; + CycleStartTimeStamp = startDateTime; /// To prevent it is undefined + wlog.InfoFormat(" currentTime = {0}s startDateTime = {1}", currentTimeSec.ToString(), startDateTime.ToString()); /// Run all devices for the first time diff --git a/TestBenchFramework/BenchControl/WaterMeters/iPerl/OptoTelegram.cs b/TestBenchFramework/BenchControl/WaterMeters/iPerl/OptoTelegram.cs deleted file mode 100644 index e19137db5..000000000 --- a/TestBenchFramework/BenchControl/WaterMeters/iPerl/OptoTelegram.cs +++ /dev/null @@ -1,151 +0,0 @@ -using System; -using System.Globalization; - -namespace TBF.BenchControl.WaterMeters.iPerl -{ - public class OptoTelegram - { - public static readonly int Length = 42; - - public double EMF; - public Int16 MagneticField; - public double Flow; - public double Volume; - public Int16 Impedance; - public UInt32 Timestamp; - public byte GG; - - string sourceStr; - - - public OptoTelegram() - { - } - - public override string ToString() - { - return sourceStr; - } - - /// - /// Create a configuration structure from a complete byte array - /// - /// Telegram description: - /// - /// AAAAAA[tab]BBBB[tab]CCCC[tab]DDDDDD[tab]EEEE[tab]FFFFFFFF[tab]GG[cr][lf] (42 bytes) - /// - /// Data Comment Type Calculate to decimal - /// ---------------------------------------------------------------- - /// AAAAAA EMF Int24 Value * 0.000000333 - /// BBBB Magnetic field Int16 Value - /// CCCC Flow Int16 Value * 0.225 * Scalig factor - /// DDDDDD Volume Int24 Value / 16000 * Scaling factor in Ltr - /// EEEE Impedance Int16 Value - /// FFFFFFFF Timestamp Uint32 Value / 8192 - /// GG Checksum Byte - /// ---------------------------------------------------------------- - /// - /// Example: - /// FFFFFE 51EA 0000 65324E 0087 F6319DFF 86 - /// FFDD3A 51F9 0000 65324E 0088 F631A60B 45 - /// ... - /// - /// A complete byte array data - /// ConfigStruct or null when byte array was not complete - public static OptoTelegram FromString(string telegram, MeterType meterType) - { - if ((telegram == null) || (telegram.Length < Length) || - (telegram[6] != '\t') || (telegram[11] != '\t') || - (telegram[16] != '\t') || (telegram[23] != '\t') || - (telegram[28] != '\t') || (telegram[37] != '\t') || - (telegram[40] != '\r') || (telegram[41] != '\n')) - { - return null; - } - - OptoTelegram opto = new OptoTelegram(); - - double factor = ScalingFactor(meterType); - - Int32 value; - - //if (Int32.TryParse(telegram.Substring(0, 6), NumberStyles.HexNumber, CultureInfo.CurrentCulture, out value)) - //{ - // Int32 svalue = (value >= 0x00800000) ? (value - 0x01000000) : value; - // opto.EMF = 0.000000333 * (double)svalue; - //} - //else return null; - - //if (Int32.TryParse(telegram.Substring(7, 4), NumberStyles.HexNumber, CultureInfo.CurrentCulture, out value)) - //{ - // Int32 svalue = (value >= 0x00008000) ? (value - 0x00010000) : value; - // opto.MagneticField = (Int16)svalue; - //} - //else return null; - - //if (Int32.TryParse(telegram.Substring(12, 4), NumberStyles.HexNumber, CultureInfo.CurrentCulture, out value)) - //{ - // Int32 svalue = (value >= 0x00008000) ? (value - 0x00010000) : value; - // opto.Flow = 0.225 * (double)svalue * factor; - //} - //else return null; - - if (Int32.TryParse(telegram.Substring(17, 6), NumberStyles.HexNumber, CultureInfo.CurrentCulture, out value)) - { - Int32 svalue = (value >= 0x00800000) ? (value - 0x01000000) : value; - opto.Volume = (double)svalue / 16000.0 * factor; - } - else return null; - - //if (Int32.TryParse(telegram.Substring(24, 4), NumberStyles.HexNumber, CultureInfo.CurrentCulture, out value)) - //{ - // Int32 svalue = (value >= 0x00008000) ? (value - 0x00010000) : value; - // opto.Impedance = (Int16)svalue; - //} - //else return null; - - UInt32 uvalue; - if (UInt32.TryParse(telegram.Substring(29, 8), NumberStyles.HexNumber, CultureInfo.CurrentCulture, out uvalue)) - { - opto.Timestamp = uvalue; - } - else return null; - - //if (UInt32.TryParse(telegram.Substring(38, 2), NumberStyles.HexNumber, CultureInfo.CurrentCulture, out uvalue)) - //{ - // opto.GG = (byte)uvalue; - //} - //else return null; - - opto.sourceStr = telegram.Substring(0, Length - 2); - - return opto; - } - - - /// - /// Scaling factor: - /// 0, 1 (DN15, Coax) . . . . 1 - /// 2 (DN20) . . . . . . . . 2 - /// 3 (DN25) . . . . . . . . 4 - /// 4, 5 (DN26, DN32) . . . . 8 - /// 6 (DN40) . . . . . . . . 16 - /// - /// MeterType (0..6) - /// Scaling factor - public static double ScalingFactor(MeterType meterType) - { - switch (meterType) - { - default: - case MeterType.DN15: - case MeterType.CoaxManifold: return 1.0; - case MeterType.DN20: return 2.0; - case MeterType.DN25: return 4.0; - case MeterType.DN26: - case MeterType.DN32: return 8.0; - case MeterType.DN40: return 16.0; - } - } - } -} diff --git a/TestBenchFramework/BenchControl/WaterMeters/iPerl/OptoTelegramRaw.cs b/TestBenchFramework/BenchControl/WaterMeters/iPerl/OptoTelegramRaw.cs index c4b9ee389..c107ff631 100644 --- a/TestBenchFramework/BenchControl/WaterMeters/iPerl/OptoTelegramRaw.cs +++ b/TestBenchFramework/BenchControl/WaterMeters/iPerl/OptoTelegramRaw.cs @@ -9,6 +9,8 @@ namespace TBF.BenchControl.WaterMeters.iPerl public OptoTelegramFlags flags; + public DateTime DateTime; + public UInt32 EmfRaw; public Int16 MagneticField; public Int16 FlowRaw; @@ -25,7 +27,12 @@ namespace TBF.BenchControl.WaterMeters.iPerl { if (flags == OptoTelegramFlags.OK) { - return string.Format("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}", + return string.Format("{0}:{1}:{2}.{3}\t{4}:\t{5}\t{6}\t{7}\t{8}\t{9}\t{10}\t{11}", + DateTime.Hour.ToString("D2"), + DateTime.Minute.ToString("D2"), + DateTime.Second.ToString("D2"), + DateTime.Millisecond.ToString("D3"), + 0, EmfRaw.ToString("X6"), MagneticField.ToString("X4"), FlowRaw.ToString("X4"), @@ -78,6 +85,8 @@ namespace TBF.BenchControl.WaterMeters.iPerl /// ConfigStruct or null when byte array was not complete public bool UpdateFromString(string telegram) { + DateTime = DateTime.Now; + if ((telegram == null) || (telegram.Length < Length) || (telegram[6] != '\t') || (telegram[11] != '\t') || (telegram[16] != '\t') || (telegram[23] != '\t') || (telegram[28] != '\t') || (telegram[37] != '\t') || diff --git a/TestBenchFramework/BenchControl/WaterMeters/iPerl/WaterMeter.cs b/TestBenchFramework/BenchControl/WaterMeters/iPerl/WaterMeter.cs index 4be4a7c74..e45c363db 100644 --- a/TestBenchFramework/BenchControl/WaterMeters/iPerl/WaterMeter.cs +++ b/TestBenchFramework/BenchControl/WaterMeters/iPerl/WaterMeter.cs @@ -430,12 +430,23 @@ namespace TBF.BenchControl.WaterMeters.iPerl { /// Reset opto data optoDataCount = 0; - optoDataLogFileName = string.Format("{0}_{1}_{2}_{3}_{4}", - (ConfigStruct != null) ? ConfigStruct.PCBNumber2String() : "UnknownPcbNr", - Utils.ToMyString(DateTime.Now), - BenchName, - Name, - (TestName != null ? TestName : string.Empty)); + + /// File name is: PCB_AA_BB_HH_MI_SS..txt + string wmPosition = Name.Substring(5); + if (wmPosition.Length == 1) wmPosition = "0" + wmPosition; + + string flowNr; + if (TestName.ToLower().Contains("q1")) flowNr = "01"; + else if (TestName.ToLower().Contains("q2")) flowNr = "02"; + else if (TestName.ToLower().Contains("q3")) flowNr = "03"; + else if (TestName.ToLower().Contains("adj")) flowNr = "00"; + else flowNr = "99"; + + optoDataLogFileName = string.Format("{0}_{1}_{2}_{3}.txt", + (ConfigStruct != null) ? ConfigStruct.PCBNumber2String() : "UnknownPcbNr", + wmPosition, + flowNr, + StateMachine.CycleStartHH_MI_SS); sampleNr = 0; @@ -495,6 +506,13 @@ namespace TBF.BenchControl.WaterMeters.iPerl { string directory = "C:\\TBF\\ProcessData\\"; /// TODO: determine correct relative path Directory.CreateDirectory(directory); + directory += (StateMachine.CycleStartYY + "\\"); + Directory.CreateDirectory(directory); + directory += (StateMachine.CycleStartMM + "\\"); + Directory.CreateDirectory(directory); + directory += (StateMachine.CycleStartDD + "\\"); + Directory.CreateDirectory(directory); + TextWriter optoLogFile = new StreamWriter(directory + optoDataLogFileName + ".txt"); for (int i = 0; i < optoDataCount; i++) optoLogFile.WriteLine(optoData[i].ToString()); optoLogFile.Close(); @@ -568,7 +586,7 @@ namespace TBF.BenchControl.WaterMeters.iPerl // CR+LF found if (optoState == OptoState.Read) { - if (pos < OptoTelegram.Length - 2) + if (pos < OptoTelegramRaw.Length - 2) { /// CR+LF found too early, truncate the beginning incl CR+LF and keep scanning in this loop allRcvd = allRcvd.Substring(pos + 2); @@ -578,7 +596,7 @@ namespace TBF.BenchControl.WaterMeters.iPerl } synchronized = true; } - // CR+LF found and (pos >= OptoTelegram.Length - 2) + // CR+LF found and (pos >= OptoTelegramRaw.Length - 2) else if (optoData[optoDataCount].UpdateFromString(allRcvd.Substring(pos - OptoTelegramRaw.Length + 2))) { OptoTelegramRreceived(optoData[optoDataCount++], synchronized2); @@ -593,7 +611,7 @@ namespace TBF.BenchControl.WaterMeters.iPerl } else /// optoState == OptoState.Flush { - if (pos < OptoTelegram.Length - 2) + if (pos < OptoTelegramRaw.Length - 2) { /// CR+LF found too early, truncate the beginning incl CR+LF and keep scanning in this loop allRcvd = allRcvd.Substring(pos + 2); diff --git a/TestBenchFramework/Properties/AssemblyInfo.cs b/TestBenchFramework/Properties/AssemblyInfo.cs index 7ab0f28d5..8bc83e8dc 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.6.152.1")] -[assembly: AssemblyFileVersion("1.6.152.1")] +[assembly: AssemblyVersion("1.6.153.1")] +[assembly: AssemblyFileVersion("1.6.153.1")] diff --git a/TestBenchFramework/TBF.csproj b/TestBenchFramework/TBF.csproj index 373913220..5b56f51cf 100644 --- a/TestBenchFramework/TBF.csproj +++ b/TestBenchFramework/TBF.csproj @@ -460,7 +460,6 @@ -