/* * TDAS.File.Reader.cs * * Copyright © 2009 * Diversified Technical Systems, Inc. * All Rights Reserved */ using System; using System.Collections.Generic; using System.IO; using System.Linq; using DTS.Common.Enums; using DTS.Common.Enums.DASFactory; using DTS.Common.Enums.Sensors; using DTS.Common.Utilities; using DTS.Common.Utilities.Logging; namespace DTS.Serialization.TDAS { // *** see TDAS.File.cs *** public partial class File { /// /// /// Utility object for serializing s to disk. /// /// public partial class Reader : Reader, IReader { /// /// /// Initialize an instance of the File.Reader class. /// /// /// /// The -type this deserializer is associated with. /// /// public Reader(File fileType) : base(fileType) { } ///// ///// Notify subscribers that the write ///// is starting. ///// //public event BeginEventHandler OnBegin; ///// ///// Notify subscribers that the write ///// is finished. ///// //public event EndEventHandler OnEnd; ///// ///// Notify subscribers that we are one ///// tick closer to write completion. ///// //public event TickEventHandler OnTick; /// /// Indicates the type of read event that is represented by the /// that has received it. /// public enum Event { NumberOfFilesDetermined, SingleFileReadComplete, FullReadComplete, } /// /// Handler for read events. /// /// /// /// Indicates the type of that is /// represented by this invocation of EventHandler. /// /// /// /// The number of files to be generated by the file read process. /// It should match the number of SliceRaw.File.Reader.Event.SingleFileReadComplete events /// that will be received during the full write. /// /// public delegate void EventHandler(Event readEvent, int numFiles); /// /// Get a complete list of test files in the specified directory. /// /// /// /// The name of the directory to be scoured for test /// files. /// /// /// /// A of filename naming all test /// files in the specified directory. /// /// private List GetChannelFilenames(string directory) { try { var channelFilenames = new List(Directory.GetFiles(directory, "*" + ChannelFileExtension)); channelFilenames.Sort(ChFileCompare); return channelFilenames; } catch (System.Exception ex) { throw new Exception("encountered problem getting channel filenames", ex); } } /// /// Get full name of test serialization file. /// /// /// /// The representation of the directory to be searched for test files. /// /// /// /// The representation of the found test filename. /// /// private string GetTestFilename(string directory) { try { if (null == directory) throw new ArgumentNullException("cannot get test filename from null directory"); if (null == TestFileExtension) throw new ArgumentException("cannot get test filename with null extension"); var testFiles = Directory.GetFiles(directory, "*" + TestFileExtension); //Remove any found that aren't just ".TLF" (for example, ".TLF PreTest Backup") var testFilesList = testFiles.ToList(); foreach (var testFile in testFiles) { if (testFile.LastIndexOf('.') < testFile.Length - 4) { testFilesList.Remove(testFile); } } if (testFilesList.Count < 1) throw new MissingFileException("Could not find required file " + "\"" + directory + TestFileExtension + "\""); if (testFilesList.Count > 1) throw new TooManyFilesException("Found " + testFiles.Length.ToString() + " \"" + TestFileExtension + "\" " + " files in directory \"" + directory + "\"; there should be only 1"); return testFilesList[0]; } catch (System.Exception ex) { //throw new TDAS.File.Reader.Exception(ex.Message, ex); throw new UserException(ex.Message); } } /// /// Perform read test serialization from it's containing file. /// /// /// /// The representation of the pathname of the base /// directory containing the test file. /// /// /// /// The serialization contained by the specified file. /// /// private string ReadTestStringFromFile(string path) { try { //APILogger.Log("reading 65 ", path); using (var mutex = new System.Threading.Mutex(false, path.Replace(Path.DirectorySeparatorChar, '_'))) { while (!mutex.WaitOne(50, false)) { System.Threading.Thread.Sleep(5); } try { using (var reader = new StreamReader(path)) try { return reader.ReadToEnd(); } catch (System.Exception ex) { throw new Exception("encountered problem reading filestream to end", ex); } } finally { mutex.ReleaseMutex(); } } } catch (System.Exception ex) { throw new Exception("encountered problem reading test string from file " + (null != path ? "\"" + path + "\"" : "<>"), ex); } } /// /// Deserialize the test structure contained in the specified serialization string. /// /// /// /// The serialization from whence the test will be extracted /// and instantiated. /// /// /// /// The represented by specified serialization /// string. /// /// readonly Dictionary rackLookup = new Dictionary(); private Test DeserializeTestFromTLF(string testFileName) { try { if (null == testFileName) throw new ArgumentNullException("cannot deserialize test from null string"); var _test = new Test(); using (var reader = new StreamReader(testFileName)) { var allText = reader.ReadToEnd(); //string delimiter = " rackLookup = new Dictionary(); while (stringNumber < allTextArray.Length && allTextArray[stringNumber] != "---- End Rack Information ----") { var rackIndex = 0; var rackInformation = allTextArray[stringNumber].Split(','); rackLookup.Add(rackInformation[rackIndex], rackInformation); stringNumber++; } if (stringNumber == allTextArray.Length) { throw new Exception("No End Rack Information"); } //Found "---- End Rack Information ----", so skip it and look for Start Module Information stringNumber++; //---- End Rack Information ---- while (stringNumber < allTextArray.Length && allTextArray[stringNumber] != "---- Start Module Information ----") { stringNumber++; } if (stringNumber == allTextArray.Length) { throw new Exception("No Start Module Information"); } //Found "---- Start Module Information ----", so skip it and its header text line stringNumber++; //---- Start Module Information ---- stringNumber++; //rack,module,trigmode,trigchan,trigdir,triglevel,moduletype,prediag,postdiag var moduleLookup = new Dictionary(); //Dictionary> moduleChannelLookup = Dictionary>(); while (stringNumber < allTextArray.Length && allTextArray[stringNumber] != "---- End Module Information ----") { var rackIndex = 0; var moduleIndex = 1; var moduleInformation = allTextArray[stringNumber].Split(','); var rackModule = "R" + moduleInformation[rackIndex] + "M" + moduleInformation[moduleIndex]; moduleLookup.Add(rackModule, moduleInformation); stringNumber++; } if (stringNumber == allTextArray.Length) { throw new Exception("No End Module Information"); } //Found "---- End Module Information ----", so skip it and look for Start Sensor Channel Information stringNumber++; //---- End Module Information ---- while (stringNumber < allTextArray.Length && allTextArray[stringNumber] != "---- Start Sensor Channel Information ----") { stringNumber++; } if (stringNumber == allTextArray.Length) { throw new Exception("No Start Sensor Channel Information"); } //Found "---- Start Sensor Channel Information ----", so skip it and its header text lines stringNumber++; //---- Start Sensor Channel Information ---- stringNumber++; //PreTest Data stringNumber++; //datachan,rack,mod,chan,descrip,s/n,offsetlow,offsethigh,calmode,calstep(ohm/volt),shuntval(eu),proptoext,sens(mv/eu or mv/v/eu),gain,extvolt,EU,filter,invert,zeroref,desiredmaxrange,commentfield,caldate,Offset?,InitialEU,sensorID,ISOcode,IRTRACC Exponent,Category var preTestChannelLookup = new Dictionary(); while (stringNumber < allTextArray.Length && allTextArray[stringNumber] != "PostTest Data") { //Get PreTest Data information var rackIndex = 1; var moduleIndex = 2; var channelIndex = 3; var channelInformation = allTextArray[stringNumber].Split(','); var rackModuleChannel = "R" + channelInformation[rackIndex] + "M" + channelInformation[moduleIndex] + "C" + channelInformation[channelIndex]; preTestChannelLookup.Add(rackModuleChannel, channelInformation); stringNumber++; } if (stringNumber == allTextArray.Length) { throw new Exception("No PostTest Data Information"); } //Found "PostTest Data", so skip it and its header text line stringNumber++; //PostTest Data stringNumber++; //datachan,rack,mod,chan,actmaxrange,prediag,offset(mv),SNRatio(dB),prezero,precal,scalefactor(volts/cnt),scalefactor(eu/cnt),datazero,postzero,postcal,max(eu),maxtime(msec),min(eu),mintime(msec),chansat,postdiag,actual 0 mV cnts,desired max range scaling var postTestChannelLookup = new Dictionary(); while (stringNumber < allTextArray.Length && allTextArray[stringNumber] != "---- End Sensor Channel Information ----") { //Get PostTest Data information var rackIndex = 1; var moduleIndex = 2; var channelIndex = 3; var channelInformation = allTextArray[stringNumber].Split(','); var rackModuleChannel = "R" + channelInformation[rackIndex] + "M" + channelInformation[moduleIndex] + "C" + channelInformation[channelIndex]; postTestChannelLookup.Add(rackModuleChannel, channelInformation); stringNumber++; } if (stringNumber == allTextArray.Length) { throw new Exception("No End Sensor Channel Information"); } //Found "---- End Sensor Channel Information ----", so skip it and look for Start Calculated Channel Information stringNumber++; //---- End Sensor Channel Information ---- while (stringNumber < allTextArray.Length && allTextArray[stringNumber] != "---- Start Calculated Channel Information ----") { stringNumber++; } if (stringNumber == allTextArray.Length) { throw new Exception("No Start Calculated Channel Information"); } //Found "---- Start Calculated Channel Information ----", so skip it and its header text lines stringNumber++; //---- Start Calculated Channel Information ---- stringNumber++; //chan,descrip,processtype,1stchan,2ndchan,3rdchan,value,EU,expmaxrange var calculatedChannelLookup = new Dictionary(); while (stringNumber < allTextArray.Length && allTextArray[stringNumber] != "---- End Calculated Channel Information ----") { //Get calculated channel information var channelIndex = 0; var channelInformation = allTextArray[stringNumber].Split(','); var calcChannel = channelInformation[channelIndex]; calculatedChannelLookup.Add(calcChannel, channelInformation); stringNumber++; } if (stringNumber == allTextArray.Length) { throw new Exception("No End Calculated Channel Information"); } //Found "---- End Calculated Channel Information ----", so skip it and look for Start TOM Channel Information stringNumber++; //---- End Calculated Channel Information ---- while (stringNumber < allTextArray.Length && allTextArray[stringNumber] != "---- Start TOM Channel Information ----" && allTextArray[stringNumber] != "---- DIM Begin (1.0) ----" && allTextArray[stringNumber] != "---- G5 Digital Input Channels Begin ----") { stringNumber++; } var TOMChannelLookup = new Dictionary(); var G5DigitalInputChannelLookup = new Dictionary(); if (stringNumber < allTextArray.Length) { switch (allTextArray[stringNumber]) { case "---- Start TOM Channel Information ----": TOMChannelLookup = ProcessTOMChannelInformation(ref stringNumber, allTextArray); break; case "---- DIM Begin (1.0) ----": ProcessDIMInformation(ref stringNumber, allTextArray); break; case "---- G5 Digital Input Channels Begin ----": G5DigitalInputChannelLookup = ProcessG5DigitalInputChannelInformation(ref stringNumber, allTextArray); break; } } while (stringNumber < allTextArray.Length && allTextArray[stringNumber] != "---- DIM Begin (1.0) ----" && allTextArray[stringNumber] != "---- G5 Digital Input Channels Begin ----") { stringNumber++; } if (stringNumber < allTextArray.Length) { switch (allTextArray[stringNumber]) { case "---- DIM Begin (1.0) ----": ProcessDIMInformation(ref stringNumber, allTextArray); break; case "---- G5 Digital Input Channels Begin ----": G5DigitalInputChannelLookup = ProcessG5DigitalInputChannelInformation(ref stringNumber, allTextArray); break; } } while (stringNumber < allTextArray.Length && allTextArray[stringNumber] != "---- G5 Digital Input Channels Begin ----") { stringNumber++; } if (stringNumber < allTextArray.Length) { G5DigitalInputChannelLookup = ProcessG5DigitalInputChannelInformation(ref stringNumber, allTextArray); } //Add loop for multiple racks here //int rateIndex = 0; //int pretrigtimeIndex = 1; //int posttrigtimeIndex = 2; //int AdjAAfilterIndex = 3; //int prezerodataptsIndex = 5; //int postzerodataptsIndex = 6; foreach (var rackModule in moduleLookup) { //Get the non-TOM modules var module = new Test.Module(_test); var trigmodeIndex = 2; InitializeModule(samplingInformation, module, rackModule.Key, rackModule.Value[trigmodeIndex], out int rackNumber); var createModule = false; foreach (var rackModuleChannel in preTestChannelLookup) { var rackString = rackModuleChannel.Key.Substring(1, rackModule.Key.IndexOf('M') - 1); int.TryParse(rackString, out int rackInt); var moduleNumberStart = rackModuleChannel.Key.IndexOf('M') + 1; var moduleNumberEnd = rackModuleChannel.Key.IndexOf('C') - 1; var moduleString = rackModuleChannel.Key.Substring(moduleNumberStart, moduleNumberEnd - moduleNumberStart + 1); int.TryParse(moduleString, out int moduleInt); if (rackInt == rackNumber && moduleInt == module.Number) { createModule = true; GetPreAndPostTestData(module, preTestChannelLookup[rackModuleChannel.Key], postTestChannelLookup[rackModuleChannel.Key], allTextArray, year, month, day, rackModuleChannel.Key); } } if (createModule) { _test.Modules.Add(module); } createModule = false; foreach (var rackModuleChannel in G5DigitalInputChannelLookup) { var rackString = rackModuleChannel.Key.Substring(1, rackModule.Key.IndexOf('M') - 1); int.TryParse(rackString, out int rackInt); var moduleNumberStart = rackModuleChannel.Key.IndexOf('M') + 1; var moduleNumberEnd = rackModuleChannel.Key.IndexOf('C') - 1; var moduleString = rackModuleChannel.Key.Substring(moduleNumberStart, moduleNumberEnd - moduleNumberStart + 1); int.TryParse(moduleString, out int moduleInt); if (rackInt == rackNumber && moduleInt == module.Number) { createModule = true; GetG5TestData(module, G5DigitalInputChannelLookup[rackModuleChannel.Key], allTextArray, year, month, day, rackModuleChannel.Key); } } if (createModule) { _test.Modules.Add(module); } } var squibFileNumber = 901; foreach (var rackModule in moduleLookup) { //Now get the TOM modules var module = new Test.Module(_test); var trigmodeIndex = 2; InitializeModule(samplingInformation, module, rackModule.Key, rackModule.Value[trigmodeIndex], out int rackNumber); var createModule = false; foreach (var rackModuleChannel in TOMChannelLookup) { var rackString = rackModuleChannel.Key.Substring(1, rackModule.Key.IndexOf('M') - 1); int.TryParse(rackString, out int rackInt); var moduleNumberStart = rackModuleChannel.Key.IndexOf('M') + 1; var moduleNumberEnd = rackModuleChannel.Key.IndexOf('C') - 1; var moduleString = rackModuleChannel.Key.Substring(moduleNumberStart, moduleNumberEnd - moduleNumberStart + 1); int.TryParse(moduleString, out int moduleInt); if (rackInt == rackNumber && moduleInt == module.Number) { createModule = true; GetTOMSquibFireChannelsData(module, TOMChannelLookup[rackModuleChannel.Key], allTextArray, year, month, day, rackModuleChannel.Key, squibFileNumber); squibFileNumber++; squibFileNumber++; } } if (createModule) { _test.Modules.Add(module); } } //if (calculatedChannelLookup.Count > 0) //{ // //Now make a calculated channel module // int maxModuleNumber = 0; // foreach (DTS.Serialization.Test.Module mod in _test.Modules) // { // maxModuleNumber = Math.Max(maxModuleNumber, mod.Number); // } // DTS.Serialization.Test.Module module = new DTS.Serialization.Test.Module(_test); // //module.Number = maxModuleNumber + 1; // //int trigmodeIndex = 2; // int rackNumber = 0; // InitializeModule(samplingInformation, module, "R0M" + (maxModuleNumber + 1).ToString(), 1.ToString(), out rackNumber); // foreach (var calculatedChannel in calculatedChannelLookup.Values) // { // GetCalculatedChannelsData(module, calculatedChannel, allTextArray, year, month, day); // } // _test.Modules.Add(module); //} } return _test; } catch (System.Exception ex) { throw new Exception("encountered problem deserializing test from string", ex); } } private void InitializeModule(string[] samplingInformation, Test.Module module, string rackModuleKey, string rackModuleValueTrigmodeIndex, out int rackNumber) // KeyValuePair rackModule) { var rateIndex = 0; var pretrigtimeIndex = 1; var posttrigtimeIndex = 2; var AdjAAfilterIndex = 3; var prezerodataptsIndex = 5; var postzerodataptsIndex = 6; float.TryParse(samplingInformation[AdjAAfilterIndex], out float floatResult); module.AaFilterRateHz = floatResult; var moduleNumberStart = rackModuleKey.IndexOf('M') + 1; var moduleIndexString = rackModuleKey.Substring(moduleNumberStart, rackModuleKey.Length - moduleNumberStart); int.TryParse(moduleIndexString, out int intResult); module.Number = intResult; var rackIndexString = rackModuleKey.Substring(1, rackModuleKey.IndexOf('M') - 1); intResult = 0; if (rackIndexString == 0.ToString()) { rackNumber = 0; module.SerialNumber = "Calc"; module.BaseSerialNumber = "CBase"; } else { var rack = rackLookup[rackIndexString]; //rackNumber = 0; int.TryParse(rackIndexString, out intResult); rackNumber = intResult; module.SerialNumber = rack[module.Number + 1]; var racksnIndex = 1; module.BaseSerialNumber = rack[racksnIndex]; } ulong.TryParse(samplingInformation[prezerodataptsIndex], out ulong ulongResult); var preZeroDataPoints = ulongResult; ulong.TryParse(samplingInformation[postzerodataptsIndex], out ulongResult); var postZeroDataPoints = ulongResult; module.NumberOfSamples = preZeroDataPoints + postZeroDataPoints; double.TryParse(samplingInformation[posttrigtimeIndex], out double doubleResult); module.RequestedPostTriggerSeconds = doubleResult; module.PostTriggerSeconds = doubleResult; doubleResult = 0; double.TryParse(samplingInformation[pretrigtimeIndex], out doubleResult); module.RequestedPreTriggerSeconds = doubleResult; module.PreTriggerSeconds = doubleResult; intResult = 0; int.TryParse(rackModuleValueTrigmodeIndex, out intResult); if (intResult == 0) { module.RecordingMode = DFConstantsAndEnums.RecordingMode.CircularBuffer; } else if (intResult == 1) { module.RecordingMode = DFConstantsAndEnums.RecordingMode.RecorderMode; } floatResult = 0; float.TryParse(samplingInformation[rateIndex], out floatResult); module.SampleRateHz = floatResult; module.StartRecordSampleNumber = 0; module.TriggerSampleNumbers = new List(); module.UnsubsampledTriggerSampleNumbers = new List(); } private Dictionary ProcessTOMChannelInformation(ref int stringNumber, string[] allTextArray) { var TOMChannelLookup = new Dictionary(); //Found "---- Start TOM Channel Information ----", so skip it and its header text lines stringNumber++; //---- Start TOM Channel Information ---- stringNumber++; //---- TOM Squib Fire Channels ---- stringNumber++; //rack,module,chan,descrip,id,type,current,delay,durationON,duration,OhmLow,OhmHigh,ISO Code,measuredohms,recordtype,scalefactor1,scalefactor2,postmeasuredohms,voltage zero average ADC,current zero average ADC while (stringNumber < allTextArray.Length && allTextArray[stringNumber] != "---- TOM Digital Channels ----") { var rackIndex = 0; var moduleIndex = 1; var channelIndex = 2; //Get TOM Squib Fire channel information var channelInformation = allTextArray[stringNumber].Split(','); var rackModuleChannel = "R" + channelInformation[rackIndex] + "M" + channelInformation[moduleIndex] + "C" + channelInformation[channelIndex]; TOMChannelLookup.Add(rackModuleChannel, channelInformation); stringNumber++; } if (stringNumber == allTextArray.Length) { throw new Exception("No TOM Digital Channels Information"); } //Found "---- TOM Digital Channels ----", so skip it and its header text line stringNumber++; //---- TOM Digital Channels ---- stringNumber++; //rack,module,chan,type,delay,durationON,duration while (stringNumber < allTextArray.Length && allTextArray[stringNumber] != "---- End TOM Channel Information ----") { //Get TOM Digital channel information stringNumber++; } if (stringNumber == allTextArray.Length) { throw new Exception("No End TOM Channel Information"); } //Found "---- End TOM Channel Information ----", so skip it and look for DIM Begin (1.0) stringNumber++; //---- End TOM Channel Information ---- return TOMChannelLookup; } private void ProcessDIMInformation(ref int stringNumber, string[] allTextArray) { //Found "---- DIM Begin (1.0) ----", so skip it and its header text line stringNumber++; //---- DIM Begin (1.0) ---- stringNumber++; //Datachan,Rack,Module,Chan,Description,Serial No,Mode,Inverted,EID,Filename,Scale,Filter Mode,Filter Threshold,ISO CODE,Cable Test,Pre Test Results, Post TestResults while (stringNumber < allTextArray.Length && allTextArray[stringNumber] != "---- DIM End ----") { //Get DIM channel information stringNumber++; } if (stringNumber == allTextArray.Length) { throw new Exception("No DIM End"); } //Found "---- DIM End ----", so skip it and look for G5 Digital Input Channels Begin stringNumber++; //---- DIM End ---- } private Dictionary ProcessG5DigitalInputChannelInformation(ref int stringNumber, string[] allTextArray) { var G5DigitalInputChannelLookup = new Dictionary(); //Found "---- G5 Digital Input Channels Begin ----", so skip it and its header text line stringNumber++; //---- G5 Digital Input Channels Begin ---- stringNumber++; //datachan,rack,mod,chan,descrip,ISOCode,scale,invert while (stringNumber < allTextArray.Length && allTextArray[stringNumber] != "---- G5 Digital Input Channels End ----") { var rackIndex = 1; var moduleIndex = 2; var channelIndex = 3; var channelInformation = allTextArray[stringNumber].Split(','); var rackModuleChannel = "R" + channelInformation[rackIndex] + "M" + channelInformation[moduleIndex] + "C" + channelInformation[channelIndex]; G5DigitalInputChannelLookup.Add(rackModuleChannel, channelInformation); stringNumber++; } return G5DigitalInputChannelLookup; } private void GetPreAndPostTestData(Test.Module module, string[] channelPreTestData, string[] channelPostTestData, string[] allTextArray, int year, int month, int day, string rackModuleChannelKey) { var deserializedChannel = new Test.Module.AnalogInputChannel(module); deserializedChannel.PersistentChannelInfo = null; // We're going to use TDASPersistentChannelInfo deserializedChannel.Data = new Test.Module.Channel.DataArray(); //PreTest Data var chanIndex = 0; var descripIndex = 4; var snIndex = 5; var proptoextIndex = 11; var sensmveuormvveuIndex = 12; var extvoltIndex = 14; var EUIndex = 15; var filterIndex = 16; var invertIndex = 17; var zerorefIndex = 18; var desiredmaxrangeIndex = 19; var OffsetIndex = 22; var InitialEUIndex = 23; var ISOcodeIndex = 25; var CategoryIndex = 27; var PolynomialCoefficent1Index = 29; var PolynomialCoefficent2Index = 30; var PolynomialCoefficent3Index = 31; var PolynomialCoefficent4Index = 32; //PostTest Data var SNRatiodBIndex = 7; var prezeroIndex = 8; //const string SENSOR_CATEGORY_NORMAL = "0"; //const string SENSOR_CATEGORY_POT = "1"; //const string SENSOR_CATEGORY_IRTRACC = "2"; const string SENSOR_CATEGORY_POLYNOMIAL = "3"; //const int MAX_SENSOR_CATEGORIES = 4; int.TryParse(channelPreTestData[chanIndex], out int intResult); deserializedChannel.Number = intResult; deserializedChannel.Start = GenerateStartDateTime(allTextArray, year, month, day); //We are generating channels based on what's in the .TLF, but they may not exist on disk (removed or problem downloading), so initialize to -2 deserializedChannel.AbsoluteDisplayOrder = -2; deserializedChannel.Bridge = SensorConstants.BridgeType.FullBridge; deserializedChannel.BridgeResistanceOhms = 0.0; deserializedChannel.ZeroPoint = 0D; deserializedChannel.CalSignalEnabled = false; if (channelPreTestData[descripIndex] == string.Empty) { if (channelPreTestData.Length > ISOcodeIndex) { deserializedChannel.ChannelDescriptionString = "ISO: " + channelPreTestData[ISOcodeIndex]; } } else { deserializedChannel.ChannelDescriptionString = channelPreTestData[descripIndex]; if (channelPreTestData.Length > ISOcodeIndex) { deserializedChannel.ChannelName2 = "ISO: " + channelPreTestData[ISOcodeIndex]; } } deserializedChannel.ChannelId = rackModuleChannelKey; double.TryParse(channelPreTestData[desiredmaxrangeIndex], out double desiredMaxRange); deserializedChannel.DesiredRange = desiredMaxRange; deserializedChannel.EngineeringUnits = channelPreTestData[EUIndex]; deserializedChannel.ExcitationVoltage = ExcitationVoltageOptions.ExcitationVoltageOption.Undefined; double.TryParse(channelPreTestData[InitialEUIndex], out double initialEU); deserializedChannel.InitialEu = initialEU; if (channelPreTestData[invertIndex] == "0") { deserializedChannel.IsInverted = false; } else { deserializedChannel.IsInverted = true; } if (channelPreTestData.Length > ISOcodeIndex) { deserializedChannel.IsoCode = channelPreTestData[ISOcodeIndex]; } if (channelPreTestData.Length > PolynomialCoefficent4Index) { if (channelPreTestData[CategoryIndex] == SENSOR_CATEGORY_POLYNOMIAL) { deserializedChannel.LinearizationFormula = new Common.Classes.Sensors.LinearizationFormula(); deserializedChannel.LinearizationFormula.NonLinearStyle = NonLinearStyles.Polynomial; var coefficients = new List(); double.TryParse(channelPreTestData[PolynomialCoefficent4Index], out double doubleResult); //M (exponent of 0) coefficients.Add(doubleResult); doubleResult = 0.0; double.TryParse(channelPreTestData[PolynomialCoefficent3Index], out doubleResult); //C (exponent of 3) coefficients.Add(doubleResult); doubleResult = 0.0; double.TryParse(channelPreTestData[PolynomialCoefficent2Index], out doubleResult); //B (exponent of 2) coefficients.Add(doubleResult); doubleResult = 0.0; double.TryParse(channelPreTestData[PolynomialCoefficent1Index], out doubleResult); //A (exponent of 1) coefficients.Add(doubleResult); deserializedChannel.LinearizationFormula.PolynomialCoefficients = coefficients.ToArray(); deserializedChannel.LinearizationFormula.FromTDCSerializeString(); //To set it valid??? } } double.TryParse(channelPreTestData[extvoltIndex], out double measuredExcitationVoltage); deserializedChannel.MeasuredExcitationVoltage = measuredExcitationVoltage; double.TryParse(channelPostTestData[SNRatiodBIndex], out double snRatio); deserializedChannel.NoiseAsPercentageOfFullScale = snRatio; short.TryParse(channelPostTestData[prezeroIndex], out short preZero); deserializedChannel.PreTestZeroLevelAdc = preZero; if (channelPreTestData[proptoextIndex] == "0") { deserializedChannel.ProportionalToExcitation = false; } else { deserializedChannel.ProportionalToExcitation = true; } if (channelPreTestData[OffsetIndex] == "Y") { deserializedChannel.RemoveOffset = true; } else { deserializedChannel.RemoveOffset = false; } double.TryParse(channelPostTestData[sensmveuormvveuIndex], out double sensitivity); deserializedChannel.Sensitivity = sensitivity; //temp deserializedChannel.SerialNumber = channelPreTestData[snIndex]; deserializedChannel.ShuntEnabled = true; switch (channelPreTestData[filterIndex]) { case "100": deserializedChannel.SoftwareFilter = ChannelFilter.Class60.ToString(); break; case "300": deserializedChannel.SoftwareFilter = ChannelFilter.Class180.ToString(); break; case "1000": deserializedChannel.SoftwareFilter = ChannelFilter.Class600.ToString(); break; case "1650": deserializedChannel.SoftwareFilter = ChannelFilter.Class1000.ToString(); break; default: deserializedChannel.SoftwareFilter = ChannelFilter.Unfiltered.ToString(); break; } deserializedChannel.VoltageInsertionCheckEnabled = false; deserializedChannel.ZeroAverageWindow = new Test.IntervalSec(0, 0); //So that AverageOverTime will return what UsePreEventDiagnosticsZero would return switch (channelPreTestData[zerorefIndex]) { case "0": deserializedChannel.ZeroMethod = ZeroMethodType.AverageOverTime; break; case "1": deserializedChannel.ZeroMethod = ZeroMethodType.UsePreEventDiagnosticsZero; break; case "2": deserializedChannel.ZeroMethod = ZeroMethodType.None; break; default: deserializedChannel.ZeroMethod = ZeroMethodType.None; break; } module.Channels.Add(deserializedChannel); } private void GetG5TestData(Test.Module module, string[] channelG5DigitalInputData, string[] allTextArray, int year, int month, int day, string rackModuleChannelKey) { var deserializedChannel = new Test.Module.AnalogInputChannel(module); deserializedChannel.PersistentChannelInfo = null; // We're going to use TDASPersistentChannelInfo deserializedChannel.Data = new Test.Module.Channel.DataArray(); //G5 Digital Input Data var chanIndex = 3; var descripIndex = 4; var ISOCodeIndex = 5; var invertIndex = 7; int.TryParse(channelG5DigitalInputData[chanIndex], out int intResult); deserializedChannel.Number = intResult; deserializedChannel.Start = GenerateStartDateTime(allTextArray, year, month, day); //We are generating channels based on what's in the .TLF, but they may not exist on disk (removed or problem downloading), so initialize to -2 deserializedChannel.AbsoluteDisplayOrder = -2; deserializedChannel.Bridge = SensorConstants.BridgeType.FullBridge; deserializedChannel.BridgeResistanceOhms = 0.0; deserializedChannel.ZeroPoint = 0D; deserializedChannel.CalSignalEnabled = false; deserializedChannel.ChannelDescriptionString = channelG5DigitalInputData[descripIndex]; deserializedChannel.ChannelId = rackModuleChannelKey; deserializedChannel.DesiredRange = 0.0; deserializedChannel.EngineeringUnits = "0/1";//temp deserializedChannel.ExcitationVoltage = ExcitationVoltageOptions.ExcitationVoltageOption.Undefined; deserializedChannel.InitialEu = 0.0; if (channelG5DigitalInputData[invertIndex] == "0") { deserializedChannel.IsInverted = false; } else { deserializedChannel.IsInverted = true; } deserializedChannel.IsoCode = channelG5DigitalInputData[ISOCodeIndex]; deserializedChannel.MeasuredExcitationVoltage = 0.0; deserializedChannel.NoiseAsPercentageOfFullScale = 0.0; deserializedChannel.PreTestZeroLevelAdc = 0; deserializedChannel.ProportionalToExcitation = false; deserializedChannel.RemoveOffset = false; deserializedChannel.Sensitivity = 0.0; //temp deserializedChannel.SerialNumber = string.Empty; deserializedChannel.ShuntEnabled = true; deserializedChannel.SoftwareFilter = ChannelFilter.Unfiltered.ToString(); deserializedChannel.VoltageInsertionCheckEnabled = false; deserializedChannel.ZeroAverageWindow = new Test.IntervalSec(0, 0); //So that AverageOverTime will return what UsePreEventDiagnosticsZero would return deserializedChannel.ZeroMethod = ZeroMethodType.AverageOverTime; module.Channels.Add(deserializedChannel); } private void GetTOMSquibFireChannelsData(Test.Module module, string[] channelTOMData, string[] allTextArray, int year, int month, int day, string rackModuleChannelKey, int squibFileNumber) { var deserializedVoltageChannel = new Test.Module.AnalogInputChannel(module); var deserializedCurrentChannel = new Test.Module.AnalogInputChannel(module); deserializedVoltageChannel.PersistentChannelInfo = null; // We're going to use TDASPersistentChannelInfo deserializedCurrentChannel.PersistentChannelInfo = null; // We're going to use TDASPersistentChannelInfo deserializedVoltageChannel.Data = new Test.Module.Channel.DataArray(); deserializedCurrentChannel.Data = new Test.Module.Channel.DataArray(); //TOM Squib Fire Channels var descripIndex = 3; var idIndex = 4; //Most recent version: var ISO_CodeIndex = 12; var postMeasuredOhmsIndex = 17; var voltageZeroAverageADCIndex = 18; var currentZeroAverageADCIndex = 19; if (channelTOMData.Length == 17) //hack { postMeasuredOhmsIndex = 16; } deserializedVoltageChannel.Number = squibFileNumber; deserializedCurrentChannel.Number = squibFileNumber + 1; deserializedVoltageChannel.Start = GenerateStartDateTime(allTextArray, year, month, day); deserializedCurrentChannel.Start = GenerateStartDateTime(allTextArray, year, month, day); //We are generating channels based on what's in the .TLF, but they may not exist on disk (removed or problem downloading), so initialize to -2 deserializedVoltageChannel.AbsoluteDisplayOrder = -2; deserializedCurrentChannel.AbsoluteDisplayOrder = -2; deserializedVoltageChannel.Bridge = SensorConstants.BridgeType.FullBridge; deserializedCurrentChannel.Bridge = SensorConstants.BridgeType.FullBridge; double.TryParse(channelTOMData[postMeasuredOhmsIndex], out double doubleResult); deserializedVoltageChannel.BridgeResistanceOhms = doubleResult; deserializedCurrentChannel.BridgeResistanceOhms = doubleResult; deserializedVoltageChannel.ZeroPoint = 0D; deserializedCurrentChannel.ZeroPoint = 0D; deserializedVoltageChannel.CalSignalEnabled = false; deserializedCurrentChannel.CalSignalEnabled = false; deserializedVoltageChannel.ChannelDescriptionString = channelTOMData[descripIndex]; deserializedCurrentChannel.ChannelDescriptionString = channelTOMData[descripIndex]; deserializedVoltageChannel.ChannelId = rackModuleChannelKey; deserializedCurrentChannel.ChannelId = rackModuleChannelKey; deserializedVoltageChannel.DesiredRange = 1; deserializedCurrentChannel.DesiredRange = 1; deserializedVoltageChannel.EngineeringUnits = "Volts"; deserializedCurrentChannel.EngineeringUnits = "Amps"; deserializedVoltageChannel.ExcitationVoltage = ExcitationVoltageOptions.ExcitationVoltageOption.Volt5; deserializedCurrentChannel.ExcitationVoltage = ExcitationVoltageOptions.ExcitationVoltageOption.Volt5; deserializedVoltageChannel.InitialEu = 0.0; deserializedCurrentChannel.InitialEu = 0.0; deserializedVoltageChannel.IsInverted = false; deserializedCurrentChannel.IsInverted = false; deserializedVoltageChannel.IsoCode = channelTOMData[ISO_CodeIndex]; deserializedCurrentChannel.IsoCode = channelTOMData[ISO_CodeIndex]; deserializedVoltageChannel.MeasuredExcitationVoltage = 0.0; deserializedCurrentChannel.MeasuredExcitationVoltage = 0.0; deserializedVoltageChannel.NoiseAsPercentageOfFullScale = 0.0; deserializedCurrentChannel.NoiseAsPercentageOfFullScale = 0.0; short zeroAverageADC = 0; if (channelTOMData.Length > voltageZeroAverageADCIndex) { short.TryParse(channelTOMData[voltageZeroAverageADCIndex], out zeroAverageADC); } deserializedVoltageChannel.PreTestZeroLevelAdc = zeroAverageADC; zeroAverageADC = 0; if (channelTOMData.Length > currentZeroAverageADCIndex) { short.TryParse(channelTOMData[currentZeroAverageADCIndex], out zeroAverageADC); } deserializedCurrentChannel.PreTestZeroLevelAdc = zeroAverageADC; deserializedVoltageChannel.ProportionalToExcitation = true; deserializedCurrentChannel.ProportionalToExcitation = true; deserializedVoltageChannel.RemoveOffset = true; deserializedCurrentChannel.RemoveOffset = true; deserializedVoltageChannel.Sensitivity = 0.0; deserializedCurrentChannel.Sensitivity = 0.0; deserializedVoltageChannel.SerialNumber = channelTOMData[idIndex]; deserializedCurrentChannel.SerialNumber = channelTOMData[idIndex]; deserializedVoltageChannel.ShuntEnabled = false; deserializedCurrentChannel.ShuntEnabled = false; deserializedVoltageChannel.SoftwareFilter = ChannelFilter.Unfiltered.ToString(); deserializedCurrentChannel.SoftwareFilter = ChannelFilter.Unfiltered.ToString(); deserializedVoltageChannel.VoltageInsertionCheckEnabled = false; deserializedCurrentChannel.VoltageInsertionCheckEnabled = false; deserializedVoltageChannel.ZeroAverageWindow = new Test.IntervalSec(0, 0); deserializedCurrentChannel.ZeroAverageWindow = new Test.IntervalSec(0, 0); deserializedVoltageChannel.ZeroMethod = ZeroMethodType.UsePreEventDiagnosticsZero; deserializedCurrentChannel.ZeroMethod = ZeroMethodType.UsePreEventDiagnosticsZero; module.Channels.Add(deserializedVoltageChannel); module.Channels.Add(deserializedCurrentChannel); } private void GetCalculatedChannelsData(Test.Module module, string[] calculatedChannelData, string[] allTextArray, int year, int month, int day) { var deserializedChannel = new Test.Module.AnalogInputChannel(module); deserializedChannel.PersistentChannelInfo = null; // We're going to use TDASPersistentChannelInfo deserializedChannel.Data = new Test.Module.Channel.DataArray(); //Calculated Channel Data var chanIndex = 0; var descripIndex = 1; var EUIndex = 7; int.TryParse(calculatedChannelData[chanIndex], out int intResult); deserializedChannel.Number = intResult; deserializedChannel.Start = GenerateStartDateTime(allTextArray, year, month, day); //We are generating channels based on what's in the .TLF, but they may not exist on disk (removed or problem downloading), so initialize to -2 deserializedChannel.AbsoluteDisplayOrder = -2; deserializedChannel.Bridge = SensorConstants.BridgeType.FullBridge; deserializedChannel.BridgeResistanceOhms = 0.0; deserializedChannel.ZeroPoint = 0D; deserializedChannel.CalSignalEnabled = false; deserializedChannel.ChannelDescriptionString = calculatedChannelData[descripIndex]; deserializedChannel.ChannelId = "C" + deserializedChannel.Number; deserializedChannel.DesiredRange = 0.0; deserializedChannel.EngineeringUnits = calculatedChannelData[EUIndex]; deserializedChannel.ExcitationVoltage = ExcitationVoltageOptions.ExcitationVoltageOption.Undefined; deserializedChannel.InitialEu = 0.0; deserializedChannel.IsInverted = false; deserializedChannel.IsoCode = string.Empty; deserializedChannel.MeasuredExcitationVoltage = 0.0; deserializedChannel.NoiseAsPercentageOfFullScale = 0.0; deserializedChannel.PreTestZeroLevelAdc = 0; deserializedChannel.ProportionalToExcitation = false; deserializedChannel.RemoveOffset = false; deserializedChannel.Sensitivity = 0.0; //temp deserializedChannel.SerialNumber = string.Empty; deserializedChannel.ShuntEnabled = true; deserializedChannel.SoftwareFilter = ChannelFilter.Unfiltered.ToString(); deserializedChannel.VoltageInsertionCheckEnabled = false; deserializedChannel.ZeroAverageWindow = new Test.IntervalSec(0, 0); //So that AverageOverTime will return what UsePreEventDiagnosticsZero would return deserializedChannel.ZeroMethod = ZeroMethodType.AverageOverTime; module.CalculatedChannels.Add(deserializedChannel); } private DateTime GenerateStartDateTime(string[] allTextArray, int year, int month, int day) { var startIndex = 0; startIndex = allTextArray[3].LastIndexOf(':') + 1; //seconds var secondString = allTextArray[3].Substring(startIndex, allTextArray[3].Length - startIndex); startIndex = 0; //hour var hourString = allTextArray[3].Substring(startIndex, 2); startIndex = allTextArray[3].IndexOf(':') + 1; //minute var minuteString = allTextArray[3].Substring(startIndex, 2); int.TryParse(secondString, out int intResult); var second = intResult; intResult = 0; int.TryParse(hourString, out intResult); var hour = intResult; intResult = 0; int.TryParse(minuteString, out intResult); var minute = intResult; return new DateTime(year, month, day, hour, minute, second); } /// /// Perform read of all test and channel data. /// /// /// /// The pathname of the directory containing the serialization to be read. /// /// /// /// The generated from the specified serialization. /// /// /// /// A test populated with deserialized test and channel data. /// /// public void Read(string directory, out Test test) //public void Read(Test.Module.Channel channel, Test.Module module, string channelFileName, out DTS.Serialization.Test test) { Read(directory, out test, null); } /// /// Perform read of all test and channel data. /// /// /// /// The pathname of the directory containing the serialization to be read. /// /// /// /// The generated from the specified serialization. /// /// /// /// A to be notified with read /// status updates. /// /// /// /// A test populated with deserialized test and channel data. /// /// public void Read(string directory, out Test test, EventHandler onEvent) //public void Read(Test.Module.Channel channel, Test.Module module, string channelFileName, out DTS.Serialization.Test test, Reader.EventHandler onEvent) { string testFileName = null; try { testFileName = GetTestFilename(directory); var channelFileNames = GetChannelFilenames(directory); //Combine the following into one foreach //Remove any without .BIN extension (.BIN_OriginalData, for example) var toRemove = new List(); foreach (var fileName in channelFileNames) { if (fileName.Substring(fileName.Length - 4, 4) != ".BIN") { toRemove.Add(fileName); } } foreach (var fileName in toRemove) { channelFileNames.Remove(fileName); } //Remove any remaining without a number (_Orig.BIN, for example) toRemove = new List(); foreach (var fileName in channelFileNames) { if (FileType.GetChannelNumberFromChannelFileName(fileName) == 0) { toRemove.Add(fileName); } } foreach (var fileName in toRemove) { channelFileNames.Remove(fileName); } ////Move Calculated Channel filenames to a different list //List calculatedChannelFileNames = new List(); //foreach (string fileName in channelFileNames) //{ // int startIndex = fileName.LastIndexOf('.') - 5; // if (fileName.Substring(startIndex, 2) == "_C") // { // calculatedChannelFileNames.Add(fileName); // } //} //foreach (string filename in calculatedChannelFileNames) //{ // channelFileNames.Remove(filename); //} //int currentChannelFileNameIndex = 0; onEvent?.Invoke(Event.NumberOfFilesDetermined, channelFileNames.Count + 1); test = DeserializeTestFromTLF(testFileName); // Generated from a serialization. Get the timestamp. test.InceptionDate = System.IO.File.GetLastWriteTime(testFileName); //Hack Alert. Test Id doesn't always match the TestID -- use the dts file name as the test id. var testId = Path.GetFileNameWithoutExtension(testFileName); if (false == test.Id.Equals(testId)) { APILogger.Log("DTS File Name: " + testId + " does not match Test Id: " + test.Id + " . Using file name as test Id"); } var bByPass = false; foreach (var fileName in channelFileNames) { var startIndex = fileName.LastIndexOf('.') - 3; var currentFileNameNumberString = fileName.Substring(startIndex, 3); int.TryParse(currentFileNameNumberString, out int currentFileNameNumber); foreach (var module in test.Modules) { foreach (var channel in module.Channels) { if (channel.Number == currentFileNameNumber) { if (!System.IO.File.Exists(fileName)) { APILogger.Log("File not found ", fileName); throw new FileNotFoundException(fileName); } ReadChannel(channel, module, fileName, ref bByPass); channel.AbsoluteDisplayOrder = channelFileNames.IndexOf(fileName); } } } } //foreach (string fileName in calculatedChannelFileNames) //{ // int startIndex = fileName.LastIndexOf('.') - 3; // string currentFileNameNumberString = fileName.Substring(startIndex, 3); // int currentFileNameNumber = 0; // Int32.TryParse(currentFileNameNumberString, out currentFileNameNumber); // foreach (Test.Module module in test.Modules) //only one module with calculated channels? // { // foreach (Test.Module.Channel channel in module.CalculatedChannels) // { // if (channel.Number == currentFileNameNumber) // { // if (!System.IO.File.Exists(fileName)) // { // APILogger.Log("File not found ", fileName); // throw new FileNotFoundException(fileName); // } // ReadChannel(channel, module, fileName, ref bByPass); // channel.AbsoluteDisplayOrder = channelFileNames.IndexOf(fileName) + 1000; // } // } // } //} onEvent?.Invoke(Event.FullReadComplete, channelFileNames.Count + 1); } catch (Exception ex) { APILogger.Log($"Exception is '{ex.Message}'"); if (ex is MissingFileException || ex is BadCrcException || ex is UserException) { throw ex; } else { throw new Exception("Encountered problem reading test file \"" + (testFileName ?? "") + "\"", ex); } } catch (FileNotFoundException) { throw; } finally { onEvent?.Invoke(Event.FullReadComplete, 0); } } public void ReadChannel(Test.Module.Channel channel, Test.Module module, string channelFileName, ref bool bByPass) { APILogger.Log("Getting stream"); var attempt = 0; var bFailed = true; while (attempt < 30 && bFailed) { attempt++; try { APILogger.Log("reading file 666 ", channelFileName); using (var mutex = new System.Threading.Mutex(false, channelFileName.Replace(Path.DirectorySeparatorChar, '_'))) { while (!mutex.WaitOne(50, false)) { System.Threading.Thread.Sleep(5); } try { using (var stream = System.IO.File.OpenRead(channelFileName)) { APILogger.Log("Getting reader"); using (var reader = new BinaryReader(stream)) { var channelInfo = new TDASBinaryChannelHeader(); var fields = Enum.GetValues(typeof(PersistentChannel.Field)).Cast().ToArray(); APILogger.Log("Got fields"); foreach (var field in fields) { switch (field) { case PersistentChannel.Field.AcquisitionRate: channelInfo.AcquisitionRate = reader.ReadDouble(); break; case PersistentChannel.Field.NumberOfPreT0DataPoints: channelInfo.NumberOfPreT0DataPoints = reader.ReadInt32(); if (channelInfo.NumberOfPreT0DataPoints >= -1) { if (module.TriggerSampleNumbers.Count == 0) { module.TriggerSampleNumbers.Add((ulong)channelInfo.NumberOfPreT0DataPoints); } } break; case PersistentChannel.Field.NumberOfPostT0DataPoints: channelInfo.NumberOfPostT0DataPoints = reader.ReadInt32(); if (channelInfo.NumberOfPostT0DataPoints >= -1) { module.NumberOfSamples = (ulong)(channelInfo.NumberOfPreT0DataPoints + channelInfo.NumberOfPostT0DataPoints); } break; case PersistentChannel.Field.PreZeroLevelInCnts: channelInfo.PreZeroLevelInCnts = reader.ReadInt32(); break; case PersistentChannel.Field.PreCalLevelInCnts: channelInfo.PreCalLevelInCnts = reader.ReadInt32(); break; case PersistentChannel.Field.SignalToNoiseRatioInDb: channelInfo.SignalToNoiseRatioInDb = reader.ReadDouble(); break; case PersistentChannel.Field.PostZeroLevelInCnts: channelInfo.PostZeroLevelInCnts = reader.ReadInt32(); break; case PersistentChannel.Field.PostCalLevelInCnts: channelInfo.PostCalLevelInCnts = reader.ReadInt32(); break; case PersistentChannel.Field.DataZeroLevelInCnts: channelInfo.DataZeroLevelInCnts = (short)reader.ReadInt32(); break; case PersistentChannel.Field.ScaleFactorMVPerCnt: channelInfo.ScaleFactorMVPerCnt = reader.ReadDouble(); break; case PersistentChannel.Field.ScaleFactorEUPerCnt: channelInfo.ScaleFactorEUPerCnt = reader.ReadDouble(); break; } }//end foreach try { const int DataChunkSize = 0x1000; var dataChunk = new short[DataChunkSize]; var analogChannel = channel as Test.Module.AnalogInputChannel; analogChannel.Multiplier = channel.Data.Multiplier; analogChannel.UnitConversion = channel.Data.UnitConversion; analogChannel.UserOffsetEU = channel.Data.UserOffsetEU; if (null != analogChannel) { if (channel is Test.Module.CalculatedChannel) { var cc = channel as Test.Module.CalculatedChannel; analogChannel.AverageAdcOverTime = new AverageShortValueOverTime(0, cc.SampleRateHz, "s"); } else { analogChannel.AverageAdcOverTime = new AverageShortValueOverTime(0, analogChannel.ParentModule.SampleRateHz, "s"); } } channel.TDASPersistentChannelInfo = new PersistentChannel(channelFileName, null, false); channel.Data = new Test.Module.Channel.DataArray(); //if (channelInfo.ScaleFactorMVPerCnt == 0) //{ // //Squibs have a ScaleFactorMVPerCnt of 0, but ScaleFactorEUPerCnt is all we need. // //So, to make the EU come out right do the following // channel.Data.MvPerEu = 1; // channel.Data.ScaleFactorMv = channelInfo.ScaleFactorEUPerCnt; //} //else //{ // voltage = (channel as DTS.Serialization.Test.Module.AnalogInputChannel).MeasuredExcitationVoltage; // channel.Data.MvPerEu = channelInfo.ScaleFactorMVPerCnt / channelInfo.ScaleFactorEUPerCnt; // * voltage); // channel.Data.ScaleFactorMv = channelInfo.ScaleFactorEUPerCnt * (voltage * channel.Data.MvPerEu); //} channel.Data.ScaleFactorMv = channelInfo.ScaleFactorMVPerCnt; channel.Data.ScaleFactorEU = channelInfo.ScaleFactorEUPerCnt; channel.Data.DataZeroLevel = (short)channelInfo.DataZeroLevelInCnts; channel.Data.UseEUScaleFactors = true; //Since this is TDAS channel.Data.MvPerEu = channelInfo.ScaleFactorMVPerCnt / channelInfo.ScaleFactorEUPerCnt;//Just to initialize to something channel.Data.Multiplier = analogChannel.Multiplier; channel.Data.UnitConversion = analogChannel.UnitConversion; channel.Data.UserOffsetEU = analogChannel.UserOffsetEU; } catch (System.Exception ex) { APILogger.Log($"Exception is '{ex.Message}'"); if (ex is MissingFileException) { throw ex; } throw new Exception("encountered problem extracting channel data from serialization", ex); } }//using binary stream }//using file stream } catch (System.Exception) { throw; } finally { mutex.ReleaseMutex(); } } APILogger.Log("successfully opened file after, ", attempt, " attempts"); bFailed = false; }//end try catch (FileNotFoundException) { APILogger.Log(string.Format("File not found " + channelFileName)); throw; } catch (System.Exception ex) { //HACK ALERT! This method is eating legitimate exceptions in an attempt to satisfy some retry algorithm. if (attempt == 30) { throw; } APILogger.Log("attempt number: ", attempt, ex); System.Threading.Thread.Sleep(200); } }//end while } } } }