init
This commit is contained in:
@@ -0,0 +1,190 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace DatabaseExport
|
||||
{
|
||||
public class CalibrationRecords
|
||||
{
|
||||
public CalibrationRecord[] Records { get; set; } = { new CalibrationRecord() };
|
||||
|
||||
public CalibrationRecords(CalibrationRecords copy)
|
||||
{
|
||||
var records = new CalibrationRecord[copy.Records.Length];
|
||||
for (var i = 0; i < copy.Records.Length; i++)
|
||||
{
|
||||
records[i] = new CalibrationRecord(copy.Records[i]);
|
||||
}
|
||||
Records = records;
|
||||
}
|
||||
|
||||
public CalibrationRecords()
|
||||
{
|
||||
Records = new CalibrationRecord[] { new CalibrationRecord() };
|
||||
}
|
||||
public CalibrationRecords(string records)
|
||||
{
|
||||
FromSerializedString(records);
|
||||
}
|
||||
public void FromSerializedString(string s)
|
||||
{
|
||||
var tokens = s.Split(new string[] { MySeparator }, StringSplitOptions.None);
|
||||
for (var i = 0; i < tokens.Length; i++) { tokens[i] = tokens[i].Replace(MySeparatorBackup, MySeparator); }
|
||||
|
||||
var records = new List<CalibrationRecord>();
|
||||
foreach (var token in tokens)
|
||||
{
|
||||
records.Add(new CalibrationRecord(token));
|
||||
}
|
||||
Records = records.ToArray();
|
||||
}
|
||||
private const string MySeparator = "__x__";
|
||||
private const string MySeparatorBackup = "___xx___";
|
||||
public string ToSerializedString(SensorCalibration sc)
|
||||
{
|
||||
var records = new List<string>();
|
||||
|
||||
foreach (var r in Records) { records.Add(r.ToSerializedString(sc)); }
|
||||
|
||||
for (var i = 0; i < records.Count; i++)
|
||||
{
|
||||
System.Diagnostics.Trace.Assert(!records[i].Contains(MySeparatorBackup));
|
||||
records[i] = records[i].Replace(MySeparator, MySeparatorBackup);
|
||||
}
|
||||
return string.Join(MySeparator, records.ToArray());
|
||||
}
|
||||
}
|
||||
|
||||
public class CalibrationRecord
|
||||
{
|
||||
public double Sensitivity { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// ZeroPoint is used to hold the calibration certificate field for 2D/3D IR-TRACC cal certs
|
||||
/// it is used to zero the IR-TRACC and POT data prior to being fed into the 3D equations
|
||||
/// </summary>
|
||||
private double _zeroPoint = 0D;
|
||||
public double ZeroPoint
|
||||
{
|
||||
get
|
||||
{
|
||||
if (false == Equals(Poly.CalibrationFactor, 0.0))
|
||||
{
|
||||
// This field is always calculated. Do not return stored value unless we are unable to calculate
|
||||
return Poly.ZeroPositionIntercept / Poly.CalibrationFactor;
|
||||
}
|
||||
return _zeroPoint;
|
||||
}
|
||||
set => _zeroPoint = value;
|
||||
}
|
||||
|
||||
public LinearizationFormula Poly { get; set; }
|
||||
|
||||
public bool AtCapacity { get; set; } = false;
|
||||
|
||||
//change this, and others, to use the sensor's values?
|
||||
public string EngineeringUnits { get; set; } = "g";
|
||||
|
||||
|
||||
public Test.Module.Channel.Sensor.SensUnits SensitivityUnits { get; set; } = Test.Module.Channel.Sensor.SensUnits.NONE;
|
||||
|
||||
public Test.Module.Channel.Sensor.ExcitationVoltageOption Excitation { get; set; } = Test.Module.Channel.Sensor.ExcitationVoltageOption.Volt5;
|
||||
|
||||
public int CapacityOutputIsBasedOn { get; set; } = 1;
|
||||
private enum Fields
|
||||
{
|
||||
Sensitivity,
|
||||
Poly,
|
||||
AtCapacity,
|
||||
EngineeringUnits,
|
||||
Excitation,
|
||||
CapacityOutputIsBasedOn,
|
||||
SensitivityUnits,
|
||||
ZeroPoint
|
||||
};
|
||||
public string ToSerializedString(SensorCalibration parentCal)
|
||||
{
|
||||
var tokens = new List<string>();
|
||||
var fields = Enum.GetValues(typeof(Fields)).Cast<Fields>().ToArray();
|
||||
foreach (var field in fields)
|
||||
{
|
||||
switch (field)
|
||||
{
|
||||
case Fields.AtCapacity: tokens.Add(AtCapacity.ToString()); break;
|
||||
case Fields.EngineeringUnits: tokens.Add(EngineeringUnits); break;
|
||||
case Fields.Excitation: tokens.Add(Excitation.ToString()); break;
|
||||
case Fields.Poly:
|
||||
if (parentCal.NonLinear) { Poly.MarkValid(true); }
|
||||
else { Poly.MarkValid(false); }
|
||||
tokens.Add(Poly.ToSerializeString());
|
||||
break;
|
||||
case Fields.Sensitivity: tokens.Add(Sensitivity.ToString(System.Globalization.CultureInfo.InvariantCulture)); break;
|
||||
case Fields.CapacityOutputIsBasedOn: tokens.Add(CapacityOutputIsBasedOn.ToString()); break;
|
||||
case Fields.SensitivityUnits: tokens.Add(SensitivityUnits.ToString()); break;
|
||||
case Fields.ZeroPoint:
|
||||
tokens.Add(ZeroPoint.ToString(System.Globalization.CultureInfo.InvariantCulture)); break;
|
||||
default: throw new NotSupportedException("unknown CalibrationRecord field: " + field.ToString());
|
||||
}
|
||||
}
|
||||
for (var i = 0; i < tokens.Count; i++)
|
||||
{
|
||||
if (null == tokens[i]) { tokens[i] = ""; }
|
||||
tokens[i] = tokens[i].Replace(System.Globalization.CultureInfo.InvariantCulture.TextInfo.ListSeparator, "x_Separator_x");
|
||||
}
|
||||
return string.Join(System.Globalization.CultureInfo.InvariantCulture.TextInfo.ListSeparator, tokens.ToArray());
|
||||
}
|
||||
public void FromString(string s)
|
||||
{
|
||||
var tokens = s.Split(new string[] { System.Globalization.CultureInfo.InvariantCulture.TextInfo.ListSeparator }, StringSplitOptions.None);
|
||||
|
||||
var fields = Enum.GetValues(typeof(Fields)).Cast<Fields>().ToArray();
|
||||
|
||||
for (var i = 0; i < tokens.Length && i < fields.Length; i++)
|
||||
{
|
||||
var token = tokens[i].Replace("x_Separator_x", System.Globalization.CultureInfo.InvariantCulture.TextInfo.ListSeparator);
|
||||
switch (fields[i])
|
||||
{
|
||||
case Fields.AtCapacity: AtCapacity = Convert.ToBoolean(token); break;
|
||||
case Fields.EngineeringUnits: EngineeringUnits = token; break;
|
||||
case Fields.Excitation: Excitation = (Test.Module.Channel.Sensor.ExcitationVoltageOption)Enum.Parse(typeof(Test.Module.Channel.Sensor.ExcitationVoltageOption), token); break;
|
||||
case Fields.Poly: Poly = new LinearizationFormula(); Poly.FromSerializeString(token); break;
|
||||
case Fields.Sensitivity: Sensitivity = Convert.ToDouble(token, System.Globalization.CultureInfo.InvariantCulture); break;
|
||||
case Fields.CapacityOutputIsBasedOn: CapacityOutputIsBasedOn = Convert.ToInt32(token); break;
|
||||
case Fields.SensitivityUnits: SensitivityUnits = (Test.Module.Channel.Sensor.SensUnits)Enum.Parse(typeof(Test.Module.Channel.Sensor.SensUnits), token); break;
|
||||
case Fields.ZeroPoint: ZeroPoint = Convert.ToDouble(token, System.Globalization.CultureInfo.InvariantCulture); break;
|
||||
default: throw new NotSupportedException("unknown CalibrationRecord field: " + fields.ToArray());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
public CalibrationRecord(string s)
|
||||
{
|
||||
FromString(s);
|
||||
}
|
||||
public CalibrationRecord(CalibrationRecord copy)
|
||||
{
|
||||
var fields = Enum.GetValues(typeof(Fields)).Cast<Fields>().ToArray();
|
||||
foreach (var field in fields)
|
||||
{
|
||||
switch (field)
|
||||
{
|
||||
case Fields.AtCapacity: AtCapacity = copy.AtCapacity; break;
|
||||
case Fields.EngineeringUnits: EngineeringUnits = copy.EngineeringUnits; break;
|
||||
case Fields.Excitation: Excitation = copy.Excitation; break;
|
||||
case Fields.Poly: Poly = new LinearizationFormula(copy.Poly); break;
|
||||
case Fields.Sensitivity: Sensitivity = copy.Sensitivity; break;
|
||||
case Fields.CapacityOutputIsBasedOn: CapacityOutputIsBasedOn = copy.CapacityOutputIsBasedOn; break;
|
||||
case Fields.SensitivityUnits: SensitivityUnits = copy.SensitivityUnits; break;
|
||||
case Fields.ZeroPoint: ZeroPoint = copy.ZeroPoint; break;
|
||||
default:
|
||||
throw new NotSupportedException("unknown calibrationrecord field: " + field.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
public CalibrationRecord()
|
||||
{
|
||||
Poly = new LinearizationFormula();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
namespace DatabaseExport
|
||||
{
|
||||
/// <summary>
|
||||
/// Digital Inputs allow collected data to behave consistently with a digital data source
|
||||
/// the settings are for configuring firmware appropriately and for transforming data for consumption
|
||||
/// </summary>
|
||||
public class DigitalInputSetting : SensorData
|
||||
{
|
||||
/// <summary>
|
||||
/// constructor and copy constructor
|
||||
/// </summary>
|
||||
public DigitalInputSetting() : base()
|
||||
{
|
||||
SetDefaults(this);
|
||||
}
|
||||
public DigitalInputSetting(DigitalInputSetting copy)
|
||||
: base(copy)
|
||||
{
|
||||
SetDefaults(this);
|
||||
}
|
||||
public static void SetDefaults(SensorData sd)
|
||||
{
|
||||
sd.AxisNumber = 0;
|
||||
sd.NumberOfAxes = 1;
|
||||
sd.Capacity = 2400;
|
||||
sd.Bridge = Test.Module.Channel.Sensor.BridgeType.DigitalInput;
|
||||
sd.Capacity = 1;
|
||||
sd.DisplayUnit = "V";
|
||||
sd.BridgeResistance = double.NaN;
|
||||
sd.CheckOffset = false;
|
||||
sd.Manufacturer = "Generic";
|
||||
sd.OffsetToleranceHigh = 2500;
|
||||
sd.OffsetToleranceLow = 2500;
|
||||
sd.Model = "Digital Input Setting";
|
||||
sd.Shunt = ShuntMode.None;
|
||||
sd.MeasureExcitation = false;
|
||||
sd.MeasureNoise = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace DatabaseExport
|
||||
{
|
||||
public class DigitalOutputSetting : SensorData
|
||||
{
|
||||
public string ChannelDescription
|
||||
{
|
||||
get => SerialNumber;
|
||||
set
|
||||
{
|
||||
SerialNumber = value;
|
||||
OnPropertyChanged("ChannelDescription");
|
||||
}
|
||||
}
|
||||
|
||||
// public DigitalOutputSetting(DigitalOutputSetting copy) : base(copy)
|
||||
// {
|
||||
// SetDefaults(this);
|
||||
// }
|
||||
|
||||
public DigitalOutputSetting()
|
||||
{
|
||||
SetDefaults(this);
|
||||
}
|
||||
|
||||
public static void SetDefaults(SensorData sd)
|
||||
{
|
||||
sd.SupportedExcitation = new Test.Module.Channel.Sensor.ExcitationVoltageOption[]
|
||||
{Test.Module.Channel.Sensor.ExcitationVoltageOption.Volt5};
|
||||
sd.Bridge = Test.Module.Channel.Sensor.BridgeType.TOMDigital;
|
||||
sd.AxisNumber = 0;
|
||||
sd.NumberOfAxes = 1;
|
||||
sd.Capacity = 1;
|
||||
sd.DisplayUnit = "V";
|
||||
sd.BridgeResistance = double.NaN;
|
||||
sd.CheckOffset = false;
|
||||
sd.Manufacturer = "Generic";
|
||||
sd.OffsetToleranceHigh = 2500;
|
||||
sd.OffsetToleranceLow = 2500;
|
||||
sd.Model = "Digital Output Setting";
|
||||
sd.Shunt = ShuntMode.None;
|
||||
sd.MeasureExcitation = false;
|
||||
sd.MeasureNoise = false;
|
||||
}
|
||||
|
||||
public DigitalOutputSetting(System.Data.DataRow dr)
|
||||
{
|
||||
Bridge = Test.Module.Channel.Sensor.BridgeType.TOMDigital;
|
||||
|
||||
var fields = Enum.GetValues(typeof(DbOperations.DigitalOutputSettings.Fields))
|
||||
.Cast<DbOperations.DigitalOutputSettings.Fields>().ToArray();
|
||||
|
||||
foreach (var field in fields)
|
||||
{
|
||||
try
|
||||
{
|
||||
var o = dr[field.ToString()];
|
||||
if (DBNull.Value.Equals(o))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
switch (field)
|
||||
{
|
||||
case DbOperations.DigitalOutputSettings.Fields.Version:
|
||||
Version = Convert.ToInt32(o);
|
||||
break;
|
||||
case DbOperations.DigitalOutputSettings.Fields.OutputMode:
|
||||
DigitalOutputMode = (OutputTOMDigitalChannel.DigitalOutputMode)Convert.ToInt16(o);
|
||||
break;
|
||||
case DbOperations.DigitalOutputSettings.Fields.LocalOnly:
|
||||
_localOnly = Convert.ToBoolean(o);
|
||||
break;
|
||||
case DbOperations.DigitalOutputSettings.Fields.LimitDuration:
|
||||
DigitalOutputLimitDuration = Convert.ToBoolean(o);
|
||||
break;
|
||||
case DbOperations.DigitalOutputSettings.Fields.LastModifiedBy:
|
||||
LastUpdatedBy = Convert.ToString(o);
|
||||
break;
|
||||
case DbOperations.DigitalOutputSettings.Fields.LastModified:
|
||||
LastModified = Convert.ToDateTime(o);
|
||||
break;
|
||||
case DbOperations.DigitalOutputSettings.Fields.DurationMS: //obsolete, but non-null, field
|
||||
//DigitalOutputDurationMS = Convert.ToDouble(o);
|
||||
break;
|
||||
case DbOperations.DigitalOutputSettings.Fields.DurationMSFloat:
|
||||
DigitalOutputDurationMS = Convert.ToDouble(o);
|
||||
break;
|
||||
case DbOperations.DigitalOutputSettings.Fields.DelayMS:
|
||||
DigitalOutputDelayMS = Convert.ToDouble(o);
|
||||
break;
|
||||
case DbOperations.DigitalOutputSettings.Fields.ChannelDescription:
|
||||
ChannelDescription = Convert.ToString(o);
|
||||
break;
|
||||
case DbOperations.DigitalOutputSettings.Fields.UserTags:
|
||||
TagsBlobBytes = (byte[])o;
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//DTS.Utilities.Logging.APILogger.Log("Failed to process: ", field.ToString(), ex);
|
||||
}
|
||||
}
|
||||
SetDefaults(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
|
||||
namespace DatabaseExport
|
||||
{
|
||||
public class FilterClass //: INotifyPropertyChanged
|
||||
{
|
||||
public enum FilterClassType
|
||||
{
|
||||
None = 0,
|
||||
AdHoc = -1,
|
||||
CFC10 = 17, // 17 Hz
|
||||
CFC60 = 100, // 100 Hz
|
||||
CFC180 = 300, // 300 Hz
|
||||
CFC600 = 1000, // 1000 Hz
|
||||
CFC1000 = 1650 // 1650 Hz
|
||||
}
|
||||
|
||||
public FilterClassType FClass { get; set; }
|
||||
|
||||
public double Frequency { get; set; }
|
||||
|
||||
public FilterClass(FilterClassType fc)
|
||||
{
|
||||
FClass = fc;
|
||||
switch (fc)
|
||||
{
|
||||
case FilterClassType.None:
|
||||
Frequency = 0;
|
||||
break;
|
||||
case FilterClassType.CFC10:
|
||||
Frequency = (double)FilterClassType.CFC10;
|
||||
break;
|
||||
case FilterClassType.CFC60:
|
||||
Frequency = (double)FilterClassType.CFC60;
|
||||
break;
|
||||
case FilterClassType.CFC180:
|
||||
Frequency = (double)FilterClassType.CFC180;
|
||||
break;
|
||||
case FilterClassType.CFC600:
|
||||
Frequency = (double)FilterClassType.CFC600;
|
||||
break;
|
||||
case FilterClassType.CFC1000:
|
||||
Frequency = (double)FilterClassType.CFC1000;
|
||||
break;
|
||||
default:
|
||||
throw new System.Exception("FilterClass: unknown class");
|
||||
}
|
||||
}
|
||||
public override string ToString()
|
||||
{
|
||||
switch (FClass)
|
||||
{
|
||||
case FilterClassType.None:
|
||||
return "None";
|
||||
case FilterClassType.CFC10:
|
||||
return string.Format("{0} (CFC10)", (int)FilterClassType.CFC10);
|
||||
case FilterClassType.CFC60:
|
||||
return string.Format("{0} (CFC60)", (int)FilterClassType.CFC60);
|
||||
case FilterClassType.CFC180:
|
||||
return string.Format("{0} (CFC180)", (int)FilterClassType.CFC180);
|
||||
case FilterClassType.CFC600:
|
||||
return string.Format("{0} (CFC600)", (int)FilterClassType.CFC600);
|
||||
case FilterClassType.CFC1000:
|
||||
return string.Format("{0} (CFC1000)", (int)FilterClassType.CFC1000);
|
||||
case FilterClassType.AdHoc:
|
||||
return ((int)Frequency).ToString();
|
||||
}
|
||||
throw new System.Exception("FilterClass.ToString: Invalid class=" + FClass.ToString());
|
||||
}
|
||||
|
||||
public FilterClass(string fclass)
|
||||
{
|
||||
int fc;
|
||||
if (int.TryParse(fclass, NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out fc))
|
||||
{
|
||||
switch (fc)
|
||||
{
|
||||
case 17:
|
||||
FClass = FilterClassType.CFC10;
|
||||
Frequency = (double)FClass;
|
||||
return;
|
||||
case 100:
|
||||
FClass = FilterClassType.CFC60;
|
||||
Frequency = (double)FClass;
|
||||
return;
|
||||
case 300:
|
||||
FClass = FilterClassType.CFC180;
|
||||
Frequency = (double)FClass;
|
||||
return;
|
||||
case 1000:
|
||||
FClass = FilterClassType.CFC600;
|
||||
Frequency = (double)FClass;
|
||||
return;
|
||||
case 1650:
|
||||
FClass = FilterClassType.CFC1000;
|
||||
Frequency = (double)FClass;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (string.IsNullOrEmpty(fclass) || fclass == "None")
|
||||
{
|
||||
FClass = FilterClassType.None;
|
||||
}
|
||||
else if (fclass.Contains("CFC1000"))
|
||||
{
|
||||
FClass = FilterClassType.CFC1000;
|
||||
Frequency = (double)FilterClassType.CFC1000;
|
||||
}
|
||||
else if (fclass.Contains("CFC10"))
|
||||
{
|
||||
FClass = FilterClassType.CFC10;
|
||||
Frequency = (double)FilterClassType.CFC10;
|
||||
}
|
||||
else if (fclass.Contains("CFC600"))
|
||||
{
|
||||
FClass = FilterClassType.CFC600;
|
||||
Frequency = (double)FilterClassType.CFC600;
|
||||
}
|
||||
else if (fclass.Contains("CFC60"))
|
||||
{
|
||||
FClass = FilterClassType.CFC60;
|
||||
Frequency = (double)FilterClassType.CFC60;
|
||||
}
|
||||
else if (fclass.Contains("CFC180"))
|
||||
{
|
||||
FClass = FilterClassType.CFC180;
|
||||
Frequency = (double)FilterClassType.CFC180;
|
||||
}
|
||||
else
|
||||
{
|
||||
FClass = FilterClassType.AdHoc;
|
||||
Frequency = Convert.ToDouble(fclass);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,330 @@
|
||||
using System.Text;
|
||||
|
||||
namespace DatabaseExport
|
||||
{
|
||||
public class IsoCode
|
||||
{
|
||||
private char[] _isoCodeFull = { '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0' };
|
||||
|
||||
private char _TestObject
|
||||
{
|
||||
get => _isoCodeFull[0];
|
||||
set => _isoCodeFull[0] = value;
|
||||
}
|
||||
|
||||
public string TestObject
|
||||
{
|
||||
get => new string(new[] { _TestObject });
|
||||
set
|
||||
{
|
||||
if (string.IsNullOrEmpty(value))
|
||||
{
|
||||
_TestObject = '?';
|
||||
}
|
||||
else
|
||||
{
|
||||
_TestObject = value[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private char _Position
|
||||
{
|
||||
get => _isoCodeFull[1];
|
||||
set => _isoCodeFull[1] = value;
|
||||
}
|
||||
|
||||
public string Position
|
||||
{
|
||||
get => new string(new[] { _Position });
|
||||
set
|
||||
{
|
||||
if (string.IsNullOrEmpty(value))
|
||||
{
|
||||
_Position = '?';
|
||||
}
|
||||
else
|
||||
{
|
||||
_Position = value[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private char[] _MainLocation
|
||||
{
|
||||
get => new[] { _isoCodeFull[2], _isoCodeFull[3], _isoCodeFull[4], _isoCodeFull[5] };
|
||||
set
|
||||
{
|
||||
for (var i = 0; i < 4; i++)
|
||||
{
|
||||
if (value.Length <= i)
|
||||
{
|
||||
_isoCodeFull[i + 2] = '0';
|
||||
}
|
||||
else
|
||||
{
|
||||
_isoCodeFull[i + 2] = value[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string MainLocation
|
||||
{
|
||||
get => new string(_MainLocation);
|
||||
set
|
||||
{
|
||||
var main = value;
|
||||
if (main.Length < 4)
|
||||
{
|
||||
main = main.PadRight(4, '?');
|
||||
}
|
||||
else if (main.Length > 4)
|
||||
{
|
||||
main = main.Substring(0, 4);
|
||||
}
|
||||
_MainLocation = main.ToCharArray(0, 4);
|
||||
}
|
||||
}
|
||||
|
||||
private char[] _FineLocation1
|
||||
{
|
||||
get => new[] { _isoCodeFull[6], _isoCodeFull[7] };
|
||||
set
|
||||
{
|
||||
for (var i = 0; i < 2; i++)
|
||||
{
|
||||
if (value.Length < i)
|
||||
{
|
||||
_isoCodeFull[i + 6] = '0';
|
||||
}
|
||||
else
|
||||
{
|
||||
_isoCodeFull[i + 6] = value[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string FineLocation1
|
||||
{
|
||||
get => new string(_FineLocation1);
|
||||
set
|
||||
{
|
||||
var loc = value;
|
||||
if (loc.Length < 2)
|
||||
{
|
||||
loc = loc.PadRight(2, '?');
|
||||
}
|
||||
else if (loc.Length > 2)
|
||||
{
|
||||
loc = loc.Substring(0, 2);
|
||||
}
|
||||
_FineLocation1 = loc.ToCharArray(0, 2);
|
||||
}
|
||||
}
|
||||
|
||||
private char[] _FineLocation2
|
||||
{
|
||||
get => new[] { _isoCodeFull[8], _isoCodeFull[9] };
|
||||
set
|
||||
{
|
||||
for (var i = 0; i < 2; i++)
|
||||
{
|
||||
if (value.Length < i)
|
||||
{
|
||||
_isoCodeFull[i + 8] = '0';
|
||||
}
|
||||
else
|
||||
{
|
||||
_isoCodeFull[i + 8] = value[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string FineLocation2
|
||||
{
|
||||
get => new string(_FineLocation2);
|
||||
set
|
||||
{
|
||||
var loc = value;
|
||||
if (loc.Length < 2)
|
||||
{
|
||||
loc = loc.PadRight(2, '?');
|
||||
}
|
||||
else if (loc.Length > 2)
|
||||
{
|
||||
loc = loc.Substring(0, 2);
|
||||
}
|
||||
_FineLocation2 = loc.ToCharArray(0, 2);
|
||||
}
|
||||
}
|
||||
|
||||
private char[] _FineLocations3
|
||||
{
|
||||
get => new[] { _isoCodeFull[10], _isoCodeFull[11] };
|
||||
set
|
||||
{
|
||||
for (var i = 0; i < 2; i++)
|
||||
{
|
||||
if (value.Length < i)
|
||||
{
|
||||
_isoCodeFull[i + 10] = '0';
|
||||
}
|
||||
else
|
||||
{
|
||||
_isoCodeFull[i + 10] = value[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string FineLocation3
|
||||
{
|
||||
get => new string(_FineLocations3);
|
||||
set
|
||||
{
|
||||
var loc = value;
|
||||
if (loc.Length < 2)
|
||||
{
|
||||
loc = loc.PadRight(2, '?');
|
||||
}
|
||||
else if (loc.Length > 2)
|
||||
{
|
||||
loc = loc.Substring(0, 2);
|
||||
}
|
||||
_FineLocations3 = loc.ToCharArray(0, 2);
|
||||
}
|
||||
}
|
||||
|
||||
private char[] _PhysicalDimension
|
||||
{
|
||||
get => new[] { _isoCodeFull[12], _isoCodeFull[13] };
|
||||
set
|
||||
{
|
||||
for (var i = 0; i < 2; i++)
|
||||
{
|
||||
if (value.Length < i)
|
||||
{
|
||||
_isoCodeFull[i + 12] = '0';
|
||||
}
|
||||
else
|
||||
{
|
||||
_isoCodeFull[i + 12] = value[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string PhysicalDimension
|
||||
{
|
||||
get => new string(_PhysicalDimension);
|
||||
set
|
||||
{
|
||||
var dim = value;
|
||||
if (dim.Length < 2)
|
||||
{
|
||||
dim = dim.PadRight(2, '?');
|
||||
}
|
||||
else if (dim.Length > 2)
|
||||
{
|
||||
dim = dim.Substring(0, 2);
|
||||
}
|
||||
_PhysicalDimension = dim.ToCharArray(0, 2);
|
||||
}
|
||||
}
|
||||
|
||||
private char _Direction
|
||||
{
|
||||
get => _isoCodeFull[14];
|
||||
set => _isoCodeFull[14] = value;
|
||||
}
|
||||
|
||||
public string Direction
|
||||
{
|
||||
get => new string(new[] { _Direction });
|
||||
set
|
||||
{
|
||||
if (string.IsNullOrEmpty(value))
|
||||
{
|
||||
_Direction = '?';
|
||||
}
|
||||
else
|
||||
{
|
||||
_Direction = value[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private char _FilterClass
|
||||
{
|
||||
get => _isoCodeFull[15];
|
||||
set => _isoCodeFull[15] = value;
|
||||
}
|
||||
|
||||
public string FilterClass
|
||||
{
|
||||
get => new string(new[] { _FilterClass });
|
||||
set
|
||||
{
|
||||
if (string.IsNullOrEmpty(value))
|
||||
{
|
||||
_FilterClass = '?';
|
||||
}
|
||||
else
|
||||
{
|
||||
_FilterClass = value[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public IsoCode(string isoCode)
|
||||
{
|
||||
if (null == isoCode)
|
||||
{
|
||||
isoCode = "";
|
||||
}
|
||||
if (isoCode.Length > 16)
|
||||
{
|
||||
isoCode = isoCode.Substring(0, 16);
|
||||
}
|
||||
if (isoCode.Length < 16)
|
||||
{
|
||||
isoCode = isoCode.PadRight(16, '?');
|
||||
}
|
||||
for (var i = 0; i < 16; i++)
|
||||
{
|
||||
_isoCodeFull[i] = isoCode[i];
|
||||
}
|
||||
}
|
||||
|
||||
public string StringRepresentation
|
||||
{
|
||||
get
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
foreach (var c in _isoCodeFull)
|
||||
{
|
||||
sb.Append(c);
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
set
|
||||
{
|
||||
for (var i = 0; i < 16; i++)
|
||||
{
|
||||
if (i >= value.Length)
|
||||
{
|
||||
_isoCodeFull[i] = '0';
|
||||
}
|
||||
else
|
||||
{
|
||||
_isoCodeFull[i] = value[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,396 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
|
||||
namespace DatabaseExport
|
||||
{
|
||||
public class SensorCalibrationList
|
||||
{
|
||||
protected SensorCalibrationList()
|
||||
{
|
||||
_calibrations = new Dictionary<string, List<SensorCalibration>>();
|
||||
using (var cmd = DbOperations.GetCommand())
|
||||
{
|
||||
cmd.CommandText = string.Format("SELECT * FROM {0}", DbOperations.SensorDB.SensorCalibrationTable);
|
||||
using (var ds = DbOperations.Connection.QueryDataSet(cmd))
|
||||
{
|
||||
foreach (DataRow row in ds.Tables[0].Rows)
|
||||
{
|
||||
var sc = new SensorCalibration(row);
|
||||
if (!_calibrations.ContainsKey(sc.SerialNumber)) { _calibrations.Add(sc.SerialNumber, new List<SensorCalibration>()); }
|
||||
_calibrations[sc.SerialNumber].Add(sc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private Dictionary<string, List<SensorCalibration>> _calibrations = null;
|
||||
private static object _lock = new object();
|
||||
|
||||
private static SensorCalibrationList _calibrationList = null;
|
||||
public static SensorCalibration GetLatestCalibrationBySerialNumberAndExcitation(SensorData sd, Test.Module.Channel.Sensor.ExcitationVoltageOption exc)
|
||||
{
|
||||
if (null == sd) { return null; }
|
||||
if (sd.IsDigitalInput() || sd.IsSquib() || sd.IsDigitalOutput()) { return SensorCalibration.NewDigitalSC(); }
|
||||
lock (_lock)
|
||||
{
|
||||
if (null == _calibrationList)
|
||||
{
|
||||
_calibrationList = new SensorCalibrationList();
|
||||
}
|
||||
if (!_calibrationList._calibrations.ContainsKey(sd.SerialNumber) || _calibrationList._calibrations[sd.SerialNumber].Count <= 0) return null;
|
||||
try
|
||||
{
|
||||
var list = _calibrationList._calibrations[sd.SerialNumber];
|
||||
list.Sort();
|
||||
foreach (var sc in list)
|
||||
{
|
||||
if (!sc.IsProportional) { return new SensorCalibration(sc); }
|
||||
if (Array.Exists(sc.Records.Records, record => record.Excitation == exc))
|
||||
{
|
||||
return new SensorCalibration(sc);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception) { /*Utilities.Logging.APILogger.Log(ex);*/ }
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
public static SensorCalibration[] GetCalibrationsBySerialNumber(SensorData sd)
|
||||
{
|
||||
if (null == sd) { return new SensorCalibration[0]; }
|
||||
if (sd.IsDigitalInput() || sd.IsSquib() || sd.IsDigitalOutput()) { return new SensorCalibration[] { SensorCalibration.NewDigitalSC() }; }
|
||||
|
||||
lock (_lock)
|
||||
{
|
||||
if (null == _calibrationList)
|
||||
{
|
||||
_calibrationList = new SensorCalibrationList();
|
||||
}
|
||||
if (!_calibrationList._calibrations.ContainsKey(sd.SerialNumber)) return new SensorCalibration[0];
|
||||
var list = new List<SensorCalibration>(_calibrationList._calibrations[sd.SerialNumber].Count);
|
||||
list.AddRange(_calibrationList._calibrations[sd.SerialNumber].Select(sc => new SensorCalibration(sc)));
|
||||
return list.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
public class SensorCalibration //: IComparable<SensorCalibration>, INotifyPropertyChanged
|
||||
{
|
||||
public InitialOffset InitialOffset { get; set; } = new InitialOffset();
|
||||
private bool _nonLinear = false;
|
||||
public bool NonLinear
|
||||
{
|
||||
get => _nonLinear;
|
||||
set
|
||||
{
|
||||
_nonLinear = value;
|
||||
if (value)
|
||||
{
|
||||
Records.Records[0].Sensitivity = 1D;
|
||||
IsProportional = false;
|
||||
RemoveOffset = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
public static SensorCalibration NewDigitalSC()
|
||||
{
|
||||
var sc = new SensorCalibration
|
||||
{
|
||||
RemoveOffset = false,
|
||||
CalibrationDate = DateTime.Now.Date,
|
||||
IsProportional = false,
|
||||
LocalOnly = false,
|
||||
NonLinear = false
|
||||
};
|
||||
sc.Records.Records[0].Sensitivity = 1;
|
||||
sc.Records.Records[0].EngineeringUnits = "V";
|
||||
sc.Records.Records[0].Excitation = Test.Module.Channel.Sensor.ExcitationVoltageOption.Volt5;
|
||||
sc.ZeroMethod = new ZeroMethod(Test.Module.Channel.Sensor.ZeroMethodType.None, 0, 0);
|
||||
return sc;
|
||||
}
|
||||
public static SensorCalibration GetLatestCalibrationBySerialNumberAndExcitation(SensorData sd, Test.Module.Channel.Sensor.ExcitationVoltageOption exc)
|
||||
{
|
||||
return SensorCalibrationList.GetLatestCalibrationBySerialNumberAndExcitation(sd, exc);
|
||||
}
|
||||
public string SerialNumber { get; set; } = "";
|
||||
|
||||
// these two are the keys
|
||||
public DateTime CalibrationDate { get; set; }
|
||||
|
||||
private string _username = "";
|
||||
public string Username
|
||||
{
|
||||
get => _username ?? string.Empty;
|
||||
set => _username = value;
|
||||
}
|
||||
private CalibrationRecords _records = new CalibrationRecords();
|
||||
public CalibrationRecords Records
|
||||
{
|
||||
get => _records;
|
||||
set => _records = value;
|
||||
}
|
||||
|
||||
public DateTime ModifyDate { get; set; }
|
||||
|
||||
private bool _isProportional = true;
|
||||
public bool IsProportional
|
||||
{
|
||||
get => !NonLinear && _isProportional;
|
||||
set => _isProportional = value;
|
||||
}
|
||||
|
||||
private bool _bRemoveOffset = true;
|
||||
public bool RemoveOffset
|
||||
{
|
||||
get => !NonLinear && _bRemoveOffset;
|
||||
set => _bRemoveOffset = value;
|
||||
}
|
||||
|
||||
private List<string> _certificationDocuments = new List<string>();
|
||||
public string[] CertificationDocuments
|
||||
{
|
||||
get => _certificationDocuments.ToArray();
|
||||
set => _certificationDocuments = new List<string>(value);
|
||||
}
|
||||
|
||||
private ZeroMethod _zeroMethod = new ZeroMethod(Test.Module.Channel.Sensor.ZeroMethodType.UsePreEventDiagnosticsZero, -.05, -.02);
|
||||
public ZeroMethod ZeroMethod
|
||||
{
|
||||
get
|
||||
{
|
||||
try
|
||||
{
|
||||
if (NonLinear)
|
||||
{
|
||||
switch (Records.Records[0].Poly.Style)
|
||||
{
|
||||
case LinearizationFormula.Styles.IRTraccAverageOverTime: _zeroMethod.Method = Test.Module.Channel.Sensor.ZeroMethodType.AverageOverTime; break;
|
||||
case LinearizationFormula.Styles.IRTraccDiagnosticsZero: _zeroMethod.Method = Test.Module.Channel.Sensor.ZeroMethodType.UsePreEventDiagnosticsZero; break;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
/*Utilities.Logging.APILogger.Log(ex);*/
|
||||
}
|
||||
return _zeroMethod;
|
||||
}
|
||||
set => _zeroMethod = value;
|
||||
}
|
||||
|
||||
private bool _bLocalOnly = false;
|
||||
public bool LocalOnly
|
||||
{
|
||||
get => _bLocalOnly;
|
||||
set => _bLocalOnly = value;
|
||||
}
|
||||
// #endregion
|
||||
|
||||
// protected const int CurrentVersion = 1;
|
||||
|
||||
public SensorCalibration()
|
||||
{
|
||||
if (NonLinear)
|
||||
{
|
||||
Records.Records[0].Sensitivity = 1D;
|
||||
IsProportional = false;
|
||||
RemoveOffset = false;
|
||||
}
|
||||
}
|
||||
public SensorCalibration(string s)
|
||||
{
|
||||
FromSerializedString(s);
|
||||
if (NonLinear)
|
||||
{
|
||||
Records.Records[0].Sensitivity = 1D;
|
||||
IsProportional = false;
|
||||
RemoveOffset = false;
|
||||
}
|
||||
}
|
||||
public SensorCalibration(DataRow dr)
|
||||
{
|
||||
var fields = Enum.GetValues(typeof(DbOperations.SensorDB.SensorCalibrationFields)).Cast<DbOperations.SensorDB.SensorCalibrationFields>().ToArray();
|
||||
foreach (var field in fields)
|
||||
{
|
||||
var o = dr[field.ToString()];
|
||||
if (DBNull.Value.Equals(o)) { continue; }
|
||||
try
|
||||
{
|
||||
switch (field)
|
||||
{
|
||||
case DbOperations.SensorDB.SensorCalibrationFields.CalibrationDate:
|
||||
CalibrationDate = Convert.ToDateTime(o);
|
||||
break;
|
||||
case DbOperations.SensorDB.SensorCalibrationFields.LocalOnly:
|
||||
LocalOnly = Convert.ToBoolean(o);
|
||||
break;
|
||||
case DbOperations.SensorDB.SensorCalibrationFields.SerialNumber:
|
||||
SerialNumber = (string)o;
|
||||
break;
|
||||
case DbOperations.SensorDB.SensorCalibrationFields.Username:
|
||||
Username = (string)o;
|
||||
break;
|
||||
case DbOperations.SensorDB.SensorCalibrationFields.CalibrationRecords:
|
||||
Records = new CalibrationRecords((string)o);
|
||||
break;
|
||||
//case Storage.DbOperations.SensorDB.SensorCalibrationFields.IRTraccCalculationType:
|
||||
//IRTraccCalculationType = (SensorModel.IRTraccFormats)Enum.Parse(typeof(SensorModel.IRTraccFormats), (string)o);
|
||||
// break;
|
||||
case DbOperations.SensorDB.SensorCalibrationFields.IsProportional:
|
||||
IsProportional = Convert.ToBoolean(o);
|
||||
break;
|
||||
case DbOperations.SensorDB.SensorCalibrationFields.ModifyDate:
|
||||
ModifyDate = Convert.ToDateTime(o);
|
||||
break;
|
||||
case DbOperations.SensorDB.SensorCalibrationFields.NonLinear:
|
||||
NonLinear = Convert.ToBoolean(o);
|
||||
break;
|
||||
case DbOperations.SensorDB.SensorCalibrationFields.CertificationDocuments:
|
||||
{
|
||||
CertificationDocuments = ((string)o).Split(new string[] { System.Globalization.CultureInfo.InvariantCulture.TextInfo.ListSeparator }, StringSplitOptions.None).ToArray();
|
||||
}
|
||||
break;
|
||||
case DbOperations.SensorDB.SensorCalibrationFields.RemoveOffset:
|
||||
RemoveOffset = Convert.ToBoolean(o);
|
||||
break;
|
||||
case DbOperations.SensorDB.SensorCalibrationFields.ZeroMethod:
|
||||
ZeroMethod = new ZeroMethod((string)o);
|
||||
break;
|
||||
case DbOperations.SensorDB.SensorCalibrationFields.InitialOffset:
|
||||
InitialOffset = new InitialOffset(); InitialOffset.FromDbSerializeString((string)o);
|
||||
break;
|
||||
default: throw new NotSupportedException("SensorCalibration::SensorCalibration(DataRow) unknown field: " + field.ToString());
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//Utilities.Logging.APILogger.Log("Failed to process field: ", field.ToString(), " from db: ", ex);
|
||||
}
|
||||
}
|
||||
//this is downright silly, but because the linearization formula marks itself valid when it deserializes with data in it, we go and correct it here.
|
||||
Records.Records[0].Poly.MarkValid(NonLinear);
|
||||
|
||||
if (NonLinear)
|
||||
{
|
||||
Records.Records[0].Sensitivity = 1D;
|
||||
IsProportional = false;
|
||||
RemoveOffset = false;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// serializes to a string
|
||||
/// primarily used by sensor models, which only have one calibration entry
|
||||
/// sensors on the other hand have many and serialize to rows in a db table
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string ToSerializedString()
|
||||
{
|
||||
var fields = Enum.GetValues(typeof(DbOperations.SensorDB.SensorCalibrationFields)).Cast<DbOperations.SensorDB.SensorCalibrationFields>().ToArray();
|
||||
|
||||
if (CalibrationDate.Year < 1960) { CalibrationDate = DateTime.Now.Date; }
|
||||
var substrings = new List<string>();
|
||||
foreach (var field in fields)
|
||||
{
|
||||
switch (field)
|
||||
{
|
||||
case DbOperations.SensorDB.SensorCalibrationFields.CalibrationDate: substrings.Add(CalibrationDate.Date.ToFileTimeUtc().ToString(System.Globalization.CultureInfo.InvariantCulture)); break;
|
||||
case DbOperations.SensorDB.SensorCalibrationFields.CalibrationRecords: substrings.Add(Records.ToSerializedString(this)); break;
|
||||
//case Storage.DbOperations.SensorDB.SensorCalibrationFields.IRTraccCalculationType: substrings.Add(IRTraccCalculationType.ToString()); break;
|
||||
case DbOperations.SensorDB.SensorCalibrationFields.IsProportional: substrings.Add(IsProportional.ToString()); break;
|
||||
case DbOperations.SensorDB.SensorCalibrationFields.LocalOnly: substrings.Add(LocalOnly.ToString()); break;
|
||||
case DbOperations.SensorDB.SensorCalibrationFields.ModifyDate: substrings.Add(DateTime.Now.ToFileTimeUtc().ToString(System.Globalization.CultureInfo.InvariantCulture)); break;
|
||||
case DbOperations.SensorDB.SensorCalibrationFields.NonLinear: substrings.Add(NonLinear.ToString()); break;
|
||||
case DbOperations.SensorDB.SensorCalibrationFields.RemoveOffset: substrings.Add(RemoveOffset.ToString()); break;
|
||||
case DbOperations.SensorDB.SensorCalibrationFields.SerialNumber: substrings.Add(SerialNumber); break;
|
||||
case DbOperations.SensorDB.SensorCalibrationFields.Username: substrings.Add(Username); break;
|
||||
case DbOperations.SensorDB.SensorCalibrationFields.ZeroMethod: substrings.Add(ZeroMethod.ToSerializeString()); break;
|
||||
case DbOperations.SensorDB.SensorCalibrationFields.InitialOffset: substrings.Add(InitialOffset.ToDbSerializeString()); break;
|
||||
case DbOperations.SensorDB.SensorCalibrationFields.CertificationDocuments:
|
||||
{
|
||||
var docs = new List<string>();
|
||||
foreach (var d in CertificationDocuments) { docs.Add(d); }
|
||||
substrings.Add(string.Join(System.Globalization.CultureInfo.InvariantCulture.TextInfo.ListSeparator, docs.ToArray()));
|
||||
}
|
||||
break;
|
||||
default: throw new NotSupportedException("SensorCalibration::ToSerializedString unknown field: " + field.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
for (var i = 0; i < substrings.Count; i++)
|
||||
{
|
||||
System.Diagnostics.Trace.Assert(!substrings[i].Contains(SEPARATOR_REPLACEMENT));
|
||||
substrings[i] = substrings[i].Replace(System.Globalization.CultureInfo.InvariantCulture.TextInfo.ListSeparator, SEPARATOR_REPLACEMENT);
|
||||
}
|
||||
return string.Join(System.Globalization.CultureInfo.InvariantCulture.TextInfo.ListSeparator, substrings.ToArray());
|
||||
}
|
||||
public void FromSerializedString(string s)
|
||||
{
|
||||
var fields = Enum.GetValues(typeof(DbOperations.SensorDB.SensorCalibrationFields))
|
||||
.Cast<DbOperations.SensorDB.SensorCalibrationFields>().ToArray();
|
||||
var tokens = s.Split(new string[] { System.Globalization.CultureInfo.InvariantCulture.TextInfo.ListSeparator }, StringSplitOptions.None);
|
||||
|
||||
for (var i = 0; i < tokens.Length && i < fields.Length; i++)
|
||||
{
|
||||
var field = fields[i];
|
||||
var token = tokens[i].Replace(SEPARATOR_REPLACEMENT, System.Globalization.CultureInfo.InvariantCulture.TextInfo.ListSeparator);
|
||||
switch (field)
|
||||
{
|
||||
case DbOperations.SensorDB.SensorCalibrationFields.CalibrationDate: CalibrationDate = DateTime.FromFileTimeUtc(Convert.ToInt64(token)); break;
|
||||
case DbOperations.SensorDB.SensorCalibrationFields.CalibrationRecords: Records = new CalibrationRecords(token); break;
|
||||
//case Storage.DbOperations.SensorDB.SensorCalibrationFields.IRTraccCalculationType: IRTraccCalculationType = (SensorModel.IRTraccFormats)Enum.Parse(typeof(SensorModel.IRTraccFormats), token);break;
|
||||
case DbOperations.SensorDB.SensorCalibrationFields.IsProportional: IsProportional = Convert.ToBoolean(token); break;
|
||||
case DbOperations.SensorDB.SensorCalibrationFields.LocalOnly: LocalOnly = Convert.ToBoolean(token); break;
|
||||
case DbOperations.SensorDB.SensorCalibrationFields.ModifyDate: ModifyDate = DateTime.FromFileTimeUtc(Convert.ToInt64(token)); break;
|
||||
case DbOperations.SensorDB.SensorCalibrationFields.NonLinear: NonLinear = Convert.ToBoolean(token); break;
|
||||
case DbOperations.SensorDB.SensorCalibrationFields.RemoveOffset: RemoveOffset = Convert.ToBoolean(token); break;
|
||||
case DbOperations.SensorDB.SensorCalibrationFields.SerialNumber: SerialNumber = token; break;
|
||||
case DbOperations.SensorDB.SensorCalibrationFields.Username: Username = token; break;
|
||||
case DbOperations.SensorDB.SensorCalibrationFields.ZeroMethod: ZeroMethod = new ZeroMethod(token); break;
|
||||
case DbOperations.SensorDB.SensorCalibrationFields.InitialOffset: InitialOffset = new InitialOffset(); InitialOffset.FromDbSerializeString(token); break;
|
||||
case DbOperations.SensorDB.SensorCalibrationFields.CertificationDocuments:
|
||||
{
|
||||
var subtokens = token.Split(new string[] { System.Globalization.CultureInfo.InvariantCulture.TextInfo.ListSeparator }, StringSplitOptions.None);
|
||||
var docs = subtokens.ToList();
|
||||
}
|
||||
break;
|
||||
default: throw new NotSupportedException("SensorCalibration::FromSerializedString unknown field: " + field.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
public const string SEPARATOR_REPLACEMENT = "__SC__";
|
||||
public SensorCalibration(SensorCalibration sc)
|
||||
{
|
||||
SerialNumber = sc.SerialNumber;
|
||||
_username = sc.Username;
|
||||
CalibrationDate = sc.CalibrationDate;
|
||||
ModifyDate = sc.ModifyDate;
|
||||
NonLinear = sc.NonLinear;
|
||||
IsProportional = sc.IsProportional;
|
||||
Records = new CalibrationRecords(sc.Records);
|
||||
RemoveOffset = sc.RemoveOffset;
|
||||
ZeroMethod = new ZeroMethod(sc.ZeroMethod);
|
||||
InitialOffset = new InitialOffset(sc.InitialOffset);
|
||||
CertificationDocuments = sc.CertificationDocuments;
|
||||
}
|
||||
public Dictionary<string, string> GetValues()
|
||||
{
|
||||
var elementNameValuePairs = new Dictionary<string, string>();
|
||||
|
||||
elementNameValuePairs[DbOperations.SensorDB.SensorCalibrationFields.SerialNumber.ToString()] = SerialNumber;
|
||||
elementNameValuePairs[DbOperations.SensorDB.SensorCalibrationFields.CalibrationDate.ToString()] = CalibrationDate.ToString(System.Globalization.CultureInfo.InvariantCulture);
|
||||
elementNameValuePairs[DbOperations.SensorDB.SensorCalibrationFields.Username.ToString()] = Username;
|
||||
elementNameValuePairs[DbOperations.SensorDB.SensorCalibrationFields.LocalOnly.ToString()] = LocalOnly.ToString();
|
||||
elementNameValuePairs[DbOperations.SensorDB.SensorCalibrationFields.NonLinear.ToString()] = NonLinear.ToString();
|
||||
elementNameValuePairs[DbOperations.SensorDB.SensorCalibrationFields.CalibrationRecords.ToString()] = Records.ToSerializedString(this);
|
||||
elementNameValuePairs[DbOperations.SensorDB.SensorCalibrationFields.ModifyDate.ToString()] = ModifyDate.ToString(System.Globalization.CultureInfo.InvariantCulture);
|
||||
elementNameValuePairs[DbOperations.SensorDB.SensorCalibrationFields.IsProportional.ToString()] = IsProportional.ToString();
|
||||
elementNameValuePairs[DbOperations.SensorDB.SensorCalibrationFields.RemoveOffset.ToString()] = RemoveOffset.ToString();
|
||||
elementNameValuePairs[DbOperations.SensorDB.SensorCalibrationFields.ZeroMethod.ToString()] = ZeroMethod.ToDbString();
|
||||
elementNameValuePairs[DbOperations.SensorDB.SensorCalibrationFields.CertificationDocuments.ToString()] = "";
|
||||
elementNameValuePairs[DbOperations.SensorDB.SensorCalibrationFields.InitialOffset.ToString()] = InitialOffset.ToDbSerializeString();
|
||||
|
||||
return elementNameValuePairs;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
namespace DatabaseExport
|
||||
{
|
||||
public enum SensorStatus
|
||||
{
|
||||
Available,
|
||||
InUse,
|
||||
OutForService,
|
||||
OutForCalibration,
|
||||
Retired
|
||||
}
|
||||
|
||||
public enum ShuntMode
|
||||
{
|
||||
None,
|
||||
Emulation,
|
||||
Internal,
|
||||
External
|
||||
}
|
||||
|
||||
public enum BridgeLeg
|
||||
{
|
||||
First,
|
||||
Second,
|
||||
Third,
|
||||
Fourth
|
||||
}
|
||||
|
||||
public enum CouplingModes
|
||||
{
|
||||
AC = 0,
|
||||
DC
|
||||
}
|
||||
|
||||
public class LowHigh //: INotifyPropertyChanged
|
||||
{
|
||||
public double Low { get; set; }
|
||||
|
||||
public double High { get; set; }
|
||||
public LowHigh(double _low, double _high)
|
||||
{
|
||||
Low = _low;
|
||||
High = _high;
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,541 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace DatabaseExport
|
||||
{
|
||||
public abstract class SensorBase : TagAwareBase
|
||||
{
|
||||
public int CompareTo(SensorModel rhs)
|
||||
{
|
||||
if (null == Model) { Model = ""; }
|
||||
if (null == rhs.Model) { rhs.Model = ""; }
|
||||
return Model.CompareTo(rhs.Model);
|
||||
}
|
||||
|
||||
public virtual bool IsDigitalInput() { return Bridge == Test.Module.Channel.Sensor.BridgeType.DigitalInput; }
|
||||
|
||||
public virtual bool IsDigitalOutput() { return Bridge == Test.Module.Channel.Sensor.BridgeType.TOMDigital; }
|
||||
public virtual bool IsSquib() { return Bridge == Test.Module.Channel.Sensor.BridgeType.SQUIB; }
|
||||
public bool CheckOffset { get; set; } = true;
|
||||
public bool MeasureNoise { get; set; } = true;
|
||||
|
||||
public bool MeasureExcitation { get; set; } = true;
|
||||
|
||||
protected bool _invert = false;
|
||||
public bool Invert
|
||||
{
|
||||
get => _invert;
|
||||
set => _invert = value;
|
||||
}
|
||||
|
||||
public string Model { get; set; } = "";
|
||||
|
||||
public string Manufacturer { get; set; } = "";
|
||||
|
||||
protected string _UserPartNumber = "";
|
||||
public string UserPartNumber
|
||||
{
|
||||
get => _UserPartNumber;
|
||||
set => _UserPartNumber = value;
|
||||
}
|
||||
|
||||
public double Capacity { get; set; } = 2400D;
|
||||
public CouplingModes CouplingMode { get; set; } = CouplingModes.AC;
|
||||
|
||||
protected LowHigh _OffsetTolerance = new LowHigh(-100D, 100D);
|
||||
public double OffsetToleranceLow
|
||||
{
|
||||
get => _OffsetTolerance.Low;
|
||||
set => _OffsetTolerance.Low = value;
|
||||
}
|
||||
public double OffsetToleranceHigh
|
||||
{
|
||||
get => _OffsetTolerance.High;
|
||||
set => _OffsetTolerance.High = value;
|
||||
}
|
||||
|
||||
protected string _DisplayUnit = "";
|
||||
public virtual string DisplayUnit
|
||||
{
|
||||
get => _DisplayUnit;
|
||||
set => SetProperty(ref _DisplayUnit, value, SensorBaseFields.MeasurementUnit.ToString());
|
||||
}
|
||||
protected SensorRange _Range = new SensorRange(10D, 100D, 1000D);
|
||||
public double RangeLow
|
||||
{
|
||||
get => 0 == _Range.Low ? Capacity : _Range.Low;
|
||||
set => _Range.Low = value;
|
||||
}
|
||||
public double RangeMedium
|
||||
{
|
||||
get => 0 == _Range.Medium ? Capacity : _Range.Medium;
|
||||
set => _Range.Medium = value;
|
||||
}
|
||||
public double RangeHigh
|
||||
{
|
||||
get => 0 == _Range.High ? Capacity : _Range.High;
|
||||
set => _Range.High = value;
|
||||
}
|
||||
|
||||
protected List<Test.Module.Channel.Sensor.ExcitationVoltageOption> _supportedExcitation = new List<Test.Module.Channel.Sensor.ExcitationVoltageOption>(
|
||||
new[] { Test.Module.Channel.Sensor.ExcitationVoltageOption.Volt5 });
|
||||
public Test.Module.Channel.Sensor.ExcitationVoltageOption[] SupportedExcitation
|
||||
{
|
||||
get => _supportedExcitation.ToArray();
|
||||
set => _supportedExcitation = new List<Test.Module.Channel.Sensor.ExcitationVoltageOption>(value);
|
||||
}
|
||||
//sensor models shouldn't have a cal date, but this is the min cal date we can use and not cause problems unintentionally somewhere else
|
||||
protected SensorCalibration _calibration = new SensorCalibration();
|
||||
public virtual SensorCalibration Calibration
|
||||
{
|
||||
get => _calibration;
|
||||
set => _calibration = value;
|
||||
}
|
||||
|
||||
public Test.Module.Channel.Sensor.BridgeType Bridge { get; set; } = Test.Module.Channel.Sensor.BridgeType.FullBridge;
|
||||
|
||||
public ShuntMode Shunt { get; set; } = ShuntMode.Emulation;
|
||||
|
||||
public double BridgeResistance { get; set; } = 350D;
|
||||
|
||||
protected FilterClass _Filter = new FilterClass(FilterClass.FilterClassType.CFC1000);
|
||||
public FilterClass Filter
|
||||
{
|
||||
get => _Filter;
|
||||
set => _Filter = value;
|
||||
}
|
||||
public bool UniPolar { get; set; } = false;
|
||||
|
||||
public bool IgnoreRange { get; set; } = false;
|
||||
|
||||
protected string _lastUpdatedBy;
|
||||
public string LastUpdatedBy
|
||||
{
|
||||
get => _lastUpdatedBy;
|
||||
set => SetProperty(ref _lastUpdatedBy, value, "LastUpdatedBy");
|
||||
}
|
||||
|
||||
public int Version { get; set; } = 1;
|
||||
|
||||
protected bool _localOnly = false;
|
||||
public bool LocalOnly => _localOnly;
|
||||
public void SetLocalOnly(bool bLocalOnly) { _localOnly = bLocalOnly; }
|
||||
|
||||
public short AxisNumber { get; set; } = 0;
|
||||
|
||||
public short NumberOfAxes { get; set; } = 1;
|
||||
|
||||
public int CalInterval { get; set; } = 365;
|
||||
public string Polarity
|
||||
{
|
||||
get => _invert ? "-" : "+";
|
||||
set => Invert = value == "-";
|
||||
}
|
||||
|
||||
public DateTime LastModified { get; set; } = (DateTime)System.Data.SqlTypes.SqlDateTime.MinValue;
|
||||
|
||||
protected IsoCode _isoCode = new IsoCode("");
|
||||
public string ISOCode
|
||||
{
|
||||
get => _isoCode.StringRepresentation;
|
||||
set => _isoCode = new IsoCode(value);
|
||||
}
|
||||
|
||||
public string PhysicalDimension
|
||||
{
|
||||
get => _isoCode.PhysicalDimension;
|
||||
set => _isoCode.PhysicalDimension = value;
|
||||
}
|
||||
|
||||
public string Direction
|
||||
{
|
||||
get => _isoCode.Direction;
|
||||
set => _isoCode.Direction = value;
|
||||
}
|
||||
|
||||
|
||||
public bool DoNotUse { get; set; } = false;
|
||||
|
||||
public bool Broken { get; set; } = false;
|
||||
|
||||
|
||||
public enum SensorBaseFields
|
||||
{
|
||||
CheckOffset,
|
||||
Invert,
|
||||
Model,
|
||||
Manufacturer,
|
||||
UserPartNumber,
|
||||
Capacity,
|
||||
CouplingMode,
|
||||
OffsetToleranceLow,
|
||||
OffsetToleranceHigh,
|
||||
MeasurementUnit,
|
||||
RangeLow,
|
||||
RangeMedium,
|
||||
RangeHigh,
|
||||
SupportedExcitation,
|
||||
Calibration,
|
||||
Bridge,
|
||||
Shunt,
|
||||
BridgeResistance,
|
||||
Filter,
|
||||
UniPolar,
|
||||
IgnoreRange,
|
||||
LastUpdatedBy,
|
||||
Version,
|
||||
LocalOnly,
|
||||
AxisNumber,
|
||||
NumberOfAxes,
|
||||
CalInterval,
|
||||
Polarity,
|
||||
LastModified,
|
||||
ISOCode,
|
||||
PhysicalDimension,
|
||||
Direction,
|
||||
Broken,
|
||||
DoNotUse
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// modifies an isocode's Filter Class based on a sensor's Filter if the isocode's Filter Class is "?"
|
||||
/// FB 8037 - sensor's default filter not displayed after SIF import
|
||||
/// </summary>
|
||||
/// <param name="importingIsoCode">the starting ISO code which may or may not already have a filter</param>
|
||||
/// <param name="sensorFilterClass">the sensor's filter class to be used if the channel doesn't already have one</param>
|
||||
/// <returns>a string representation of the ISO code with a non-'?' Filter Class if the sensor's Filter is one of the ISO values</returns>
|
||||
public string BuildIsoCodeFromFilter(string importingIsoCode, FilterClass.FilterClassType sensorFilterClass)
|
||||
{
|
||||
var isoCodeWithFilter = new IsoCode(importingIsoCode);
|
||||
if (isoCodeWithFilter.FilterClass == "?")
|
||||
{
|
||||
isoCodeWithFilter.FilterClass = FClassToIsoFilterCode(sensorFilterClass);
|
||||
};
|
||||
return isoCodeWithFilter.StringRepresentation;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// returns the ISO Code for a Filter Class
|
||||
/// </summary>
|
||||
private string FClassToIsoFilterCode(FilterClass.FilterClassType fClass)
|
||||
{
|
||||
var isoFilterCode = "?";
|
||||
|
||||
switch (fClass)
|
||||
{
|
||||
case FilterClass.FilterClassType.CFC1000:
|
||||
isoFilterCode = "A";
|
||||
break;
|
||||
case FilterClass.FilterClassType.CFC600:
|
||||
isoFilterCode = "B";
|
||||
break;
|
||||
case FilterClass.FilterClassType.CFC180:
|
||||
isoFilterCode = "C";
|
||||
break;
|
||||
case FilterClass.FilterClassType.CFC60:
|
||||
isoFilterCode = "D";
|
||||
break;
|
||||
case FilterClass.FilterClassType.None:
|
||||
isoFilterCode = "P";
|
||||
break;
|
||||
//FB 13120 add AdHoc
|
||||
case FilterClass.FilterClassType.AdHoc:
|
||||
isoFilterCode = "S";
|
||||
break;
|
||||
case FilterClass.FilterClassType.CFC10:
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException("fClass", fClass, null);
|
||||
}
|
||||
return isoFilterCode;
|
||||
}
|
||||
|
||||
}
|
||||
public class SensorModel : SensorBase, IComparable<SensorModel>
|
||||
{
|
||||
public override string LookupTable => DbOperations.SensorDB.SensorModelsTable;
|
||||
|
||||
public override ConstraintHelper[] GetConstraints()
|
||||
{
|
||||
return new ConstraintHelper[]
|
||||
{
|
||||
new ConstraintHelper()
|
||||
{
|
||||
ColumnName = DbOperations.SensorDB.SensorModelFields.Model.ToString(),
|
||||
DbType = System.Data.SqlDbType.NVarChar,
|
||||
DbValue = Model
|
||||
},
|
||||
new ConstraintHelper()
|
||||
{
|
||||
ColumnName = DbOperations.SensorDB.SensorModelFields.Manufacturer.ToString(),
|
||||
DbType = System.Data.SqlDbType.NVarChar,
|
||||
DbValue = Manufacturer
|
||||
}
|
||||
};
|
||||
}
|
||||
public Dictionary<string, string> GetValues()
|
||||
{
|
||||
var elementNameValuePairs =
|
||||
new Dictionary<string, string>
|
||||
{
|
||||
[DbOperations.SensorDB.SensorModelFields.Model.ToString()] = Model,
|
||||
[DbOperations.SensorDB.SensorModelFields.Manufacturer.ToString()] = Manufacturer,
|
||||
[DbOperations.SensorDB.SensorModelFields.UserPartNumber.ToString()] = UserPartNumber,
|
||||
[DbOperations.SensorDB.SensorModelFields.Capacity.ToString()] = Capacity.ToString(System.Globalization.CultureInfo.InvariantCulture),
|
||||
[DbOperations.SensorDB.SensorModelFields.OffsetToleranceLow.ToString()] = OffsetToleranceLow.ToString(System.Globalization.CultureInfo.InvariantCulture),
|
||||
[DbOperations.SensorDB.SensorModelFields.OffsetToleranceHigh.ToString()] = OffsetToleranceHigh.ToString(System.Globalization.CultureInfo.InvariantCulture),
|
||||
[DbOperations.SensorDB.SensorModelFields.MeasurementUnit.ToString()] = DisplayUnit,
|
||||
[DbOperations.SensorDB.SensorModelFields.Bridge.ToString()] = Bridge.ToString(),
|
||||
[DbOperations.SensorDB.SensorModelFields.Shunt.ToString()] = Shunt.ToString(),
|
||||
[DbOperations.SensorDB.SensorModelFields.BridgeResistance.ToString()] = BridgeResistance.ToString(System.Globalization.CultureInfo.InvariantCulture),
|
||||
[DbOperations.SensorDB.SensorModelFields.FilterClass.ToString()] = Filter.ToString(),
|
||||
[DbOperations.SensorDB.SensorModelFields.UniPolar.ToString()] = UniPolar.ToString(),
|
||||
[DbOperations.SensorDB.SensorModelFields.IgnoreRange.ToString()] = IgnoreRange.ToString(),
|
||||
[DbOperations.SensorDB.SensorModelFields.CouplingMode.ToString()] = CouplingMode.ToString(),
|
||||
[DbOperations.SensorDB.SensorModelFields.Version.ToString()] = Version.ToString(System.Globalization.CultureInfo.InvariantCulture),
|
||||
[DbOperations.SensorDB.SensorModelFields.RangeLow.ToString()] = RangeLow.ToString(System.Globalization.CultureInfo.InvariantCulture),
|
||||
[DbOperations.SensorDB.SensorModelFields.RangeAve.ToString()] = RangeMedium.ToString(System.Globalization.CultureInfo.InvariantCulture),
|
||||
[DbOperations.SensorDB.SensorModelFields.RangeHigh.ToString()] = RangeHigh.ToString(System.Globalization.CultureInfo.InvariantCulture),
|
||||
[DbOperations.SensorDB.SensorModelFields.LastModified.ToString()] = LastModified.ToString(System.Globalization.CultureInfo.InvariantCulture),
|
||||
[DbOperations.SensorDB.SensorModelFields.ModifiedBy.ToString()] = LastUpdatedBy,
|
||||
[DbOperations.SensorDB.SensorModelFields.LocalOnly.ToString()] = LocalOnly.ToString(),
|
||||
[DbOperations.SensorDB.SensorModelFields.NumberOfAxes.ToString()] = NumberOfAxes.ToString(System.Globalization.CultureInfo.InvariantCulture),
|
||||
[DbOperations.SensorDB.SensorModelFields.CalInterval.ToString()] = CalInterval.ToString(System.Globalization.CultureInfo.InvariantCulture),
|
||||
[DbOperations.SensorDB.SensorModelFields.AxisNumber.ToString()] = AxisNumber.ToString(System.Globalization.CultureInfo.InvariantCulture),
|
||||
[DbOperations.SensorDB.SensorModelFields.Polarity.ToString()] = Polarity,
|
||||
[DbOperations.SensorDB.SensorModelFields.Invert.ToString()] = Invert.ToString(),
|
||||
[DbOperations.SensorDB.SensorModelFields.CheckOffset.ToString()] = CheckOffset.ToString(),
|
||||
[DbOperations.SensorDB.SensorModelFields.CalibrationRecord.ToString()] = Calibration.ToSerializedString(),
|
||||
[DbOperations.SensorDB.SensorModelFields.ISOCode.ToString()] = ISOCode
|
||||
};
|
||||
|
||||
elementNameValuePairs[DbOperations.SensorDB.SensorModelFields.SupportedExcitation.ToString()] = string.Join(System.Globalization.CultureInfo.InvariantCulture.TextInfo.ListSeparator, SupportedExcitation.Select(se => se.ToString()).ToArray());
|
||||
|
||||
return elementNameValuePairs;
|
||||
}
|
||||
private Test.Module.Channel.Sensor.BridgeType ConvertToBridge(int bridge)
|
||||
{
|
||||
switch (bridge)
|
||||
{
|
||||
case 0: return Test.Module.Channel.Sensor.BridgeType.IEPE;
|
||||
case 3: return Test.Module.Channel.Sensor.BridgeType.FullBridge;
|
||||
case 2: return Test.Module.Channel.Sensor.BridgeType.HalfBridge;
|
||||
case 1: return Test.Module.Channel.Sensor.BridgeType.QuarterBridge;
|
||||
default: return Test.Module.Channel.Sensor.BridgeType.FullBridge;
|
||||
}
|
||||
}
|
||||
|
||||
internal SensorModel(System.Data.DataRow dr)
|
||||
{
|
||||
var fields = Enum.GetValues(typeof(DbOperations.SensorDB.SensorModelFields))
|
||||
.Cast<DbOperations.SensorDB.SensorModelFields>().ToArray();
|
||||
foreach (var field in fields)
|
||||
{
|
||||
try
|
||||
{
|
||||
switch (field)
|
||||
{
|
||||
case DbOperations.SensorDB.SensorModelFields.Polarity:
|
||||
Polarity = (string)dr[field.ToString()];
|
||||
break;
|
||||
case DbOperations.SensorDB.SensorModelFields.AxisNumber:
|
||||
AxisNumber = Convert.ToInt16(dr[field.ToString()]);
|
||||
break;
|
||||
case DbOperations.SensorDB.SensorModelFields.Bridge:
|
||||
Bridge = ConvertToBridge(Convert.ToInt32(dr[field.ToString()]));
|
||||
//Bridge = (Test.Module.Channel.Sensor.BridgeType)Convert.ToInt32(dr[field.ToString()]);
|
||||
break;
|
||||
case DbOperations.SensorDB.SensorModelFields.BridgeResistance:
|
||||
BridgeResistance = Convert.ToDouble(dr[field.ToString()]);
|
||||
break;
|
||||
case DbOperations.SensorDB.SensorModelFields.CalInterval:
|
||||
CalInterval = Convert.ToInt32(dr[field.ToString()]);
|
||||
break;
|
||||
case DbOperations.SensorDB.SensorModelFields.Capacity:
|
||||
Capacity = Convert.ToDouble(dr[field.ToString()]);
|
||||
break;
|
||||
case DbOperations.SensorDB.SensorModelFields.CouplingMode:
|
||||
CouplingMode = (CouplingModes)Convert.ToInt32(dr[field.ToString()]);
|
||||
break;
|
||||
case DbOperations.SensorDB.SensorModelFields.FilterClass:
|
||||
Filter = new FilterClass((string)dr[field.ToString()]);
|
||||
break;
|
||||
case DbOperations.SensorDB.SensorModelFields.IgnoreRange:
|
||||
IgnoreRange = Convert.ToBoolean(dr[field.ToString()]);
|
||||
break;
|
||||
/*case Storage.DbOperations.SensorDB.SensorModelFields.InitialEU:
|
||||
InitialEU = Convert.ToDouble(dr[field.ToString()]);
|
||||
break;*/
|
||||
case DbOperations.SensorDB.SensorModelFields.CheckOffset:
|
||||
CheckOffset = Convert.ToBoolean(dr[field.ToString()]);
|
||||
break;
|
||||
case DbOperations.SensorDB.SensorModelFields.Invert:
|
||||
Invert = Convert.ToBoolean(dr[field.ToString()]);
|
||||
break;
|
||||
case DbOperations.SensorDB.SensorModelFields.LastModified:
|
||||
LastModified = (DateTime)dr[field.ToString()];
|
||||
break;
|
||||
case DbOperations.SensorDB.SensorModelFields.LocalOnly:
|
||||
SetLocalOnly(Convert.ToBoolean(dr[field.ToString()]));
|
||||
break;
|
||||
case DbOperations.SensorDB.SensorModelFields.Manufacturer:
|
||||
Manufacturer = (string)dr[field.ToString()];
|
||||
break;
|
||||
case DbOperations.SensorDB.SensorModelFields.MeasurementUnit:
|
||||
DisplayUnit = (string)dr[field.ToString()];
|
||||
break;
|
||||
case DbOperations.SensorDB.SensorModelFields.Model:
|
||||
Model = (string)dr[field.ToString()];
|
||||
break;
|
||||
case DbOperations.SensorDB.SensorModelFields.ModifiedBy:
|
||||
LastUpdatedBy = (string)dr[field.ToString()];
|
||||
break;
|
||||
case DbOperations.SensorDB.SensorModelFields.NumberOfAxes:
|
||||
NumberOfAxes = Convert.ToInt16(dr[field.ToString()]);
|
||||
break;
|
||||
case DbOperations.SensorDB.SensorModelFields.OffsetToleranceHigh:
|
||||
OffsetToleranceHigh = Convert.ToDouble(dr[field.ToString()]);
|
||||
break;
|
||||
case DbOperations.SensorDB.SensorModelFields.OffsetToleranceLow:
|
||||
OffsetToleranceLow = Convert.ToDouble(dr[field.ToString()]);
|
||||
break;
|
||||
case DbOperations.SensorDB.SensorModelFields.RangeAve:
|
||||
RangeMedium = Convert.ToDouble(dr[field.ToString()]);
|
||||
break;
|
||||
case DbOperations.SensorDB.SensorModelFields.RangeHigh:
|
||||
RangeHigh = Convert.ToDouble(dr[field.ToString()]);
|
||||
break;
|
||||
case DbOperations.SensorDB.SensorModelFields.RangeLow:
|
||||
RangeLow = Convert.ToDouble(dr[field.ToString()]);
|
||||
break;
|
||||
case DbOperations.SensorDB.SensorModelFields.Shunt:
|
||||
Shunt = (ShuntMode)Convert.ToInt32(dr[field.ToString()]);
|
||||
break;
|
||||
case DbOperations.SensorDB.SensorModelFields.UniPolar:
|
||||
UniPolar = Convert.ToBoolean(dr[field.ToString()]);
|
||||
break;
|
||||
case DbOperations.SensorDB.SensorModelFields.UserPartNumber:
|
||||
UserPartNumber = (string)dr[field.ToString()];
|
||||
break;
|
||||
case DbOperations.SensorDB.SensorModelFields.Version:
|
||||
Version = Convert.ToInt32(dr[field.ToString()]);
|
||||
break;
|
||||
case DbOperations.SensorDB.SensorModelFields.ISOCode:
|
||||
ISOCode = (string)dr[field.ToString()];
|
||||
break;
|
||||
case DbOperations.SensorDB.SensorModelFields.CalibrationRecord:
|
||||
Calibration = new SensorCalibration((string)dr[field.ToString()]);
|
||||
break;
|
||||
case DbOperations.SensorDB.SensorModelFields.SupportedExcitation:
|
||||
{
|
||||
var options = new List<Test.Module.Channel.Sensor.ExcitationVoltageOption>();
|
||||
var tokens = ((string)dr[field.ToString()]).Split(new string[] { System.Globalization.CultureInfo.InvariantCulture.TextInfo.ListSeparator }, StringSplitOptions.None);
|
||||
foreach (var token in tokens)
|
||||
{
|
||||
if (Enum.TryParse(token, out Test.Module.Channel.Sensor.ExcitationVoltageOption option)) { options.Add(option); }
|
||||
}
|
||||
|
||||
SupportedExcitation = options.ToArray();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new NotSupportedException("Unknown field: " + field);
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//DTS.Utilities.Logging.APILogger.Log("Failed to process field: ", field, "exception: ", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public class SensorModelCollection //: INotifyPropertyChanged
|
||||
{
|
||||
private Dictionary<string, Dictionary<string, SensorModel>> _sensorModels = new Dictionary<string, Dictionary<string, SensorModel>>();
|
||||
private static void PopulateCollection()
|
||||
{
|
||||
if (null == _collection)
|
||||
{
|
||||
_collection = new SensorModelCollection();
|
||||
}
|
||||
else
|
||||
{
|
||||
_collection._sensorModels.Clear();
|
||||
}
|
||||
_collection.LoadAllSensorModels();
|
||||
}
|
||||
private static SensorModelCollection _collection = null;
|
||||
public static SensorModelCollection SensorModelList
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
if (null == _collection)
|
||||
{
|
||||
PopulateCollection();
|
||||
}
|
||||
return _collection;
|
||||
}
|
||||
}
|
||||
}
|
||||
private static object _lock = new object();
|
||||
public SensorModel[] SensorModels
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
var l = new List<SensorModel>();
|
||||
var e = _sensorModels.GetEnumerator();
|
||||
while (e.MoveNext())
|
||||
{
|
||||
var e2 = e.Current.Value.GetEnumerator();
|
||||
while (e2.MoveNext())
|
||||
{
|
||||
l.Add(e2.Current.Value);
|
||||
}
|
||||
}
|
||||
return l.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
protected void LoadAllSensorModels()
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var cmd = DbOperations.GetCommand())
|
||||
{
|
||||
cmd.CommandText = string.Format("SELECT * FROM [{0}]", DbOperations.SensorDB.SensorModelsTable);
|
||||
|
||||
using (var ds = DbOperations.Connection.QueryDataSet(cmd))
|
||||
{
|
||||
if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
|
||||
{
|
||||
foreach (System.Data.DataRow dr in ds.Tables[0].Rows)
|
||||
{
|
||||
try
|
||||
{
|
||||
var sm = new SensorModel(dr);
|
||||
if (!_sensorModels.ContainsKey(sm.Manufacturer)) { _sensorModels.Add(sm.Manufacturer, new Dictionary<string, SensorModel>()); }
|
||||
if (!_sensorModels[sm.Manufacturer].ContainsKey(sm.Model))
|
||||
{
|
||||
_sensorModels[sm.Manufacturer].Add(sm.Model, sm);
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//DTS.Utilities.Logging.APILogger.Log("Failed to process a row in the database: ", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//DTS.Utilities.Logging.APILogger.Log("Failed to retrieve sensor models, ", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
namespace DatabaseExport
|
||||
{
|
||||
public class SensorRange //: INotifyPropertyChanged
|
||||
{
|
||||
public double Low { get; set; }
|
||||
|
||||
public double Medium { get; set; }
|
||||
|
||||
public double High { get; set; }
|
||||
public SensorRange(double _low, double _medium, double _high)
|
||||
{
|
||||
Low = _low;
|
||||
Medium = _medium;
|
||||
High = _high;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,276 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace DatabaseExport
|
||||
{
|
||||
public class SensorsCollection //: INotifyPropertyChanged
|
||||
{
|
||||
private static object _lock = new object();
|
||||
private static SensorsCollection _sensorCollection = null;
|
||||
public static SensorsCollection SensorsList
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
return _sensorCollection ?? (_sensorCollection = new SensorsCollection());
|
||||
}
|
||||
}
|
||||
}
|
||||
private Dictionary<string, SensorData> _sensorDictionary;
|
||||
/// <summary>
|
||||
/// we keep two dictionaries for sensor ids
|
||||
/// 1) we want efficient look up for existing ids
|
||||
/// 2) we need to clean out the lookup. if someone commits an existing sensor that had an id with a different id or no id, we have to clean up
|
||||
/// </summary>
|
||||
private Dictionary<string, List<SensorData>> _sensorIDToSensors;
|
||||
private Dictionary<string, string> _serialNumberToStoredSensorId;
|
||||
public SensorsCollection()
|
||||
{
|
||||
LoadAllSensors();
|
||||
}
|
||||
private void LoadAllSensors()
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
_sensorDictionary = new Dictionary<string, SensorData>();
|
||||
_serialNumberToStoredSensorId = new Dictionary<string, string>();
|
||||
_sensorIDToSensors = new Dictionary<string, List<SensorData>>();
|
||||
try
|
||||
{
|
||||
using (var cmd = DbOperations.GetCommand())
|
||||
{
|
||||
//sp_GetSensors
|
||||
cmd.CommandText = @"SELECT [SerialNumber],[UserSerialNumber],[Model],[Manufacturer],[Status],[MeasurementUnit],[OffsetToleranceLow],[OffsetToleranceHigh],[Id],[Capacity],[Comment],[BridgeType],[BridgeLegMode],[Shunt],[Invert],[UserValue1],[UserValue2],[UserValue3],[FilterClass],[BridgeResistance],[IsoCode],[CheckOffset],[SupportedExcitation],[InitialEU],[CalInterval],[CalibrationSignal],[InternalShuntResistance],[ExternalShuntResistance],[UniPolar],[RangeLow],[RangeAve],[RangeHigh],[Created],[TimesUsed],[SensorCategory],[BypassFilter],[CouplingMode],[Version],[LastModified],[ModifiedBy],[LocalOnly],[AxisNumber],[NumberOfAxes],[DbTimeStamp],[UserTags],[DoNotUse],[Broken] FROM [tblSensors]";
|
||||
|
||||
using (var ds = DbOperations.Connection.QueryDataSet(cmd))
|
||||
{
|
||||
if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
|
||||
{
|
||||
foreach (System.Data.DataRow dr in ds.Tables[0].Rows)
|
||||
{
|
||||
try
|
||||
{
|
||||
var sd = new SensorData(dr);
|
||||
if (!_sensorDictionary.ContainsKey(sd.SerialNumber))
|
||||
{
|
||||
_sensorDictionary.Add(sd.SerialNumber, sd);
|
||||
if (string.IsNullOrEmpty(sd.Id)) continue;
|
||||
if (!_sensorIDToSensors.ContainsKey(sd.Id))
|
||||
{
|
||||
_sensorIDToSensors.Add(sd.Id, new List<SensorData>());
|
||||
}
|
||||
_sensorIDToSensors[sd.Id].Add(sd);
|
||||
_serialNumberToStoredSensorId[sd.SerialNumber] = sd.Id;
|
||||
}
|
||||
else
|
||||
{
|
||||
//well we are in effect ignoring previous ones here, so lets clean up
|
||||
//the sensor id association information ...
|
||||
if (_serialNumberToStoredSensorId.ContainsKey(sd.SerialNumber))
|
||||
{
|
||||
//its gots it so we've gots to clean up
|
||||
var oldId = _serialNumberToStoredSensorId[sd.SerialNumber];
|
||||
var list = _sensorIDToSensors[oldId];
|
||||
for (var i = list.Count - 1; i >= 0; i--)
|
||||
{
|
||||
if (list[i].SerialNumber == sd.SerialNumber)
|
||||
{
|
||||
list.RemoveAt(i);
|
||||
}
|
||||
}
|
||||
if (list.Count > 0) { _sensorIDToSensors[oldId] = list; }
|
||||
else { _sensorIDToSensors.Remove(oldId); }
|
||||
_serialNumberToStoredSensorId.Remove(sd.SerialNumber);
|
||||
}
|
||||
_sensorDictionary[sd.SerialNumber] = sd;
|
||||
|
||||
}
|
||||
}
|
||||
catch (Exception) { /*Utilities.Logging.APILogger.Log("Failed to load sensor: ", ex2);*/ }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception) { /*Utilities.Logging.APILogger.Log("Failed to load Sensors: ", ex); */}
|
||||
try
|
||||
{
|
||||
var settings = new List<DigitalInputSetting>();
|
||||
using (var cmd = DbOperations.GetCommand())
|
||||
{
|
||||
cmd.CommandText = @"SELECT * FROM tblDigitalInputSetting";
|
||||
|
||||
using (var ds = DbOperations.Connection.QueryDataSet(cmd))
|
||||
{
|
||||
var fields = Enum.GetValues(typeof(DbOperations.DigitalInputSettings.Fields)).Cast<DbOperations.DigitalInputSettings.Fields>().ToArray();
|
||||
|
||||
foreach (System.Data.DataRow dr in ds.Tables[0].Rows)
|
||||
{
|
||||
var s = new DigitalInputSetting();
|
||||
foreach (var field in fields)
|
||||
{
|
||||
try
|
||||
{
|
||||
var o = dr[field.ToString()];
|
||||
if (null == o || DBNull.Value.Equals(o)) { continue; }
|
||||
switch (field)
|
||||
{
|
||||
case DbOperations.DigitalInputSettings.Fields.LastModified: s.LastModified = Convert.ToDateTime(o); break;
|
||||
case DbOperations.DigitalInputSettings.Fields.LastModifiedBy: s.LastUpdatedBy = Convert.ToString(o); break;
|
||||
case DbOperations.DigitalInputSettings.Fields.ScaleMultiplier: s.ScaleMultiplier.FromDbSerializeString(Convert.ToString(o)); break;
|
||||
case DbOperations.DigitalInputSettings.Fields.SettingMode: s.InputMode = (DigitalInputScaleMultiplier.InputModes)Convert.ToInt32(o); break;
|
||||
case DbOperations.DigitalInputSettings.Fields.SettingName: s.SettingName = Convert.ToString(o); break;
|
||||
case DbOperations.DigitalInputSettings.Fields.SensorId: s.Id = Convert.ToString(o); break;
|
||||
case DbOperations.DigitalInputSettings.Fields.UserValue1:
|
||||
s.UserValue1 = Convert.ToString(o);
|
||||
s.Comment = s.UserValue1;
|
||||
break;
|
||||
case DbOperations.DigitalInputSettings.Fields.UserValue2:
|
||||
s.UserValue2 = Convert.ToString(o);
|
||||
break;
|
||||
case DbOperations.DigitalInputSettings.Fields.UserValue3:
|
||||
s.UserValue3 = Convert.ToString(o);
|
||||
break;
|
||||
case DbOperations.DigitalInputSettings.Fields.UserTags:
|
||||
s.TagsBlobBytes = (byte[])o;
|
||||
break;
|
||||
default: throw new NotSupportedException("DigitalInputSettingsList::DigitalInputSettingsList unsupported column: " + field.ToString());
|
||||
}
|
||||
}
|
||||
catch (Exception) {/* Utilities.Logging.APILogger.Log(ex); */}
|
||||
}
|
||||
settings.Add(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach (var s in settings)
|
||||
{
|
||||
if (_sensorDictionary.ContainsKey(s.SerialNumber))
|
||||
{
|
||||
//don't load it, just ignore the setting
|
||||
}
|
||||
else
|
||||
{
|
||||
_sensorDictionary[s.SerialNumber] = s;
|
||||
if (string.IsNullOrWhiteSpace(s.Id)) continue;
|
||||
if (!_sensorIDToSensors.ContainsKey(s.Id)) { _sensorIDToSensors.Add(s.Id, new List<SensorData>()); }
|
||||
_sensorIDToSensors[s.Id].Add(s);
|
||||
_serialNumberToStoredSensorId[s.SerialNumber] = s.Id;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception) {/* Utilities.Logging.APILogger.Log(ex);*/ }
|
||||
try
|
||||
{
|
||||
var settings = new List<SquibSetting>();
|
||||
using (var cmd = DbOperations.GetCommand())
|
||||
{
|
||||
cmd.CommandText = @"SELECT * FROM tblTOMSquibChannels";
|
||||
|
||||
using (var ds = DbOperations.Connection.QueryDataSet(cmd))
|
||||
{
|
||||
foreach (System.Data.DataRow dr in ds.Tables[0].Rows)
|
||||
{
|
||||
try { settings.Add(new SquibSetting(dr)); }
|
||||
catch (Exception) {/* Utilities.Logging.APILogger.Log(ex);*/ }
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach (var s in settings)
|
||||
{
|
||||
if (_sensorDictionary.ContainsKey(s.SerialNumber))
|
||||
{
|
||||
//serial number already exists as something else, ignore this one!
|
||||
}
|
||||
else
|
||||
{
|
||||
_sensorDictionary[s.SerialNumber] = s;
|
||||
if (!string.IsNullOrWhiteSpace(s.Id))
|
||||
{
|
||||
if (!_sensorIDToSensors.ContainsKey(s.Id))
|
||||
{
|
||||
_sensorIDToSensors.Add(s.Id, new List<SensorData>());
|
||||
}
|
||||
_sensorIDToSensors[s.Id].Add(s);
|
||||
_serialNumberToStoredSensorId[s.SerialNumber] = s.Id;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception) { /*Utilities.Logging.APILogger.Log(ex);*/ }
|
||||
try
|
||||
{
|
||||
var lDOS = new List<DigitalOutputSetting>();
|
||||
using (var cmd = DbOperations.GetCommand())
|
||||
{
|
||||
cmd.CommandText = @"SELECT * FROM tblTOMDigitalChannels";
|
||||
|
||||
using (var ds = DbOperations.Connection.QueryDataSet(cmd))
|
||||
{
|
||||
foreach (System.Data.DataRow dr in ds.Tables[0].Rows)
|
||||
{
|
||||
try { lDOS.Add(new DigitalOutputSetting(dr)); }
|
||||
catch (Exception) { /*Utilities.Logging.APILogger.Log(ex);*/ }
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach (var s in lDOS)
|
||||
{
|
||||
if (!_sensorDictionary.ContainsKey(s.SerialNumber))
|
||||
{
|
||||
_sensorDictionary[s.SerialNumber] = s;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception) { /*Utilities.Logging.APILogger.Log(ex);*/ }
|
||||
}
|
||||
}
|
||||
//TODO: fix broken
|
||||
public SensorData GetSensorBySerialNumber(string serialNumber, bool excludeBroken = true)
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
if (!_sensorDictionary.ContainsKey(serialNumber))
|
||||
{
|
||||
if (!SensorData.IsTestSpecificDigitalOutSN(serialNumber)) return null;
|
||||
var sd = new DigitalOutputSetting { SerialNumber = serialNumber };
|
||||
return sd;
|
||||
}
|
||||
else
|
||||
{
|
||||
var sd = _sensorDictionary[serialNumber];
|
||||
if (excludeBroken) { if (sd.Broken || sd.DoNotUse) { return null; } }
|
||||
if (sd.NumberOfAxes > 1 || sd.AxisNumber > 0) { return null; }
|
||||
//for now eliminate multiple axes sensors
|
||||
//per 6093 Disable 6-axis sensor capability
|
||||
// "Prefiltered > CFC 1000" (Unfiltered)
|
||||
if (sd.FilterClassIso == "?") { sd.FilterClassIso = "P"; }
|
||||
return sd;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return a list of all sensors, even those marked Broken or Do Not Use
|
||||
/// </summary>
|
||||
public SensorData[] AllSensorsDb
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
var l = new List<SensorData>(_sensorDictionary.Values.ToArray());
|
||||
//for now eliminate multiple axes sensors per 6093 Disable 6-axis sensor capability
|
||||
for (var i = l.Count - 1; i >= 0; i--)
|
||||
{
|
||||
if (l[i].NumberOfAxes > 1 || l[i].AxisNumber > 0) { l.RemoveAt(i); }
|
||||
}
|
||||
l.Sort();
|
||||
return l.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace DatabaseExport
|
||||
{
|
||||
public class SquibSetting : SensorData
|
||||
{
|
||||
public string SquibDescription
|
||||
{
|
||||
get => SerialNumber;
|
||||
set { SerialNumber = value; OnPropertyChanged("SquibDescription"); }
|
||||
}
|
||||
|
||||
private bool _bypassCurrentFilter = false;
|
||||
public bool BypassCurrentFilter
|
||||
{
|
||||
get => _bypassCurrentFilter;
|
||||
set => SetProperty(ref _bypassCurrentFilter, value, "BypassCurrentFilter");
|
||||
}
|
||||
|
||||
private bool _bypassVoltageFilter = false;
|
||||
public bool BypassVoltageFilter
|
||||
{
|
||||
get => _bypassVoltageFilter;
|
||||
set => SetProperty(ref _bypassVoltageFilter, value, "BypassVoltageFilter");
|
||||
}
|
||||
|
||||
public string ArticleId
|
||||
{
|
||||
get => Id;
|
||||
set { Id = value; OnPropertyChanged("ArticleId"); }
|
||||
}
|
||||
public static void SetDefaults(SensorData sd)
|
||||
{
|
||||
sd.AxisNumber = 0;
|
||||
sd.Capacity = 5;
|
||||
sd.NumberOfAxes = 1;
|
||||
sd.Manufacturer = "Generic";
|
||||
sd.Model = "Squib Setting";
|
||||
sd.Shunt = ShuntMode.None;
|
||||
sd.CheckOffset = false;
|
||||
sd.BridgeResistance = -1;
|
||||
sd.MeasureNoise = false;
|
||||
sd.MeasureExcitation = false;
|
||||
sd.Bridge = Test.Module.Channel.Sensor.BridgeType.SQUIB;
|
||||
sd.SupportedExcitation = new Test.Module.Channel.Sensor.ExcitationVoltageOption[] { Test.Module.Channel.Sensor.ExcitationVoltageOption.Volt5 };
|
||||
sd.DisplayUnit = "V";
|
||||
sd.Comment = string.IsNullOrWhiteSpace(sd.UserValue1) ? sd.SerialNumber : sd.UserValue1;
|
||||
}
|
||||
|
||||
public SquibSetting(System.Data.DataRow dr)
|
||||
{
|
||||
SetDefaults(this);
|
||||
var fields = Enum.GetValues(typeof(DbOperations.Squib.Fields)).Cast<DbOperations.Squib.Fields>()
|
||||
.ToArray();
|
||||
|
||||
foreach (var field in fields)
|
||||
{
|
||||
var o = dr[field.ToString()];
|
||||
if (DBNull.Value.Equals(o)) { continue; }
|
||||
try
|
||||
{
|
||||
switch (field)
|
||||
{
|
||||
case DbOperations.Squib.Fields.Version:
|
||||
Version = Convert.ToInt32(o);
|
||||
break;
|
||||
case DbOperations.Squib.Fields.SquibToleranceLow:
|
||||
SquibToleranceLow = Convert.ToDouble(o);
|
||||
break;
|
||||
case DbOperations.Squib.Fields.SquibToleranceHigh:
|
||||
SquibToleranceHigh = Convert.ToDouble(o);
|
||||
break;
|
||||
case DbOperations.Squib.Fields.SquibOutputCurrent:
|
||||
SquibOutputCurrent = Convert.ToDouble(o);
|
||||
break;
|
||||
case DbOperations.Squib.Fields.SquibDescription:
|
||||
SquibDescription = Convert.ToString(o);
|
||||
break;
|
||||
case DbOperations.Squib.Fields.MeasurementType:
|
||||
SquibMeasurementType = (OutputSquibChannel.SquibMeasurementType)Convert.ToInt16(o);
|
||||
break;
|
||||
case DbOperations.Squib.Fields.LocalOnly:
|
||||
_localOnly = Convert.ToBoolean(o);
|
||||
break;
|
||||
case DbOperations.Squib.Fields.LimitDuration:
|
||||
LimitSquibFireDuration = Convert.ToBoolean(o);
|
||||
break;
|
||||
case DbOperations.Squib.Fields.LastModifiedBy:
|
||||
_lastUpdatedBy = Convert.ToString(o);
|
||||
break;
|
||||
case DbOperations.Squib.Fields.LastModified:
|
||||
LastModified = Convert.ToDateTime(o);
|
||||
break;
|
||||
case DbOperations.Squib.Fields.ISOCode:
|
||||
ISOCode = Convert.ToString(o);
|
||||
break;
|
||||
case DbOperations.Squib.Fields.FireMode:
|
||||
SquibFireMode = (OutputSquibChannel.SquibFireMode)Convert.ToInt16(o);
|
||||
break;
|
||||
case DbOperations.Squib.Fields.DurationMS:
|
||||
SquibFireDurationMS = Convert.ToDouble(o);
|
||||
break;
|
||||
case DbOperations.Squib.Fields.DelayMS:
|
||||
SquibFireDelayMS = Convert.ToDouble(o);
|
||||
break;
|
||||
case DbOperations.Squib.Fields.BypassVoltageFilter:
|
||||
BypassVoltageFilter = Convert.ToBoolean(o);
|
||||
break;
|
||||
case DbOperations.Squib.Fields.BypassCurrentFilter:
|
||||
BypassCurrentFilter = Convert.ToBoolean(o);
|
||||
break;
|
||||
case DbOperations.Squib.Fields.ArticleId:
|
||||
ArticleId = Convert.ToString(o);
|
||||
break;
|
||||
case DbOperations.Squib.Fields.UserValue1:
|
||||
UserValue1 = Convert.ToString(o);
|
||||
Comment = UserValue1;
|
||||
break;
|
||||
case DbOperations.Squib.Fields.UserValue2:
|
||||
UserValue2 = Convert.ToString(o);
|
||||
break;
|
||||
case DbOperations.Squib.Fields.UserValue3:
|
||||
UserValue3 = Convert.ToString(o);
|
||||
break;
|
||||
case DbOperations.Squib.Fields.UserTags:
|
||||
TagsBlobBytes = (byte[])o;
|
||||
break;
|
||||
default:
|
||||
throw new NotSupportedException("Unknown field: " + field.ToString());
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//ignore
|
||||
}
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(Comment))
|
||||
{
|
||||
Comment = SerialNumber;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
|
||||
namespace DatabaseExport
|
||||
{
|
||||
public class ZeroMethod //: INotifyPropertyChanged
|
||||
{
|
||||
public Test.Module.Channel.Sensor.ZeroMethodType Method { get; set; }
|
||||
|
||||
public double Start { get; set; }
|
||||
|
||||
public double End { get; set; }
|
||||
|
||||
public ZeroMethod(Test.Module.Channel.Sensor.ZeroMethodType zm, double _start, double _end)
|
||||
{
|
||||
Method = zm;
|
||||
Start = _start;
|
||||
End = _end;
|
||||
}
|
||||
public ZeroMethod(string zm)
|
||||
{
|
||||
Initialize(zm, System.Globalization.CultureInfo.InvariantCulture);
|
||||
}
|
||||
/// <summary>
|
||||
/// do a deep copy
|
||||
/// </summary>
|
||||
/// <param name="copy"></param>
|
||||
public ZeroMethod(ZeroMethod copy)
|
||||
{
|
||||
Method = copy.Method;
|
||||
Start = copy.Start;
|
||||
End = copy.End;
|
||||
}
|
||||
private void Initialize(string zm, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
var tokens = zm.Split(',');
|
||||
if (tokens.Length < 3) { return; }
|
||||
Start = Convert.ToDouble(tokens[1], culture);
|
||||
End = Convert.ToDouble(tokens[2], culture);
|
||||
Method = (Test.Module.Channel.Sensor.ZeroMethodType)
|
||||
Enum.Parse(typeof(Test.Module.Channel.Sensor.ZeroMethodType), tokens[0]);
|
||||
}
|
||||
public string ToDbString()
|
||||
{
|
||||
return string.Format("{0},{1},{2}", Method.ToString(), Start, End);
|
||||
}
|
||||
public string ToSerializeString()
|
||||
{
|
||||
return string.Format("{0},{1},{2}",
|
||||
Method.ToString(),
|
||||
Start.ToString(System.Globalization.CultureInfo.InvariantCulture),
|
||||
End.ToString(System.Globalization.CultureInfo.InvariantCulture));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user