init
This commit is contained in:
179
Common/DTS.Common.Serialization/SoMat/SoMat.File.Writer.cs
Normal file
179
Common/DTS.Common.Serialization/SoMat/SoMat.File.Writer.cs
Normal file
@@ -0,0 +1,179 @@
|
||||
/*
|
||||
* SoMat.File.Writer.cs
|
||||
*
|
||||
* Copyright © 2009
|
||||
* Diversified Technical Systems, Inc.
|
||||
* All Rights Reserved
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using DTS.Common.Utilities.Logging;
|
||||
|
||||
namespace DTS.Serialization.SoMat
|
||||
{
|
||||
// *** see SoMat.File.Writer.cs ***
|
||||
public partial class File
|
||||
{ ///
|
||||
/// <summary>
|
||||
/// Utility object for serializing <see cref="DTS.Serialization.Test"/>s to disk
|
||||
/// in the Diadem
|
||||
/// </summary>
|
||||
///
|
||||
public class Writer : Writer<File>, IWriter<Test>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initialize an instance of the SoMat.File.Writer class.
|
||||
/// </summary>
|
||||
///
|
||||
/// <param name="fileType">
|
||||
/// The associated <see cref="DTS.SErialization.Diadem.File"/> object.
|
||||
/// </param>
|
||||
///
|
||||
internal Writer(File fileType, int encoding)
|
||||
: base(fileType, encoding)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Write the specified test to the specified pathname.
|
||||
/// </summary>
|
||||
///
|
||||
/// <param name="pathname">
|
||||
/// The <see cref="string"/> pathname to which the specified test should be serialized.
|
||||
/// </param>
|
||||
///
|
||||
/// <param name="test">
|
||||
/// The <see cref="DTS.Serialization.Test"/> to be written out.
|
||||
/// </param>
|
||||
///
|
||||
public void Write(string pathname, string id, Test test, bool bFiltering, bool includeGroupNameInISOExport, double minStartTime, int dataCollectionLength)
|
||||
{
|
||||
throw new NotSupportedException("SoMat::File::Writer Write(pathname, id, test, bFiltering) not supported");
|
||||
}
|
||||
private FilteredData[] _filterdData = null;
|
||||
public FilteredData[] FilteredData
|
||||
{
|
||||
get => _filterdData;
|
||||
set => _filterdData = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write the representation file/files of the specified DTS.Serialization.Test
|
||||
/// at the given pathname.
|
||||
/// </summary>
|
||||
///
|
||||
/// <param name="targetPathname">
|
||||
/// The <see cref="string"/> pathname of the specified object's resulting file
|
||||
/// representation.
|
||||
/// </param>
|
||||
///
|
||||
public void Write(string pathname,
|
||||
string id,
|
||||
string dataFolder,
|
||||
Test test,
|
||||
bool bFiltering,
|
||||
bool includeGroupNameInISOExport,
|
||||
FilteredData fd,
|
||||
Test.Module.Channel tmChannel,
|
||||
int channelNumber,
|
||||
BeginEventHandler beginEventHandler,
|
||||
CancelEventHandler cancelEventHandler,
|
||||
EndEventHandler endEventHandler,
|
||||
TickEventHandler tickEventHandler,
|
||||
ErrorEventHandler errorEventHandler,
|
||||
CancelRequested cancelRequested,
|
||||
double minStartTime,
|
||||
int dataCollectionLength)
|
||||
{
|
||||
System.Exception exception = null;
|
||||
try
|
||||
{
|
||||
beginEventHandler?.Invoke(this, Convert.ToUInt32(test.Channels.Count)); var header = new SoMatTestHeader(test, FilteredData);
|
||||
using (var sw = new StreamWriter(pathname, false, Encoding.Default))
|
||||
{
|
||||
header.Serialize(sw);
|
||||
foreach (var channel in header.Channels)
|
||||
{
|
||||
channel.Serialize(sw);
|
||||
}
|
||||
|
||||
sw.Write("DM_Start=\r\n");
|
||||
|
||||
ulong maxSamples = 0;
|
||||
foreach (var module in test.Modules)
|
||||
{
|
||||
maxSamples = Math.Max(maxSamples, module.NumberOfSamples);
|
||||
}
|
||||
|
||||
double totalWriteTicksDispatched = 0;
|
||||
double totalWriteTicksNeeded = 100;
|
||||
|
||||
var DataSamplesPerTick = Convert.ToUInt64(maxSamples / (double)totalWriteTicksNeeded);
|
||||
|
||||
for (uint i = 0; i < maxSamples; i++)
|
||||
{
|
||||
sw.WriteLine();
|
||||
var bNeedTab = false;
|
||||
foreach (var fdvar in _filterdData)
|
||||
{
|
||||
if (bNeedTab) { sw.Write("\t"); }
|
||||
if (i < fdvar.Data.Length)
|
||||
{
|
||||
sw.Write(fdvar.Data[i].ToString("0.00000E+00"));
|
||||
}
|
||||
bNeedTab = true;
|
||||
}
|
||||
if (0 == i % DataSamplesPerTick)
|
||||
{
|
||||
if (null != tickEventHandler)
|
||||
{
|
||||
tickEventHandler(this, ((double)totalWriteTicksDispatched++) / totalWriteTicksNeeded * 100);
|
||||
System.Windows.Forms.Application.DoEvents();
|
||||
}
|
||||
}
|
||||
}
|
||||
sw.Flush();
|
||||
sw.Close();
|
||||
}
|
||||
}
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
exception = ex;
|
||||
APILogger.Log("encountered problem writing SoMat test files", ex);
|
||||
}
|
||||
tickEventHandler?.Invoke(this, 100D);
|
||||
if (null != errorEventHandler && null != exception)
|
||||
{
|
||||
endEventHandler(this);
|
||||
errorEventHandler(this, exception);
|
||||
}
|
||||
else if (null != exception) { throw exception; }
|
||||
else
|
||||
{
|
||||
tickEventHandler?.Invoke(this, 100.0);
|
||||
endEventHandler?.Invoke(this);
|
||||
}
|
||||
}
|
||||
public void Initialize(string pathname,
|
||||
string id,
|
||||
string dataFolder,
|
||||
Test test,
|
||||
bool bFiltering,
|
||||
bool includeGroupNameInISOExport,
|
||||
FilteredData fd,
|
||||
Test.Module.Channel tmChannel,
|
||||
int channelNumber,
|
||||
BeginEventHandler beginEventHandler,
|
||||
CancelEventHandler cancelEventHandler,
|
||||
EndEventHandler endEventHandler,
|
||||
TickEventHandler tickEventHandler,
|
||||
ErrorEventHandler errorEventHandler,
|
||||
CancelRequested cancelRequested)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
55
Common/DTS.Common.Serialization/SoMat/SoMat.File.cs
Normal file
55
Common/DTS.Common.Serialization/SoMat/SoMat.File.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* SoMat.File.cs
|
||||
*
|
||||
* Copyright © 2013
|
||||
* Diversified Technical Systems, Inc.
|
||||
* All Rights Reserved
|
||||
*/
|
||||
|
||||
namespace DTS.Serialization.SoMat
|
||||
{
|
||||
///
|
||||
/// <summary>
|
||||
/// File
|
||||
/// </summary>
|
||||
///
|
||||
public partial class File
|
||||
: Serialization.File, IWritable<Test>
|
||||
{ ///
|
||||
/// <summary>
|
||||
/// Initialize an instance of the FtssCsv.File class.
|
||||
/// </summary>
|
||||
///
|
||||
public File()
|
||||
: base("SoMat")
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get this file format's extension.
|
||||
/// </summary>
|
||||
public static string Extension => ".txt";
|
||||
|
||||
/// <summary>
|
||||
/// Get the file writer for this file type.
|
||||
/// </summary>
|
||||
public IWriter<Test> Exporter
|
||||
{
|
||||
get
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_Exporter == null)
|
||||
_Exporter = new Writer(this, DefaultEncoding);
|
||||
return _Exporter;
|
||||
}
|
||||
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
throw new Exception("encountered problem getting exporter", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
private IWriter<Test> _Exporter = null;
|
||||
}
|
||||
}
|
||||
178
Common/DTS.Common.Serialization/SoMat/SoMatChannel.cs
Normal file
178
Common/DTS.Common.Serialization/SoMat/SoMatChannel.cs
Normal file
@@ -0,0 +1,178 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace DTS.Serialization.SoMat
|
||||
{
|
||||
public class SoMatChannel
|
||||
{
|
||||
public int LogicalChannel { get; set; }
|
||||
public string ChanType { get; set; } = "SEQUENTIAL";
|
||||
public string ChanName { get; set; } = "";
|
||||
public ulong NumDataPoints { get; set; } = 0;
|
||||
public int NumDims { get; set; } = 2;
|
||||
public int DataMode { get; set; } = 1;
|
||||
public string DataModeType { get; set; } = "TIMHIS";
|
||||
public string AxisLabelDim1 { get; set; } = "Time";
|
||||
public string AxisLabelDim2 { get; set; } = "";
|
||||
public string AxisUnitsDim1 { get; set; } = "Secs";
|
||||
public string AxisUnitsDim2 { get; set; } = "";
|
||||
public string SampleRate { get; set; } = "";
|
||||
public string TimeBase { get; set; } = "";
|
||||
public string MaxValue { get; set; } = "";
|
||||
public string MinValue { get; set; } = "";
|
||||
public string UserMax { get; set; } = "";
|
||||
public string UserMin { get; set; } = "";
|
||||
public string ChanDim2 { get; set; } = "1";
|
||||
public string DescDim2 { get; set; } = "";
|
||||
public string CTypeDim2 { get; set; } = "8";
|
||||
public string HDWParams { get; set; } = "";
|
||||
public string CalParams { get; set; } = "";
|
||||
public string DGParams { get; set; } = "";
|
||||
|
||||
public enum TriggerModes { ALWAYS_ON, GATE, TRIGGER, ONE_SHOT };
|
||||
public TriggerModes TriggerMode { get; set; } = TriggerModes.TRIGGER;
|
||||
|
||||
public string _elapsedTime = "";
|
||||
public string ElapsedTime
|
||||
{
|
||||
get => _elapsedTime;
|
||||
set => _elapsedTime = value;
|
||||
}
|
||||
public string HistType { get; set; } = "Other";
|
||||
public string AcquisitionRate { get; set; } = "";
|
||||
public string RTCStart { get; set; } = "";
|
||||
public string RTCEnd { get; set; } = "";
|
||||
public int PhysicalChannelNumber { get; set; }
|
||||
public void Serialize(System.IO.StreamWriter sw)
|
||||
{
|
||||
sw.Write("DM_LogicalChan=");
|
||||
sw.WriteLine(LogicalChannel.ToString());
|
||||
|
||||
sw.Write("DM_ChanType=");
|
||||
sw.WriteLine(ChanType);
|
||||
|
||||
sw.Write("DM_ChanName=");
|
||||
sw.WriteLine(ChanName);
|
||||
|
||||
sw.Write("DM_NumPoints=");
|
||||
sw.WriteLine(NumDataPoints.ToString());
|
||||
|
||||
sw.Write("DM_NumDims=");
|
||||
sw.WriteLine(NumDims.ToString());
|
||||
|
||||
sw.Write("DM_DataMode=");
|
||||
sw.WriteLine(DataMode.ToString());
|
||||
|
||||
sw.Write("DM_DataModeType=");
|
||||
sw.WriteLine(DataModeType);
|
||||
|
||||
sw.Write("DM_AxisLabel.Dim1=");
|
||||
sw.WriteLine(AxisLabelDim1);
|
||||
|
||||
sw.Write("DM_AxisLabel.Dim2=");
|
||||
sw.WriteLine(AxisLabelDim2);
|
||||
|
||||
sw.Write("DM_AxisUnits.Dim1=");
|
||||
sw.WriteLine(AxisUnitsDim1);
|
||||
|
||||
sw.Write("DM_AxisUnits.Dim2=");
|
||||
sw.WriteLine(AxisUnitsDim2);
|
||||
|
||||
sw.Write("DM_SampleRate=");
|
||||
sw.WriteLine(SampleRate);
|
||||
|
||||
sw.Write("DM_TimeBase=");
|
||||
sw.WriteLine(TimeBase);
|
||||
|
||||
sw.Write("DM_MaxValue=");
|
||||
sw.WriteLine(MaxValue);
|
||||
|
||||
sw.Write("DM_MinValue=");
|
||||
sw.WriteLine(MinValue);
|
||||
|
||||
sw.Write("DM_UserMax=");
|
||||
sw.WriteLine(UserMax);
|
||||
|
||||
sw.Write("DM_UserMin=");
|
||||
sw.WriteLine(UserMin);
|
||||
|
||||
sw.Write("2100_Chan.Dim2=");
|
||||
sw.WriteLine(ChanDim2);
|
||||
|
||||
sw.Write("2100_CDESC.Dim2=");
|
||||
sw.WriteLine(DescDim2);
|
||||
|
||||
sw.Write("2100_CTYPE.Dim2=");
|
||||
sw.WriteLine(CTypeDim2);
|
||||
|
||||
sw.Write("HDWParams=");
|
||||
sw.WriteLine(HDWParams);
|
||||
|
||||
sw.Write("CALParams=");
|
||||
sw.WriteLine(CalParams);
|
||||
|
||||
sw.Write("DGParams=");
|
||||
sw.WriteLine(DGParams);
|
||||
|
||||
sw.Write("Trig=");
|
||||
sw.WriteLine(TriggerMode);
|
||||
|
||||
sw.Write("DM_ElapsedTime=");
|
||||
sw.WriteLine(ElapsedTime);
|
||||
|
||||
sw.Write("DM_HistType=");
|
||||
sw.WriteLine(HistType);
|
||||
|
||||
sw.Write("DM_AcquisitionRate=");
|
||||
sw.WriteLine(AcquisitionRate);
|
||||
|
||||
sw.Write("RTCStart=");
|
||||
sw.WriteLine(RTCStart);
|
||||
|
||||
sw.Write("RTCEnd=");
|
||||
sw.WriteLine(RTCEnd);
|
||||
|
||||
sw.Write("DM_PhysicalChan=");
|
||||
sw.WriteLine(PhysicalChannelNumber);
|
||||
|
||||
sw.WriteLine();
|
||||
}
|
||||
public SoMatChannel(Test.Module.Channel channel, int logicalChannel, FilteredData filteredData, int moduleArrayIndex,
|
||||
int numChannelsPerModule, DateTime inceptionDateTime)
|
||||
{
|
||||
LogicalChannel = logicalChannel;
|
||||
var aic = channel as Test.Module.AnalogInputChannel;
|
||||
|
||||
ChanName = aic.ChannelDescriptionString;
|
||||
NumDataPoints = aic.ParentModule.NumberOfSamples;
|
||||
AxisLabelDim2 = aic.SerialNumber;
|
||||
AxisUnitsDim2 = aic.EngineeringUnits.TrimEnd();
|
||||
//0:0.###E+00
|
||||
SampleRate = aic.ParentModule.SampleRateHz.ToString("0.00000E+00");
|
||||
|
||||
if (aic.TimeOfFirstSampleValid) { TimeBase = aic.TimeOfFirstSampleSec.ToString("0.00000E+00"); }
|
||||
else
|
||||
{
|
||||
var start = aic.ParentModule.StartRecordSampleNumber - (double)aic.ParentModule.TriggerSampleNumbers[0];
|
||||
start /= aic.ParentModule.SampleRateHz;
|
||||
TimeBase = start.ToString("0.00000E+00");
|
||||
}
|
||||
|
||||
_filteredData = filteredData;
|
||||
MaxValue = filteredData.Data.Max().ToString("0.00000E+00");
|
||||
MinValue = filteredData.Data.Min().ToString("0.00000E+00");
|
||||
UserMax = aic.DesiredRange.ToString("0.00000E+00");
|
||||
UserMin = (-1D * aic.DesiredRange).ToString("0.00000E+00");
|
||||
DescDim2 = aic.SerialNumber;
|
||||
var elapsedTime = aic.ParentModule.NumberOfSamples / (double)aic.ParentModule.SampleRateHz;
|
||||
ElapsedTime = (elapsedTime).ToString("0.00000E+00");
|
||||
var elapsed = new TimeSpan(0, 0, 0, 0, Convert.ToInt32(elapsedTime * 1000D));
|
||||
AcquisitionRate = aic.ParentModule.SampleRateHz.ToString("F4");
|
||||
var end = inceptionDateTime.Add(elapsed);
|
||||
RTCStart = $"{inceptionDateTime.ToShortDateString()} {inceptionDateTime.ToShortTimeString()} {end.ToShortDateString()} {end.ToShortTimeString()}";
|
||||
RTCEnd = $"{end.ToShortDateString()} {end.ToShortTimeString()}";
|
||||
PhysicalChannelNumber = 1 + moduleArrayIndex * numChannelsPerModule + aic.Number;
|
||||
}
|
||||
private readonly FilteredData _filteredData;
|
||||
}
|
||||
}
|
||||
57
Common/DTS.Common.Serialization/SoMat/SoMatTestHeader.cs
Normal file
57
Common/DTS.Common.Serialization/SoMat/SoMatTestHeader.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace DTS.Serialization.SoMat
|
||||
{
|
||||
public class SoMatTestHeader
|
||||
{
|
||||
public string TestTitle { get; set; } = "";
|
||||
public string Operator { get; set; } = "";
|
||||
public string RunDateTime { get; set; } = "";
|
||||
|
||||
private readonly List<SoMatChannel> _channels = new List<SoMatChannel>();
|
||||
public int NumLogChannels => _channels.Count;
|
||||
public SoMatChannel[] Channels => _channels.ToArray();
|
||||
public int NumDataModes { get; set; } = 1;
|
||||
|
||||
public void Serialize(System.IO.StreamWriter sw)
|
||||
{
|
||||
sw.Write("DM_TestTitle=");
|
||||
sw.WriteLine(TestTitle);
|
||||
|
||||
sw.Write("DM_Operator=");
|
||||
sw.WriteLine(Operator);
|
||||
|
||||
sw.Write("RUNDATETIME=");
|
||||
sw.WriteLine(RunDateTime);
|
||||
|
||||
sw.Write("DM_NumLogChans=");
|
||||
sw.WriteLine(NumLogChannels.ToString());
|
||||
|
||||
sw.Write("DM_NumDataModes=");
|
||||
sw.WriteLine(NumDataModes.ToString());
|
||||
|
||||
sw.WriteLine();
|
||||
}
|
||||
public SoMatTestHeader(Test test, FilteredData[] filteredData)
|
||||
{
|
||||
TestTitle = test.Id;
|
||||
RunDateTime = string.Format("{0} {1}", test.InceptionDate.ToShortDateString(), test.InceptionDate.ToShortTimeString());
|
||||
try
|
||||
{
|
||||
Operator = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
|
||||
}
|
||||
catch (System.Exception) { }
|
||||
|
||||
for (var i = 0; i < test.Channels.Count && i < filteredData.Length; i++)
|
||||
{
|
||||
var moduleArrayIndex = 0;
|
||||
for (moduleArrayIndex = 0; moduleArrayIndex < test.Modules.Count; moduleArrayIndex++)
|
||||
{
|
||||
if (test.Channels[i].ParentModule.SerialNumber ==
|
||||
test.Modules[moduleArrayIndex].SerialNumber) { break; }
|
||||
}
|
||||
_channels.Add(new SoMatChannel(test.Channels[i], 1 + i, filteredData[i], moduleArrayIndex, 3, test.InceptionDate));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user