DatastreamFrame logging fixed, FrameFormat handling improved, PD log file names fixed, ver. 2.18.910

This commit is contained in:
Milan Hanajik
2018-06-01 13:21:11 +02:00
parent 5d4dedcb25
commit acb5491225
12 changed files with 123 additions and 66 deletions
@@ -0,0 +1,14 @@
///
/// Copyright (c) 2018 Sensus Slovensko a.s.
///
using System;
namespace TBF.BenchControl.GenericDevices
{
interface IHasTestName
{
string TestName { set; }
int TestRepeats { set; }
int RepetitionNr { set; }
}
}
@@ -23,9 +23,9 @@ namespace TBF.BenchControl.RegisterReaders.SerialStream
public float RefFlow; /// [m3/h] public float RefFlow; /// [m3/h]
public int Counter; public int Counter;
const int MaxLength = 256; const int MaxDataLength = 256;
public char[] Data = new char[MaxLength]; char[] data = new char[MaxDataLength];
public int Length; int dataLength;
public byte CheckSum; public byte CheckSum;
@@ -38,11 +38,11 @@ namespace TBF.BenchControl.RegisterReaders.SerialStream
/// ///
/// Calculated values /// Calculated values
/// ///
public double Volume(double scalingFactor) { return (double)VolumeRawExt / scalingFactor; } public double Volume(FrameFormat ff) { return (double)VolumeRawExt / ff.VolumeScaleFactor; }
public decimal TimestampDec() { return (decimal)TimestampExt / (decimal)8192; } public decimal TimestampDec(FrameFormat ff) { return (decimal)TimestampExt / (decimal)ff.TimeScaleFactor; }
public double VolumeDelta(double scalingFactor, DatastreamFrame previous) { return (previous == null) ? 0 : Volume(scalingFactor) - previous.Volume(scalingFactor); } public double VolumeDelta(FrameFormat ff, DatastreamFrame previous) { return (previous == null) ? 0 : Volume(ff) - previous.Volume(ff); }
public decimal TimeDelta() { return TimestampDec() - TestStartTimestampDec; } public decimal TimeDelta(FrameFormat ff) { return TimestampDec(ff) - TestStartTimestampDec; }
public string Label() public string Label()
{ {
@@ -103,8 +103,9 @@ namespace TBF.BenchControl.RegisterReaders.SerialStream
return false; return false;
} }
Length = frame.Length; /// Copy data into the fixed size buffer
for (int i = 0; i < Math.Min(MaxLength, frame.Length); i++) Data[i] = frame[i]; dataLength = frame.Length - 2;
for (int i = 0; i < Math.Min(MaxDataLength, dataLength); i++) data[i] = frame[i];
bool f1 = UInt32.TryParse(frame.Substring(ff.VolumeFieldStart, ff.VolumeFieldLength), NumberStyles.HexNumber, CultureInfo.CurrentCulture, out VolumeRaw); bool f1 = UInt32.TryParse(frame.Substring(ff.VolumeFieldStart, ff.VolumeFieldLength), NumberStyles.HexNumber, CultureInfo.CurrentCulture, out VolumeRaw);
bool f2 = UInt32.TryParse(frame.Substring(ff.TimeFieldStart, ff.TimeFieldLength), NumberStyles.HexNumber, CultureInfo.CurrentCulture, out Timestamp); bool f2 = UInt32.TryParse(frame.Substring(ff.TimeFieldStart, ff.TimeFieldLength), NumberStyles.HexNumber, CultureInfo.CurrentCulture, out Timestamp);
@@ -175,6 +176,7 @@ namespace TBF.BenchControl.RegisterReaders.SerialStream
return false; return false;
} }
dataLength = 0;
return true; return true;
} }
@@ -185,7 +187,7 @@ namespace TBF.BenchControl.RegisterReaders.SerialStream
} }
public string ToString(double scalingFactor, DatastreamFrame previous) public string ToString(FrameFormat ff, DatastreamFrame previous)
{ {
if (Flags == FrameFlags.SyncError) if (Flags == FrameFlags.SyncError)
{ {
@@ -195,20 +197,20 @@ namespace TBF.BenchControl.RegisterReaders.SerialStream
{ {
return "Invalid telegram"; return "Invalid telegram";
} }
else /// if (flags == OptoTelegramFlags.OK / OptoTelegramFlags.OK_TestStart / OptoTelegramFlags.OK_TestEnd) else /// if (flags == OptoTelegramFlags.OK || OptoTelegramFlags.OK_TestStart || OptoTelegramFlags.OK_TestEnd)
{ {
StringBuilder sb = new StringBuilder(MaxLength); StringBuilder sb = new StringBuilder(MaxDataLength);
for (int i = 0; i < Math.Min(MaxLength, Length - 2); i++) sb.Append(Data[i]); for (int i = 0; i < Math.Min(MaxDataLength, dataLength); i++) sb.Append(data[i]);
return string.Format("{0}:{1}:{2}.{3}\t{4} : {5} Volume={6} Time={7} {8}", return string.Format("{0}:{1}:{2}.{3} #{4} : {5} Volume={6} Time={7} {8}",
DateTime.Hour.ToString("D2"), DateTime.Hour.ToString("D2"),
DateTime.Minute.ToString("D2"), DateTime.Minute.ToString("D2"),
DateTime.Second.ToString("D2"), DateTime.Second.ToString("D2"),
DateTime.Millisecond.ToString("D4"), DateTime.Millisecond.ToString("D3"),
Counter, Counter.ToString("D6"),
sb, sb.ToString(),
VolumeRaw.ToString("X6"), Volume(ff),
Timestamp.ToString("X8"), TimestampDec(ff),
Label()); Label());
} }
} }
@@ -75,5 +75,15 @@ namespace TBF.BenchControl.RegisterReaders.SerialStream
TimeWrapThreshold = 1L << (4 * TimeFieldLength - 1); TimeWrapThreshold = 1L << (4 * TimeFieldLength - 1);
} }
} }
public override string ToString()
{
return string.Format("L={0} V={1}-{2}-{3}-{4}-{5} T={6}-{7}-{8}-{9}-{10}",
FrameLength,
VolumeUnits, VolumeScaleFactor,
VolumeFieldStart, VolumeFieldEnd, VolumeFieldFormat,
TimeUnits, TimeScaleFactor,
TimeFieldStart, TimeFieldEnd, TimeFieldFormat);
}
} }
} }
@@ -13,7 +13,7 @@ namespace TBF.BenchControl.RegisterReaders.SerialStream
/// <summary> /// <summary>
/// This component = instance of this class is a placeholder for a combined main watermeter /// This component = instance of this class is a placeholder for a combined main watermeter
/// </summary> /// </summary>
public class SerialStream : ComponentBase, IDevice, GenericDevices.IRegisterReader, IOperation public class SerialStream : ComponentBase, IDevice, GenericDevices.IRegisterReader, GenericDevices.IHasTestName, IOperation
{ {
private static readonly ILog log = LogManager.GetLogger(typeof(SerialStream)); private static readonly ILog log = LogManager.GetLogger(typeof(SerialStream));
public override string ToString() { return string.Format("RegisterReaders.SerialStream({0})", Cfg.ToString(1)); } public override string ToString() { return string.Format("RegisterReaders.SerialStream({0})", Cfg.ToString(1)); }
@@ -82,7 +82,13 @@ namespace TBF.BenchControl.RegisterReaders.SerialStream
/// <summary> Name set by the test, to be used as a part of the opto-data log file name </summary> /// <summary> Name set by the test, to be used as a part of the opto-data log file name </summary>
public string TestName; public string TestName { set { testName = value; } }
public int TestRepeats { set { testRepeats = value; } }
public int RepetitionNr { set { repetitionNr = value; } }
///
string testName;
int testRepeats;
int repetitionNr;
/// <summary> Name set by the test, to be used as a part of the opto-data log file name </summary> /// <summary> Name set by the test, to be used as a part of the opto-data log file name </summary>
public string BenchName; public string BenchName;
@@ -193,6 +199,7 @@ namespace TBF.BenchControl.RegisterReaders.SerialStream
VolumeFieldStart, VolumeFieldEnd, VolumeFieldFormat, VolumeFieldStart, VolumeFieldEnd, VolumeFieldFormat,
TimeUnits, TimeScaleFactor, TimeUnits, TimeScaleFactor,
TimeFieldStart, TimeFieldEnd, TimeFieldFormat); TimeFieldStart, TimeFieldEnd, TimeFieldFormat);
log.WarnFormat("Initialize() ... FrameFormat set to {0}", currentFrameFormat);
/// Allocate memory for opto-data from iPerl /// Allocate memory for opto-data from iPerl
datastreamFrames = new DatastreamFrame[MaxDatastreamFramesCount]; datastreamFrames = new DatastreamFrame[MaxDatastreamFramesCount];
@@ -309,10 +316,11 @@ namespace TBF.BenchControl.RegisterReaders.SerialStream
int digitIx = Name.IndexOfAny(new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }); int digitIx = Name.IndexOfAny(new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' });
string position = (digitIx >= 0) ? Name.Substring(digitIx) : string.Empty; string position = (digitIx >= 0) ? Name.Substring(digitIx) : string.Empty;
datastreamLogFileName = string.Format("{0}_{1}_{2}.txt", datastreamLogFileName = string.Format("{0}_{1}_{2}_{3}.txt",
StateMachine.CycleStartTimeStamp.ToString("HHmmss"), StateMachine.CycleStartTimeStamp.ToString("HHmmss"),
position, position,
TestName); testName,
repetitionNr);
StartParsingDatastream(new FrameFormat(FrameLength, StartParsingDatastream(new FrameFormat(FrameLength,
VolumeUnits, VolumeScaleFactor, VolumeUnits, VolumeScaleFactor,
@@ -357,7 +365,7 @@ namespace TBF.BenchControl.RegisterReaders.SerialStream
if (TestStartFrameIx > 0 && TestStartFrameIx < datastreamFrames.Length && datastreamFrames[TestStartFrameIx].Flags == FrameFlags.OK) if (TestStartFrameIx > 0 && TestStartFrameIx < datastreamFrames.Length && datastreamFrames[TestStartFrameIx].Flags == FrameFlags.OK)
{ {
datastreamFrames[TestStartFrameIx].Flags = FrameFlags.OK_TestStart; datastreamFrames[TestStartFrameIx].Flags = FrameFlags.OK_TestStart;
DatastreamFrame.TestStartTimestampDec = datastreamFrames[TestStartFrameIx].TimestampDec(); DatastreamFrame.TestStartTimestampDec = datastreamFrames[TestStartFrameIx].TimestampDec(currentFrameFormat);
} }
if (TestEndFrameIx > 0 && TestEndFrameIx < datastreamFrames.Length && datastreamFrames[TestEndFrameIx].Flags == FrameFlags.OK) if (TestEndFrameIx > 0 && TestEndFrameIx < datastreamFrames.Length && datastreamFrames[TestEndFrameIx].Flags == FrameFlags.OK)
@@ -367,11 +375,11 @@ namespace TBF.BenchControl.RegisterReaders.SerialStream
StopParsingDatastream(); StopParsingDatastream();
DatastreamFrame.FIRFilterFlow(datastreamFrames, datastreamFramesCount); DatastreamFrame.FIRFilterFlow(datastreamFrames, datastreamFramesCount);
SaveDatastreamLog(); SaveDatastreamLog(currentFrameFormat);
} }
void SaveDatastreamLog() void SaveDatastreamLog(FrameFormat ff)
{ {
string directory = string.Format("C:\\TBF\\ProcessData\\{0}\\{1}\\{2}\\", string directory = string.Format("C:\\TBF\\ProcessData\\{0}\\{1}\\{2}\\",
StateMachine.CycleStartTimeStamp.ToString("yy"), StateMachine.CycleStartTimeStamp.ToString("yy"),
@@ -386,8 +394,8 @@ namespace TBF.BenchControl.RegisterReaders.SerialStream
using (TextWriter datastreamLogFile = new StreamWriter(datastreamLogPathName)) using (TextWriter datastreamLogFile = new StreamWriter(datastreamLogPathName))
{ {
datastreamLogFile.WriteLine(datastreamFrames[0].ToString(scalFact, null)); datastreamLogFile.WriteLine(datastreamFrames[0].ToString(ff, null));
for (int i = 1; i < datastreamFramesCount; i++) datastreamLogFile.WriteLine(datastreamFrames[i].ToString(scalFact, datastreamFrames[i - 1])); for (int i = 1; i < datastreamFramesCount; i++) datastreamLogFile.WriteLine(datastreamFrames[i].ToString(ff, datastreamFrames[i - 1]));
datastreamLogFile.Close(); datastreamLogFile.Close();
} }
} }
@@ -418,6 +426,7 @@ namespace TBF.BenchControl.RegisterReaders.SerialStream
{ {
currentFrameFormat = ff; currentFrameFormat = ff;
datastreamParsingEnabled = true; datastreamParsingEnabled = true;
log.WarnFormat("StartParsingDatastream() ... FrameFormat set to {0}", currentFrameFormat);
} }
/// <summary> Stop parsig the opto serial port data </summary> /// <summary> Stop parsig the opto serial port data </summary>
@@ -472,7 +481,7 @@ namespace TBF.BenchControl.RegisterReaders.SerialStream
// CR+LF found // CR+LF found
if (streamState == DatastreamState.Read) if (streamState == DatastreamState.Read)
{ {
if (pos < FrameLength - 2) if (pos < ff.FrameLength - 2)
{ {
/// CR+LF found too early, truncate the beginning incl CR+LF and keep scanning in this loop /// CR+LF found too early, truncate the beginning incl CR+LF and keep scanning in this loop
allRcvd = allRcvd.Substring(pos + 2); allRcvd = allRcvd.Substring(pos + 2);
@@ -484,7 +493,7 @@ namespace TBF.BenchControl.RegisterReaders.SerialStream
synchronized = true; synchronized = true;
} }
// CR+LF found and (pos >= OptoTelegramRaw.Length - 2) // CR+LF found and (pos >= OptoTelegramRaw.Length - 2)
else if (datastreamFrames[datastreamFramesCount].UpdateFromString(allRcvd.Substring(pos - ff.FrameLength + 2), ff, datastreamFramesCount, ref volumeRawExtLast, ref timestampExtLast)) else if (datastreamFrames[datastreamFramesCount].UpdateFromString(allRcvd.Substring(pos - ff.FrameLength + 2, ff.FrameLength), ff, datastreamFramesCount, ref volumeRawExtLast, ref timestampExtLast))
{ {
OptoTelegramRreceived(datastreamFramesCount++, synchronized2); OptoTelegramRreceived(datastreamFramesCount++, synchronized2);
synchronized2 = synchronized; synchronized2 = synchronized;
@@ -539,22 +548,22 @@ namespace TBF.BenchControl.RegisterReaders.SerialStream
if (volumeLtr == 0 && volumeLtr0 == 0) if (volumeLtr == 0 && volumeLtr0 == 0)
{ {
volumeLtr = (double)lastVolumeRaw * ScalingFactor() / 16000.0; volumeLtr = (double)lastVolumeRaw / currentFrameFormat.VolumeScaleFactor;
volumeLtr0 = volumeLtr; volumeLtr0 = volumeLtr;
} }
else else
{ {
volumeLtr = (double)lastVolumeRaw * ScalingFactor() / 16000.0; volumeLtr = (double)lastVolumeRaw / currentFrameFormat.VolumeScaleFactor;
} }
if (timestampSec == 0 && timestampSec0 == 0) if (timestampSec == 0 && timestampSec0 == 0)
{ {
timestampSec = (double)lastTimestamp / 8192.0; timestampSec = (double)lastTimestamp / currentFrameFormat.TimeScaleFactor;
timestampSec0 = timestampSec; timestampSec0 = timestampSec;
} }
else else
{ {
timestampSec = (double)lastTimestamp / 8192.0; timestampSec = (double)lastTimestamp / currentFrameFormat.TimeScaleFactor;
} }
//optoDataLogger.InfoFormat("{0} {1} {2} ltr {3} {4}", optoTelegram, lastTimestamp, lastVolumeRaw.ToString("X8"), timestampSec.ToString("F1"), volumeLtr.ToString("F3")); //optoDataLogger.InfoFormat("{0} {1} {2} ltr {3} {4}", optoTelegram, lastTimestamp, lastVolumeRaw.ToString("X8"), timestampSec.ToString("F1"), volumeLtr.ToString("F3"));
@@ -255,9 +255,12 @@ namespace TBF.BenchControl.TestMethods.Endurance
foreach (var rr in sensPath.RegisterReaders) foreach (var rr in sensPath.RegisterReaders)
{ {
if (rr is TestMethods.iPerlCommunication.iPerlHead.IperlHead) GenericDevices.IHasTestName readerWithTstName = rr as GenericDevices.IHasTestName;
if (readerWithTstName != null)
{ {
(rr as TestMethods.iPerlCommunication.iPerlHead.IperlHead).TestName = test.Name; readerWithTstName.TestName = test.Name;
readerWithTstName.TestRepeats = test.Repeats;
readerWithTstName.RepetitionNr = repetitionNr;
} }
} }
@@ -404,9 +404,12 @@ namespace TBF.BenchControl.TestMethods.FlyingStart
foreach (var rr in sensPath.RegisterReaders) foreach (var rr in sensPath.RegisterReaders)
{ {
if (rr is TestMethods.iPerlCommunication.iPerlHead.IperlHead) GenericDevices.IHasTestName readerWithTstName = rr as GenericDevices.IHasTestName;
if (readerWithTstName != null)
{ {
(rr as TestMethods.iPerlCommunication.iPerlHead.IperlHead).TestName = test.Name; readerWithTstName.TestName = test.Name;
readerWithTstName.TestRepeats = test.Repeats;
readerWithTstName.RepetitionNr = repetitionNr;
} }
} }
@@ -570,9 +570,12 @@ namespace TBF.BenchControl.TestMethods.FlyingStartFirstRepetWithMassColl
foreach (var rr in sensPath.RegisterReaders) foreach (var rr in sensPath.RegisterReaders)
{ {
if (rr is TestMethods.iPerlCommunication.iPerlHead.IperlHead) GenericDevices.IHasTestName readerWithTstName = rr as GenericDevices.IHasTestName;
if (readerWithTstName != null)
{ {
(rr as TestMethods.iPerlCommunication.iPerlHead.IperlHead).TestName = test.Name; readerWithTstName.TestName = test.Name;
readerWithTstName.TestRepeats = test.Repeats;
readerWithTstName.RepetitionNr = repetitionNr;
} }
} }
@@ -575,9 +575,12 @@ namespace TBF.BenchControl.TestMethods.FlyingStartMassCollProlonged
foreach (var rr in sensPath.RegisterReaders) foreach (var rr in sensPath.RegisterReaders)
{ {
if (rr is TestMethods.iPerlCommunication.iPerlHead.IperlHead) GenericDevices.IHasTestName readerWithTstName = rr as GenericDevices.IHasTestName;
if (readerWithTstName != null)
{ {
(rr as TestMethods.iPerlCommunication.iPerlHead.IperlHead).TestName = test.Name; readerWithTstName.TestName = test.Name;
readerWithTstName.TestRepeats = test.Repeats;
readerWithTstName.RepetitionNr = repetitionNr;
} }
} }
@@ -625,9 +625,12 @@ namespace TBF.BenchControl.TestMethods.FlyingStartMassCollection
foreach (var rr in sensPath.RegisterReaders) foreach (var rr in sensPath.RegisterReaders)
{ {
if (rr is TestMethods.iPerlCommunication.iPerlHead.IperlHead) GenericDevices.IHasTestName readerWithTstName = rr as GenericDevices.IHasTestName;
if (readerWithTstName != null)
{ {
(rr as TestMethods.iPerlCommunication.iPerlHead.IperlHead).TestName = test.Name; readerWithTstName.TestName = test.Name;
readerWithTstName.TestRepeats = test.Repeats;
readerWithTstName.RepetitionNr = repetitionNr;
} }
} }
@@ -18,7 +18,7 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication.iPerlHead
/// <summary> /// <summary>
/// This component = instance of this class is a placeholder for a combined main watermeter /// This component = instance of this class is a placeholder for a combined main watermeter
/// </summary> /// </summary>
public class IperlHead : ComponentBase, IDevice, GenericDevices.IRegisterReader, IOperation public class IperlHead : ComponentBase, IDevice, GenericDevices.IRegisterReader, GenericDevices.IHasTestName, IOperation
{ {
private static readonly ILog log = LogManager.GetLogger(typeof(IperlHead)); private static readonly ILog log = LogManager.GetLogger(typeof(IperlHead));
public override string ToString() { return string.Format("iPerl({0})", Cfg.ToString(1)); } public override string ToString() { return string.Format("iPerl({0})", Cfg.ToString(1)); }
@@ -282,7 +282,13 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication.iPerlHead
/// <summary> Name set by the test, to be used as a part of the opto-data log file name </summary> /// <summary> Name set by the test, to be used as a part of the opto-data log file name </summary>
public string TestName; public string TestName { set { testName = value; } }
public int TestRepeats { set { testRepeats = value; } }
public int RepetitionNr { set { repetitionNr = value; } }
///
string testName;
int testRepeats;
int repetitionNr;
/// <summary> Name set by the test, to be used as a part of the opto-data log file name </summary> /// <summary> Name set by the test, to be used as a part of the opto-data log file name </summary>
public string BenchName; public string BenchName;
@@ -521,10 +527,10 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication.iPerlHead
if (wmPosition.Length == 1) wmPosition = "0" + wmPosition; if (wmPosition.Length == 1) wmPosition = "0" + wmPosition;
string flowNr; string flowNr;
if (TestName != null && TestName.ToLower().Contains("q1")) flowNr = "01"; if (testName != null && testName.ToLower().Contains("q1")) flowNr = "01";
else if (TestName != null && TestName.ToLower().Contains("q2")) flowNr = "02"; else if (testName != null && testName.ToLower().Contains("q2")) flowNr = "02";
else if (TestName != null && TestName.ToLower().Contains("q3")) flowNr = "03"; else if (testName != null && testName.ToLower().Contains("q3")) flowNr = "03";
else if (TestName != null && TestName.ToLower().Contains("adj")) flowNr = "0-1"; else if (testName != null && testName.ToLower().Contains("adj")) flowNr = "0-1";
else flowNr = "99"; else flowNr = "99";
optoDataLogFileName = string.Format("{0}_{1}_{2}_{3}.txt", optoDataLogFileName = string.Format("{0}_{1}_{2}_{3}.txt",
+2 -2
View File
@@ -29,5 +29,5 @@ using System.Runtime.InteropServices;
// Build Number // Build Number
// Revision // Revision
// //
[assembly: AssemblyVersion("2.18.909.0")] [assembly: AssemblyVersion("2.18.910.0")]
[assembly: AssemblyFileVersion("2.18.909.0")] [assembly: AssemblyFileVersion("2.18.910.0")]
+1
View File
@@ -520,6 +520,7 @@
<DependentUpon>ValveCfgCtrl.cs</DependentUpon> <DependentUpon>ValveCfgCtrl.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="BenchControl\Elde\ValveEx\ValveFactory.cs" /> <Compile Include="BenchControl\Elde\ValveEx\ValveFactory.cs" />
<Compile Include="BenchControl\GenericDevices\IHasTestName.cs" />
<Compile Include="BenchControl\GenericDevices\ICameraDisplay.cs" /> <Compile Include="BenchControl\GenericDevices\ICameraDisplay.cs" />
<Compile Include="BenchControl\GenericDevices\IDataEntryForCamera.cs" /> <Compile Include="BenchControl\GenericDevices\IDataEntryForCamera.cs" />
<Compile Include="BenchControl\GenericDevices\IErrorFlags.cs" /> <Compile Include="BenchControl\GenericDevices\IErrorFlags.cs" />