DatastreamFrame logging fixed, FrameFormat handling improved, PD log file names fixed, ver. 2.18.910
This commit is contained in:
@@ -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 int Counter;
|
||||
|
||||
const int MaxLength = 256;
|
||||
public char[] Data = new char[MaxLength];
|
||||
public int Length;
|
||||
const int MaxDataLength = 256;
|
||||
char[] data = new char[MaxDataLength];
|
||||
int dataLength;
|
||||
|
||||
public byte CheckSum;
|
||||
|
||||
@@ -38,11 +38,11 @@ namespace TBF.BenchControl.RegisterReaders.SerialStream
|
||||
///
|
||||
/// Calculated values
|
||||
///
|
||||
public double Volume(double scalingFactor) { return (double)VolumeRawExt / scalingFactor; }
|
||||
public decimal TimestampDec() { return (decimal)TimestampExt / (decimal)8192; }
|
||||
public double Volume(FrameFormat ff) { return (double)VolumeRawExt / ff.VolumeScaleFactor; }
|
||||
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 decimal TimeDelta() { return TimestampDec() - TestStartTimestampDec; }
|
||||
public double VolumeDelta(FrameFormat ff, DatastreamFrame previous) { return (previous == null) ? 0 : Volume(ff) - previous.Volume(ff); }
|
||||
public decimal TimeDelta(FrameFormat ff) { return TimestampDec(ff) - TestStartTimestampDec; }
|
||||
|
||||
public string Label()
|
||||
{
|
||||
@@ -103,8 +103,9 @@ namespace TBF.BenchControl.RegisterReaders.SerialStream
|
||||
return false;
|
||||
}
|
||||
|
||||
Length = frame.Length;
|
||||
for (int i = 0; i < Math.Min(MaxLength, frame.Length); i++) Data[i] = frame[i];
|
||||
/// Copy data into the fixed size buffer
|
||||
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 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;
|
||||
}
|
||||
|
||||
dataLength = 0;
|
||||
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)
|
||||
{
|
||||
@@ -195,20 +197,20 @@ namespace TBF.BenchControl.RegisterReaders.SerialStream
|
||||
{
|
||||
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);
|
||||
for (int i = 0; i < Math.Min(MaxLength, Length - 2); i++) sb.Append(Data[i]);
|
||||
StringBuilder sb = new StringBuilder(MaxDataLength);
|
||||
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.Minute.ToString("D2"),
|
||||
DateTime.Second.ToString("D2"),
|
||||
DateTime.Millisecond.ToString("D4"),
|
||||
Counter,
|
||||
sb,
|
||||
VolumeRaw.ToString("X6"),
|
||||
Timestamp.ToString("X8"),
|
||||
DateTime.Millisecond.ToString("D3"),
|
||||
Counter.ToString("D6"),
|
||||
sb.ToString(),
|
||||
Volume(ff),
|
||||
TimestampDec(ff),
|
||||
Label());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,5 +75,15 @@ namespace TBF.BenchControl.RegisterReaders.SerialStream
|
||||
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>
|
||||
/// This component = instance of this class is a placeholder for a combined main watermeter
|
||||
/// </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));
|
||||
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>
|
||||
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>
|
||||
public string BenchName;
|
||||
@@ -193,6 +199,7 @@ namespace TBF.BenchControl.RegisterReaders.SerialStream
|
||||
VolumeFieldStart, VolumeFieldEnd, VolumeFieldFormat,
|
||||
TimeUnits, TimeScaleFactor,
|
||||
TimeFieldStart, TimeFieldEnd, TimeFieldFormat);
|
||||
log.WarnFormat("Initialize() ... FrameFormat set to {0}", currentFrameFormat);
|
||||
|
||||
/// Allocate memory for opto-data from iPerl
|
||||
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' });
|
||||
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"),
|
||||
position,
|
||||
TestName);
|
||||
testName,
|
||||
repetitionNr);
|
||||
|
||||
StartParsingDatastream(new FrameFormat(FrameLength,
|
||||
VolumeUnits, VolumeScaleFactor,
|
||||
@@ -357,7 +365,7 @@ namespace TBF.BenchControl.RegisterReaders.SerialStream
|
||||
if (TestStartFrameIx > 0 && TestStartFrameIx < datastreamFrames.Length && datastreamFrames[TestStartFrameIx].Flags == FrameFlags.OK)
|
||||
{
|
||||
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)
|
||||
@@ -367,11 +375,11 @@ namespace TBF.BenchControl.RegisterReaders.SerialStream
|
||||
|
||||
StopParsingDatastream();
|
||||
DatastreamFrame.FIRFilterFlow(datastreamFrames, datastreamFramesCount);
|
||||
SaveDatastreamLog();
|
||||
SaveDatastreamLog(currentFrameFormat);
|
||||
}
|
||||
|
||||
|
||||
void SaveDatastreamLog()
|
||||
void SaveDatastreamLog(FrameFormat ff)
|
||||
{
|
||||
string directory = string.Format("C:\\TBF\\ProcessData\\{0}\\{1}\\{2}\\",
|
||||
StateMachine.CycleStartTimeStamp.ToString("yy"),
|
||||
@@ -386,8 +394,8 @@ namespace TBF.BenchControl.RegisterReaders.SerialStream
|
||||
|
||||
using (TextWriter datastreamLogFile = new StreamWriter(datastreamLogPathName))
|
||||
{
|
||||
datastreamLogFile.WriteLine(datastreamFrames[0].ToString(scalFact, null));
|
||||
for (int i = 1; i < datastreamFramesCount; i++) datastreamLogFile.WriteLine(datastreamFrames[i].ToString(scalFact, datastreamFrames[i - 1]));
|
||||
datastreamLogFile.WriteLine(datastreamFrames[0].ToString(ff, null));
|
||||
for (int i = 1; i < datastreamFramesCount; i++) datastreamLogFile.WriteLine(datastreamFrames[i].ToString(ff, datastreamFrames[i - 1]));
|
||||
datastreamLogFile.Close();
|
||||
}
|
||||
}
|
||||
@@ -418,6 +426,7 @@ namespace TBF.BenchControl.RegisterReaders.SerialStream
|
||||
{
|
||||
currentFrameFormat = ff;
|
||||
datastreamParsingEnabled = true;
|
||||
log.WarnFormat("StartParsingDatastream() ... FrameFormat set to {0}", currentFrameFormat);
|
||||
}
|
||||
|
||||
/// <summary> Stop parsig the opto serial port data </summary>
|
||||
@@ -472,7 +481,7 @@ namespace TBF.BenchControl.RegisterReaders.SerialStream
|
||||
// CR+LF found
|
||||
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
|
||||
allRcvd = allRcvd.Substring(pos + 2);
|
||||
@@ -484,7 +493,7 @@ namespace TBF.BenchControl.RegisterReaders.SerialStream
|
||||
synchronized = true;
|
||||
}
|
||||
// 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);
|
||||
synchronized2 = synchronized;
|
||||
@@ -539,22 +548,22 @@ namespace TBF.BenchControl.RegisterReaders.SerialStream
|
||||
|
||||
if (volumeLtr == 0 && volumeLtr0 == 0)
|
||||
{
|
||||
volumeLtr = (double)lastVolumeRaw * ScalingFactor() / 16000.0;
|
||||
volumeLtr = (double)lastVolumeRaw / currentFrameFormat.VolumeScaleFactor;
|
||||
volumeLtr0 = volumeLtr;
|
||||
}
|
||||
else
|
||||
{
|
||||
volumeLtr = (double)lastVolumeRaw * ScalingFactor() / 16000.0;
|
||||
volumeLtr = (double)lastVolumeRaw / currentFrameFormat.VolumeScaleFactor;
|
||||
}
|
||||
|
||||
if (timestampSec == 0 && timestampSec0 == 0)
|
||||
{
|
||||
timestampSec = (double)lastTimestamp / 8192.0;
|
||||
timestampSec = (double)lastTimestamp / currentFrameFormat.TimeScaleFactor;
|
||||
timestampSec0 = timestampSec;
|
||||
}
|
||||
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"));
|
||||
|
||||
@@ -255,10 +255,13 @@ namespace TBF.BenchControl.TestMethods.Endurance
|
||||
|
||||
foreach (var rr in sensPath.RegisterReaders)
|
||||
{
|
||||
if (rr is TestMethods.iPerlCommunication.iPerlHead.IperlHead)
|
||||
{
|
||||
(rr as TestMethods.iPerlCommunication.iPerlHead.IperlHead).TestName = test.Name;
|
||||
}
|
||||
GenericDevices.IHasTestName readerWithTstName = rr as GenericDevices.IHasTestName;
|
||||
if (readerWithTstName != null)
|
||||
{
|
||||
readerWithTstName.TestName = test.Name;
|
||||
readerWithTstName.TestRepeats = test.Repeats;
|
||||
readerWithTstName.RepetitionNr = repetitionNr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -404,11 +404,14 @@ namespace TBF.BenchControl.TestMethods.FlyingStart
|
||||
|
||||
foreach (var rr in sensPath.RegisterReaders)
|
||||
{
|
||||
if (rr is TestMethods.iPerlCommunication.iPerlHead.IperlHead)
|
||||
{
|
||||
(rr as TestMethods.iPerlCommunication.iPerlHead.IperlHead).TestName = test.Name;
|
||||
}
|
||||
}
|
||||
GenericDevices.IHasTestName readerWithTstName = rr as GenericDevices.IHasTestName;
|
||||
if (readerWithTstName != null)
|
||||
{
|
||||
readerWithTstName.TestName = test.Name;
|
||||
readerWithTstName.TestRepeats = test.Repeats;
|
||||
readerWithTstName.RepetitionNr = repetitionNr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Measurement loop - preparation
|
||||
|
||||
+8
-5
@@ -570,11 +570,14 @@ namespace TBF.BenchControl.TestMethods.FlyingStartFirstRepetWithMassColl
|
||||
|
||||
foreach (var rr in sensPath.RegisterReaders)
|
||||
{
|
||||
if (rr is TestMethods.iPerlCommunication.iPerlHead.IperlHead)
|
||||
{
|
||||
(rr as TestMethods.iPerlCommunication.iPerlHead.IperlHead).TestName = test.Name;
|
||||
}
|
||||
}
|
||||
GenericDevices.IHasTestName readerWithTstName = rr as GenericDevices.IHasTestName;
|
||||
if (readerWithTstName != null)
|
||||
{
|
||||
readerWithTstName.TestName = test.Name;
|
||||
readerWithTstName.TestRepeats = test.Repeats;
|
||||
readerWithTstName.RepetitionNr = repetitionNr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Measurement loop - preparation
|
||||
|
||||
+8
-5
@@ -575,11 +575,14 @@ namespace TBF.BenchControl.TestMethods.FlyingStartMassCollProlonged
|
||||
|
||||
foreach (var rr in sensPath.RegisterReaders)
|
||||
{
|
||||
if (rr is TestMethods.iPerlCommunication.iPerlHead.IperlHead)
|
||||
{
|
||||
(rr as TestMethods.iPerlCommunication.iPerlHead.IperlHead).TestName = test.Name;
|
||||
}
|
||||
}
|
||||
GenericDevices.IHasTestName readerWithTstName = rr as GenericDevices.IHasTestName;
|
||||
if (readerWithTstName != null)
|
||||
{
|
||||
readerWithTstName.TestName = test.Name;
|
||||
readerWithTstName.TestRepeats = test.Repeats;
|
||||
readerWithTstName.RepetitionNr = repetitionNr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Measurement loop - preparation
|
||||
|
||||
+8
-5
@@ -625,11 +625,14 @@ namespace TBF.BenchControl.TestMethods.FlyingStartMassCollection
|
||||
|
||||
foreach (var rr in sensPath.RegisterReaders)
|
||||
{
|
||||
if (rr is TestMethods.iPerlCommunication.iPerlHead.IperlHead)
|
||||
{
|
||||
(rr as TestMethods.iPerlCommunication.iPerlHead.IperlHead).TestName = test.Name;
|
||||
}
|
||||
}
|
||||
GenericDevices.IHasTestName readerWithTstName = rr as GenericDevices.IHasTestName;
|
||||
if (readerWithTstName != null)
|
||||
{
|
||||
readerWithTstName.TestName = test.Name;
|
||||
readerWithTstName.TestRepeats = test.Repeats;
|
||||
readerWithTstName.RepetitionNr = repetitionNr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Measurement loop - preparation
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication.iPerlHead
|
||||
/// <summary>
|
||||
/// This component = instance of this class is a placeholder for a combined main watermeter
|
||||
/// </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));
|
||||
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>
|
||||
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>
|
||||
public string BenchName;
|
||||
@@ -521,10 +527,10 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication.iPerlHead
|
||||
if (wmPosition.Length == 1) wmPosition = "0" + wmPosition;
|
||||
|
||||
string flowNr;
|
||||
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("q3")) flowNr = "03";
|
||||
else if (TestName != null && TestName.ToLower().Contains("adj")) flowNr = "0-1";
|
||||
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("q3")) flowNr = "03";
|
||||
else if (testName != null && testName.ToLower().Contains("adj")) flowNr = "0-1";
|
||||
else flowNr = "99";
|
||||
|
||||
optoDataLogFileName = string.Format("{0}_{1}_{2}_{3}.txt",
|
||||
|
||||
@@ -29,5 +29,5 @@ using System.Runtime.InteropServices;
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
[assembly: AssemblyVersion("2.18.909.0")]
|
||||
[assembly: AssemblyFileVersion("2.18.909.0")]
|
||||
[assembly: AssemblyVersion("2.18.910.0")]
|
||||
[assembly: AssemblyFileVersion("2.18.910.0")]
|
||||
|
||||
@@ -520,6 +520,7 @@
|
||||
<DependentUpon>ValveCfgCtrl.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="BenchControl\Elde\ValveEx\ValveFactory.cs" />
|
||||
<Compile Include="BenchControl\GenericDevices\IHasTestName.cs" />
|
||||
<Compile Include="BenchControl\GenericDevices\ICameraDisplay.cs" />
|
||||
<Compile Include="BenchControl\GenericDevices\IDataEntryForCamera.cs" />
|
||||
<Compile Include="BenchControl\GenericDevices\IErrorFlags.cs" />
|
||||
|
||||
Reference in New Issue
Block a user