init
This commit is contained in:
@@ -0,0 +1,148 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace DatabaseImport
|
||||
{
|
||||
public class CalibrationRecords : ICalibrationRecords
|
||||
{
|
||||
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[] { new CalibrationRecord() };
|
||||
}
|
||||
public CalibrationRecords(string records)
|
||||
{
|
||||
FromSerializedString(records);
|
||||
}
|
||||
public void FromSerializedString(string s)
|
||||
{
|
||||
var tokens = s.Split(new[] { 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 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;
|
||||
|
||||
public string EngineeringUnits { get; set; } = "g";
|
||||
|
||||
|
||||
public Test.Module.Channel.Sensor.SensUnits SensitivityUnits { get; set; } = Test.Module.Channel.Sensor.SensUnits.NONE;
|
||||
|
||||
public ExcitationVoltageOptions.ExcitationVoltageOption Excitation { get; set; } = ExcitationVoltageOptions.ExcitationVoltageOption.Volt5;
|
||||
|
||||
public double CapacityOutputIsBasedOn { get; set; } = 1.000;
|
||||
|
||||
// private InitialOffset.Forms _initialOffsetMethod = InitialOffset.Forms.EU;
|
||||
// public InitialOffset.Forms InitialOffsetMethod { get { return _initialOffsetMethod; } set { _initialOffsetMethod = value; } }
|
||||
|
||||
private enum Fields
|
||||
{
|
||||
Sensitivity,
|
||||
Poly,
|
||||
AtCapacity,
|
||||
EngineeringUnits,
|
||||
Excitation,
|
||||
CapacityOutputIsBasedOn,
|
||||
SensitivityUnits,
|
||||
ZeroPoint
|
||||
};
|
||||
public void FromString(string s)
|
||||
{
|
||||
var tokens = s.Split(new[] { 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 = (ExcitationVoltageOptions.ExcitationVoltageOption)Enum.Parse(typeof(ExcitationVoltageOptions.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.ToDouble(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,55 @@
|
||||
using System;
|
||||
using System.Data;
|
||||
|
||||
namespace DatabaseImport
|
||||
{
|
||||
/// <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
|
||||
{
|
||||
public DigitalInputSetting(IDataRecord reader) : base()
|
||||
{
|
||||
SetDefaults(this);
|
||||
try
|
||||
{
|
||||
LastModified = Convert.ToDateTime(reader[DbOperations.DigitalInputSettings.Fields.LastModified.ToString()]);
|
||||
LastUpdatedBy = Convert.ToString(reader[DbOperations.DigitalInputSettings.Fields.LastModifiedBy.ToString()]);
|
||||
InputMode = (DigitalInputModes)Convert.ToInt32(reader[DbOperations.DigitalInputSettings.Fields.SettingMode.ToString()]);
|
||||
SettingName = Convert.ToString(reader[DbOperations.DigitalInputSettings.Fields.SettingName.ToString()]);
|
||||
Id = Convert.ToString(reader[DbOperations.DigitalInputSettings.Fields.eId.ToString()]);
|
||||
UserValue1 = Convert.ToString(reader[DbOperations.DigitalInputSettings.Fields.UserValue1.ToString()]);
|
||||
UserValue2 = Convert.ToString(reader[DbOperations.DigitalInputSettings.Fields.UserValue2.ToString()]);
|
||||
UserValue3 = Convert.ToString(reader[DbOperations.DigitalInputSettings.Fields.UserValue3.ToString()]);
|
||||
TagsBlobBytes = (byte[])reader[DbOperations.DigitalInputSettings.Fields.UserTags.ToString()];
|
||||
Comment = Convert.ToString(reader[DbOperations.DigitalInputSettings.Fields.UserValue1.ToString()]);
|
||||
ScaleMultiplier.FromDbSerializeString(Convert.ToString(reader[DbOperations.DigitalInputSettings.Fields.ScaleMultiplier.ToString()]));
|
||||
Broken = Convert.ToBoolean(reader[DbOperations.DigitalInputSettings.Fields.Broken.ToString()]);
|
||||
DoNotUse = Convert.ToBoolean(reader[DbOperations.DigitalInputSettings.Fields.DoNotUse.ToString()]);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//APILogger.Log("Failed to process: ", ex);
|
||||
}
|
||||
}
|
||||
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,75 @@
|
||||
using System;
|
||||
using System.Data;
|
||||
|
||||
namespace DatabaseImport
|
||||
{
|
||||
public class DigitalOutputSetting : SensorData
|
||||
{
|
||||
public string ChannelDescription
|
||||
{
|
||||
get => SerialNumber;
|
||||
set
|
||||
{
|
||||
SerialNumber = value;
|
||||
OnPropertyChanged("ChannelDescription");
|
||||
}
|
||||
}
|
||||
public DigitalOutputSetting()
|
||||
{
|
||||
SetDefaults(this);
|
||||
}
|
||||
public static void SetDefaults(SensorData sd)
|
||||
{
|
||||
sd.SupportedExcitation = new[] { ExcitationVoltageOptions.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(IDataRecord reader)
|
||||
{
|
||||
Bridge = Test.Module.Channel.Sensor.BridgeType.TOMDigital;
|
||||
|
||||
try
|
||||
{
|
||||
Version = Convert.ToInt32(reader[DbOperations.DigitalOutputSettings.Fields.Version.ToString()]);
|
||||
DigitalOutputMode =
|
||||
(DigitalOutputModes)Convert.ToInt16(
|
||||
reader[DbOperations.DigitalOutputSettings.Fields.OutputMode.ToString()]);
|
||||
_localOnly = Convert.ToBoolean(reader[DbOperations.DigitalOutputSettings.Fields.LocalOnly.ToString()]);
|
||||
DigitalOutputLimitDuration =
|
||||
Convert.ToBoolean(reader[DbOperations.DigitalOutputSettings.Fields.LimitDuration.ToString()]);
|
||||
LastUpdatedBy =
|
||||
Convert.ToString(reader[DbOperations.DigitalOutputSettings.Fields.LastModifiedBy.ToString()]);
|
||||
LastModified =
|
||||
Convert.ToDateTime(reader[DbOperations.DigitalOutputSettings.Fields.LastModified.ToString()]);
|
||||
DigitalOutputDurationMS =
|
||||
Convert.ToDouble(reader[DbOperations.DigitalOutputSettings.Fields.DurationMSFloat.ToString()]);
|
||||
DigitalOutputDelayMS =
|
||||
Convert.ToDouble(reader[DbOperations.DigitalOutputSettings.Fields.DelayMS.ToString()]);
|
||||
ChannelDescription = Convert.ToString(reader["SerialNumber"]);
|
||||
TagsBlobBytes = (byte[])reader[DbOperations.DigitalOutputSettings.Fields.UserTags.ToString()];
|
||||
Broken = Convert.ToBoolean(reader[DbOperations.DigitalOutputSettings.Fields.Broken.ToString()]);
|
||||
DoNotUse = Convert.ToBoolean(reader[DbOperations.DigitalOutputSettings.Fields.DoNotUse.ToString()]);
|
||||
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//APILogger.Log("Failed to process: ", ex);
|
||||
}
|
||||
|
||||
SetDefaults(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Xml.Linq;
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
|
||||
namespace DatabaseImport
|
||||
{
|
||||
public class FilterClass : INotifyPropertyChanged
|
||||
{
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
protected bool SetProperty<T>(ref T storage, T value, string propertyName = null)
|
||||
{
|
||||
if (Equals(storage, value)) return false;
|
||||
|
||||
storage = value;
|
||||
OnPropertyChanged(propertyName);
|
||||
return true;
|
||||
}
|
||||
protected void OnPropertyChanged(string propertyName = null)
|
||||
{
|
||||
var eventHandler = PropertyChanged;
|
||||
if (eventHandler != null)
|
||||
{
|
||||
eventHandler(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
}
|
||||
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 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 Exception("FilterClass.ToString: Invalid class=" + FClass.ToString());
|
||||
}
|
||||
|
||||
public FilterClass(string fclass)
|
||||
{
|
||||
int fc;
|
||||
if (int.TryParse(fclass, NumberStyles.Any, 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 DatabaseImport
|
||||
{
|
||||
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,268 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Data;
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
|
||||
namespace DatabaseImport
|
||||
{
|
||||
public class SensorCalibration : IComparable<SensorCalibration>, INotifyPropertyChanged, ISensorCalibration
|
||||
{
|
||||
public long CalVersion { get; set; } = long.MinValue;
|
||||
|
||||
public InitialOffset InitialOffset { get; set; } = new InitialOffset();
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
protected bool SetProperty<T>(ref T storage, T value, string propertyName = null)
|
||||
{
|
||||
if (Equals(storage, value)) return false;
|
||||
|
||||
storage = value;
|
||||
OnPropertyChanged(propertyName);
|
||||
return true;
|
||||
}
|
||||
protected void OnPropertyChanged(string propertyName = null)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
private bool _nonLinear;
|
||||
public bool NonLinear
|
||||
{
|
||||
get => _nonLinear;
|
||||
set
|
||||
{
|
||||
_nonLinear = value;
|
||||
if (!value) return;
|
||||
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 = ExcitationVoltageOptions.ExcitationVoltageOption.Volt5;
|
||||
sc.ZeroMethod = new ZeroMethod(ZeroMethodType.None, 0, 0);
|
||||
return sc;
|
||||
}
|
||||
public static SensorCalibration GetLatestCalibrationBySerialNumberAndExcitation(SensorData sd, ExcitationVoltageOptions.ExcitationVoltageOption exc)
|
||||
{
|
||||
return SensorCalibrationList.GetLatestCalibrationBySerialNumberAndExcitation(sd, exc);
|
||||
}
|
||||
private string _serialNumber = "";
|
||||
public string SerialNumber
|
||||
{
|
||||
get => _serialNumber;
|
||||
set => SetProperty(ref _serialNumber, value, "SerialNumber");
|
||||
}
|
||||
|
||||
private DateTime _calibrationDate; // these two are the keys
|
||||
public DateTime CalibrationDate
|
||||
{
|
||||
get => _calibrationDate;
|
||||
set => SetProperty(ref _calibrationDate, value, "CalibrationDate");
|
||||
}
|
||||
private string _username = "";
|
||||
public string Username
|
||||
{
|
||||
get => _username ?? string.Empty;
|
||||
set => SetProperty(ref _username, value, "Username");
|
||||
}
|
||||
private CalibrationRecords _records = new CalibrationRecords();
|
||||
public CalibrationRecords Records
|
||||
{
|
||||
get => _records;
|
||||
set => _records = value;
|
||||
}
|
||||
|
||||
private DateTime _modifyDate;
|
||||
public DateTime ModifyDate
|
||||
{
|
||||
get => _modifyDate;
|
||||
set => _modifyDate = value;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
public static int DefaultZeroMethod = 0;
|
||||
|
||||
private ZeroMethod _zeroMethod;
|
||||
public ZeroMethod ZeroMethod
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == _zeroMethod)
|
||||
{
|
||||
_zeroMethod = new ZeroMethod((ZeroMethodType)DefaultZeroMethod, -.05, -.02);
|
||||
}
|
||||
try
|
||||
{
|
||||
if (NonLinear)
|
||||
{
|
||||
switch (Records.Records[0].Poly.NonLinearStyle)
|
||||
{
|
||||
case NonLinearStyles.IRTraccAverageOverTime: _zeroMethod.Method = ZeroMethodType.AverageOverTime; break;
|
||||
case NonLinearStyles.IRTraccDiagnosticsZero: _zeroMethod.Method = ZeroMethodType.UsePreEventDiagnosticsZero; break;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception) { /*APILogger.Log(ex);*/ }
|
||||
return _zeroMethod;
|
||||
}
|
||||
set => _zeroMethod = value;
|
||||
}
|
||||
|
||||
public bool LocalOnly { get; set; }
|
||||
public SensorCalibration()
|
||||
{
|
||||
if (!NonLinear) return;
|
||||
Records.Records[0].Sensitivity = 1D;
|
||||
IsProportional = false;
|
||||
RemoveOffset = false;
|
||||
}
|
||||
public SensorCalibration(string s)
|
||||
{
|
||||
FromSerializedString(s);
|
||||
if (!NonLinear) return;
|
||||
Records.Records[0].Sensitivity = 1D;
|
||||
IsProportional = false;
|
||||
RemoveOffset = false;
|
||||
}
|
||||
public SensorCalibration(DataRow dr)
|
||||
{
|
||||
try
|
||||
{
|
||||
CalibrationDate = Convert.ToDateTime(dr[DbOperations.SensorDB.SensorCalibrationFields.CalibrationDate.ToString()]);
|
||||
LocalOnly = Convert.ToBoolean(dr[DbOperations.SensorDB.SensorCalibrationFields.LocalOnly.ToString()]);
|
||||
SerialNumber = (string)dr[DbOperations.SensorDB.SensorCalibrationFields.SerialNumber.ToString()];
|
||||
Username = (string)dr[DbOperations.SensorDB.SensorCalibrationFields.Username.ToString()];
|
||||
Records = new CalibrationRecords((string)dr[DbOperations.SensorDB.SensorCalibrationFields.CalibrationRecords.ToString()]);
|
||||
IsProportional = Convert.ToBoolean(dr[DbOperations.SensorDB.SensorCalibrationFields.IsProportional.ToString()]);
|
||||
ModifyDate = Convert.ToDateTime(dr[DbOperations.SensorDB.SensorCalibrationFields.ModifyDate.ToString()]);
|
||||
NonLinear = Convert.ToBoolean(dr[DbOperations.SensorDB.SensorCalibrationFields.NonLinear.ToString()]);
|
||||
CertificationDocuments = ((string)dr[DbOperations.SensorDB.SensorCalibrationFields.CertificationDocuments.ToString()]).Split(new[] { CultureInfo.InvariantCulture.TextInfo.ListSeparator }, StringSplitOptions.None).ToArray();
|
||||
RemoveOffset = Convert.ToBoolean(dr[DbOperations.SensorDB.SensorCalibrationFields.RemoveOffset.ToString()]);
|
||||
ZeroMethod = new ZeroMethod((string)dr[DbOperations.SensorDB.SensorCalibrationFields.ZeroMethod.ToString()]);
|
||||
InitialOffset = new InitialOffset(); InitialOffset.FromDbSerializeString((string)dr[DbOperations.SensorDB.SensorCalibrationFields.InitialOffset.ToString()]);
|
||||
|
||||
//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) return;
|
||||
Records.Records[0].Sensitivity = 1D;
|
||||
IsProportional = false;
|
||||
RemoveOffset = false;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//APILogger.Log("Failed to process Sensor Calibration record", ex);
|
||||
}
|
||||
}
|
||||
public void FromSerializedString(string s)
|
||||
{
|
||||
var fields = Enum.GetValues(typeof(DbOperations.SensorDB.SensorCalibrationFields)).Cast<DbOperations.SensorDB.SensorCalibrationFields>().ToArray();
|
||||
var tokens = s.Split(new[] { 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, 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 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: CertificationDocuments = token.Split(new[] { CultureInfo.InvariantCulture.TextInfo.ListSeparator }, StringSplitOptions.None); break;
|
||||
}
|
||||
}
|
||||
}
|
||||
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 int CompareTo(SensorCalibration other)
|
||||
{
|
||||
if (null == other) { return 1; }
|
||||
if (Equals(this, other)) { return 0; }
|
||||
if (CalibrationDate.Date != other.CalibrationDate.Date)
|
||||
return other.CalibrationDate.CompareTo(CalibrationDate);
|
||||
var modifyCompare = other.ModifyDate.CompareTo(ModifyDate);
|
||||
return 0 == modifyCompare ? other.CalVersion.CompareTo(CalVersion) : modifyCompare;
|
||||
}
|
||||
public void ReadXML(System.Xml.XmlElement root)
|
||||
{
|
||||
foreach (var node in root.ChildNodes)
|
||||
{
|
||||
if (node is System.Xml.XmlElement) { ProcessXmlElement(node as System.Xml.XmlElement); }
|
||||
}
|
||||
}
|
||||
private void ProcessXmlElement(System.Xml.XmlElement node)
|
||||
{
|
||||
if (!Enum.TryParse(node.Name, out DbOperations.SensorDB.SensorCalibrationFields field)) return;
|
||||
switch (field)
|
||||
{
|
||||
case DbOperations.SensorDB.SensorCalibrationFields.CalibrationDate: CalibrationDate = DateTime.Parse(node.InnerText, CultureInfo.InvariantCulture); break;
|
||||
case DbOperations.SensorDB.SensorCalibrationFields.CalibrationRecords: Records = new CalibrationRecords(node.InnerText); break;
|
||||
case DbOperations.SensorDB.SensorCalibrationFields.CertificationDocuments: CertificationDocuments = new string[0]; break;
|
||||
case DbOperations.SensorDB.SensorCalibrationFields.IsProportional: IsProportional = Convert.ToBoolean(node.InnerText); break;
|
||||
case DbOperations.SensorDB.SensorCalibrationFields.LocalOnly: LocalOnly = Convert.ToBoolean(node.InnerText); break;
|
||||
case DbOperations.SensorDB.SensorCalibrationFields.ModifyDate: ModifyDate = DateTime.Parse(node.InnerText, CultureInfo.InvariantCulture); break;
|
||||
case DbOperations.SensorDB.SensorCalibrationFields.NonLinear: NonLinear = Convert.ToBoolean(node.InnerText); break;
|
||||
case DbOperations.SensorDB.SensorCalibrationFields.RemoveOffset: RemoveOffset = Convert.ToBoolean(node.InnerText); break;
|
||||
case DbOperations.SensorDB.SensorCalibrationFields.SerialNumber: SerialNumber = node.InnerText; break;
|
||||
case DbOperations.SensorDB.SensorCalibrationFields.Username: Username = node.InnerText; break;
|
||||
case DbOperations.SensorDB.SensorCalibrationFields.ZeroMethod: ZeroMethod = new ZeroMethod(node.InnerText); break;
|
||||
case DbOperations.SensorDB.SensorCalibrationFields.InitialOffset: InitialOffset = new InitialOffset(); InitialOffset.FromDbSerializeString(node.InnerText); break;
|
||||
default: throw new NotSupportedException("SensorCalibration::ProcessXMLElement unsupported tag: " + field);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
|
||||
namespace DatabaseImport
|
||||
{
|
||||
public class SensorCalibrationList
|
||||
{
|
||||
private static List<SensorCalibration> _cachedCalibrations = null;
|
||||
protected SensorCalibrationList()
|
||||
{
|
||||
//removed code that appeared it would never work? (wrong parameters to sql sp)
|
||||
}
|
||||
private readonly Dictionary<string, List<SensorCalibration>> _calibrations;
|
||||
private static readonly object LOCK = new object();
|
||||
|
||||
private static SensorCalibrationList _calibrationList;
|
||||
public static void Reload()
|
||||
{
|
||||
lock (LOCK)
|
||||
{
|
||||
_calibrationList = new SensorCalibrationList();
|
||||
}
|
||||
}
|
||||
public static SensorCalibration GetLatestCalibrationBySerialNumberAndExcitation(SensorData sd, ExcitationVoltageOptions.ExcitationVoltageOption exc)
|
||||
{
|
||||
if (null == sd) { return null; }
|
||||
if (sd.IsDigitalInput() || sd.IsSquib() || sd.IsDigitalOutput()) { return SensorCalibration.NewDigitalSC(); }
|
||||
if (null != _cachedCalibrations)
|
||||
{
|
||||
var matches = from sc in _cachedCalibrations where sc.SerialNumber == sd.SerialNumber select sc;
|
||||
var sensorCalibrations = matches as SensorCalibration[] ?? matches.ToArray();
|
||||
if (sensorCalibrations.Any())
|
||||
{
|
||||
SensorCalibration cal = null;
|
||||
|
||||
foreach (var sc in sensorCalibrations)
|
||||
{
|
||||
if (sc.IsProportional)
|
||||
{
|
||||
var bOk = Array.Exists(sc.Records.Records, record => record.Excitation == exc);
|
||||
|
||||
if (!bOk) { continue; }
|
||||
}
|
||||
if (null == cal) { cal = sc; }
|
||||
else if (sc.CalibrationDate > cal.CalibrationDate) { cal = sc; }
|
||||
else if (sc.CalibrationDate == cal.CalibrationDate && sc.ModifyDate > cal.ModifyDate)
|
||||
{
|
||||
cal = sc;
|
||||
}
|
||||
}
|
||||
if (null != cal) { return cal; }
|
||||
}
|
||||
}
|
||||
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) {/* APILogger.Log(ex);*/ }
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
// /// <summary>
|
||||
// /// deletes all calibration data
|
||||
// /// originally created so TDM imports could clear all tables except DAS tables
|
||||
// /// </summary>
|
||||
public static void DeleteAll()
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var cmd = DbOperations.GetSQLCommand(true))
|
||||
{
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
cmd.CommandText = DbOperationsEnum.StoredProcedure.sp_SensorCalibrationsDelete.ToString();
|
||||
|
||||
#region params
|
||||
|
||||
cmd.Parameters.Add(new SqlParameter("@SensorSerialNumber", SqlDbType.Int) { Value = null });
|
||||
cmd.Parameters.Add(new SqlParameter("@CalibrationDate", SqlDbType.DateTime) { Value = null });
|
||||
cmd.Parameters.Add(new SqlParameter("@ModifiedDate", SqlDbType.DateTime) { Value = null });
|
||||
var errorNumberParam =
|
||||
new SqlParameter("@errorNumber", SqlDbType.Int) { Direction = ParameterDirection.Output };
|
||||
cmd.Parameters.Add(errorNumberParam);
|
||||
var errorMessageParam =
|
||||
new SqlParameter("@errorMessage", SqlDbType.NVarChar, 250)
|
||||
{
|
||||
Direction = ParameterDirection.Output
|
||||
};
|
||||
cmd.Parameters.Add(errorMessageParam);
|
||||
|
||||
#endregion params
|
||||
|
||||
cmd.ExecuteNonQuery();
|
||||
if (int.Parse(errorNumberParam.Value.ToString()) != 0)
|
||||
{
|
||||
//errorMessageParam.Value
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
cmd.Connection.Dispose();
|
||||
}
|
||||
}
|
||||
lock (LOCK)
|
||||
{
|
||||
if (null == _calibrationList)
|
||||
{
|
||||
_calibrationList = new SensorCalibrationList();
|
||||
}
|
||||
_calibrationList._calibrations.Clear();
|
||||
}
|
||||
}
|
||||
catch (Exception) {/* APILogger.Log("Failed to delete sensor calibrations ", ex); */}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace DatabaseImport
|
||||
{
|
||||
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 event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
protected bool SetProperty<T>(ref T storage, T value, string propertyName = null)
|
||||
{
|
||||
if (Equals(storage, value)) return false;
|
||||
|
||||
storage = value;
|
||||
OnPropertyChanged(propertyName);
|
||||
return true;
|
||||
}
|
||||
protected void OnPropertyChanged(string propertyName = null)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
|
||||
public double Low { get; set; }
|
||||
|
||||
public double High { get; set; }
|
||||
|
||||
public LowHigh(double low, double high)
|
||||
{
|
||||
Low = low;
|
||||
High = high;
|
||||
}
|
||||
public LowHigh(string value)
|
||||
{
|
||||
var values = value.Split(',');
|
||||
if (values.Length < 2) { throw new InvalidDataException("invalid low-high: " + value); }
|
||||
Low = double.Parse(values[0], System.Globalization.CultureInfo.InvariantCulture);
|
||||
High = double.Parse(values[1], System.Globalization.CultureInfo.InvariantCulture);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,669 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Data;
|
||||
|
||||
namespace DatabaseImport
|
||||
{
|
||||
public class SensorData : SensorBase, IComparable<SensorData>, ISensorData
|
||||
{
|
||||
/// <summary>
|
||||
/// 11260 Implement DiagnosticsMode in DataPRO
|
||||
/// DiagnosticsMode means the bridge in analog is short circuited to the outside world and only internal resistors are used
|
||||
/// </summary>
|
||||
public bool DiagnosticsMode { get; set; } = false;
|
||||
public const string TEST_SPECIFIC_DOUT = "TSD_";
|
||||
public static bool IsTestSpecificDigitalOutSN(string sn)
|
||||
{
|
||||
if (!sn.StartsWith(TEST_SPECIFIC_DOUT)) return false;
|
||||
var s = sn.Substring(4);
|
||||
return Guid.TryParse(s, out var notUsed);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// At one time all the different DelayMS were using one underlying property for storage, _delayMS.
|
||||
/// Now, the individual SquibFireDelayMS, etc. are defined because we don't want controls that are sharing to limit each other.
|
||||
/// </summary>
|
||||
public double DelayMS
|
||||
{
|
||||
get => _delayMS;
|
||||
set => _delayMS = value;
|
||||
}
|
||||
|
||||
public const double MINIMUM_DIGITALOUTPUT_DELAY_MS = 0D;
|
||||
public const double MAXIMUM_DIGITALOUTPUT_DELAY_MS = 99000D;
|
||||
|
||||
private double _digitalOutputDelayMS;
|
||||
public double DigitalOutputDelayMS
|
||||
{
|
||||
get => _digitalOutputDelayMS;
|
||||
set
|
||||
{
|
||||
var d = value;
|
||||
if (d < MINIMUM_DIGITALOUTPUT_DELAY_MS)
|
||||
{
|
||||
d = MINIMUM_DIGITALOUTPUT_DELAY_MS;
|
||||
}
|
||||
else if (d > MAXIMUM_DIGITALOUTPUT_DELAY_MS)
|
||||
{
|
||||
d = MAXIMUM_DIGITALOUTPUT_DELAY_MS;
|
||||
}
|
||||
SetProperty(ref _digitalOutputDelayMS, d, "DigitalOutputDelayMS");
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// At one time all the different DurationMS were using one underlying property for storage, _durationMS.
|
||||
/// Now, the individual SquibFireDurationMS, etc. are defined because we don't want controls that are sharing to limit each other.
|
||||
/// </summary>
|
||||
public double DurationMS
|
||||
{
|
||||
get => _durationMS;
|
||||
set => SetProperty(ref _durationMS, value, "DurationMS");
|
||||
}
|
||||
|
||||
private double _digitalOutputDurationMS = 10D;
|
||||
public double DigitalOutputDurationMS
|
||||
{
|
||||
get => _digitalOutputDurationMS;
|
||||
set => SetProperty(ref _digitalOutputDurationMS, value, "DigitalOutputDurationMS");
|
||||
}
|
||||
private DigitalOutputModes _digitalOutputMode = DigitalOutputModes.FVLH;
|
||||
|
||||
public DigitalOutputModes DigitalOutputMode
|
||||
{
|
||||
get => _digitalOutputMode;
|
||||
set => SetProperty(ref _digitalOutputMode, value, "DigitalOutputMode");
|
||||
}
|
||||
|
||||
public bool DigitalOutputLimitDuration
|
||||
{
|
||||
get => _limitDuration;
|
||||
set => SetProperty(ref _limitDuration, value, "LimitDuration");
|
||||
}
|
||||
|
||||
private double _delayMS;
|
||||
|
||||
public double SquibFireDelayMS
|
||||
{
|
||||
get => _delayMS;
|
||||
set => SetProperty(ref _delayMS, value, "SquibFireDelayMS");
|
||||
}
|
||||
|
||||
private double _durationMS = 10D;
|
||||
public double SquibFireDurationMS
|
||||
{
|
||||
get => _durationMS;
|
||||
set => SetProperty(ref _durationMS, value, "SquibFireDurationMS");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// right now all the Limit Duration mechanisms using the same underlying property for storage (_limitDuration), however
|
||||
/// the public access methods (LimitSquibDuration, etc) exist in case we separate them out in the future
|
||||
/// </summary>
|
||||
public bool LimitDuration
|
||||
{
|
||||
get => _limitDuration;
|
||||
set => SetProperty(ref _limitDuration, value, "LimitDuration");
|
||||
}
|
||||
|
||||
private bool _limitDuration = true;
|
||||
public bool LimitSquibFireDuration
|
||||
{
|
||||
get => _limitDuration;
|
||||
set => SetProperty(ref _limitDuration, value, "LimitSquibFireDuration");
|
||||
}
|
||||
|
||||
private double _squibToleranceLow = 1D;
|
||||
|
||||
public double SquibToleranceLow
|
||||
{
|
||||
get => _squibToleranceLow;
|
||||
set => SetProperty(ref _squibToleranceLow, value, "SquibToleranceLow");
|
||||
}
|
||||
|
||||
private double _squibToleranceHigh = 8D;
|
||||
public double SquibToleranceHigh
|
||||
{
|
||||
get => _squibToleranceHigh;
|
||||
set => SetProperty(ref _squibToleranceHigh, value, "SquibToleranceHigh");
|
||||
}
|
||||
|
||||
private SquibMeasurementType _squibMeasurementType = SquibMeasurementType.VOLTAGE;
|
||||
public SquibMeasurementType SquibMeasurementType
|
||||
{
|
||||
get => _squibMeasurementType;
|
||||
set => SetProperty(ref _squibMeasurementType, value, "SquibMeasurementType");
|
||||
}
|
||||
|
||||
private double _squibOutputCurrent = 1.5D;
|
||||
public double SquibOutputCurrent
|
||||
{
|
||||
get => _squibOutputCurrent;
|
||||
set => SetProperty(ref _squibOutputCurrent, value, "SquibOutputCurrent");
|
||||
}
|
||||
|
||||
public override string DisplayUnit
|
||||
{
|
||||
get
|
||||
{
|
||||
if (IsSquib())
|
||||
{
|
||||
switch (SquibMeasurementType)
|
||||
{
|
||||
case SquibMeasurementType.CURRENT:
|
||||
return "A";
|
||||
default:
|
||||
return "V";
|
||||
}
|
||||
}
|
||||
if (null == Calibration || 0 == Calibration.Records.Records.Length) { return ""; }
|
||||
return Calibration.Records.Records[0].EngineeringUnits; //6194 disable display units for the short term
|
||||
}
|
||||
//6194 disable display units for the short term
|
||||
set { }
|
||||
}
|
||||
private SquibFireMode _squibFireMode = SquibFireMode.NONE;
|
||||
public SquibFireMode SquibFireMode
|
||||
{
|
||||
get => _squibFireMode;
|
||||
set => SetProperty(ref _squibFireMode, value, "SquibFireMode");
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// the input mode for this setting
|
||||
/// </summary>
|
||||
protected DigitalInputModes _inputMode = DigitalInputModes.CCNO;
|
||||
/// <summary>
|
||||
/// the scaler is a bit different than an ordinary scaler, so the name here is inaccurate, however the idea is
|
||||
/// that we allow the user to transform collected data, primarly by allowing them to define the 0,1 value of the digital output
|
||||
/// </summary>
|
||||
protected DigitalInputScaleMultiplier _digitalInputScaleMultiplier = new DigitalInputScaleMultiplier();
|
||||
|
||||
/// <summary>
|
||||
/// the setting name allows us to refer to different settings and allow it to be more easily included in test setups and channel setups
|
||||
/// </summary>
|
||||
public string SettingName
|
||||
{
|
||||
get => SerialNumber;
|
||||
set
|
||||
{
|
||||
SerialNumber = value;
|
||||
OnPropertyChanged("SettingName");
|
||||
}
|
||||
}
|
||||
|
||||
public DigitalInputModes InputMode
|
||||
{
|
||||
get => _inputMode;
|
||||
set => SetProperty(ref _inputMode, value, "InputMode");
|
||||
}
|
||||
|
||||
public DigitalInputScaleMultiplier ScaleMultiplier
|
||||
{
|
||||
get => _digitalInputScaleMultiplier;
|
||||
set => SetProperty(ref _digitalInputScaleMultiplier, value, "ScaleMultiplier");
|
||||
}
|
||||
|
||||
public SensorData(SensorData copy)
|
||||
{
|
||||
if (null == copy) { copy = new SensorData(); }
|
||||
DbTimeStamp = copy.DbTimeStamp;
|
||||
_digitalOutputMode = copy._digitalOutputMode;
|
||||
_inputMode = copy._inputMode;
|
||||
SquibMeasurementType = copy.SquibMeasurementType;
|
||||
_digitalInputScaleMultiplier = new DigitalInputScaleMultiplier(copy._digitalInputScaleMultiplier);
|
||||
_delayMS = copy._delayMS;
|
||||
_digitalOutputDelayMS = copy._digitalOutputDelayMS;
|
||||
_durationMS = copy._durationMS;
|
||||
_digitalOutputDurationMS = copy._digitalOutputDurationMS;
|
||||
_limitDuration = copy._limitDuration;
|
||||
_squibToleranceHigh = copy._squibToleranceHigh;
|
||||
_squibToleranceLow = copy._squibToleranceLow;
|
||||
_squibFireMode = copy._squibFireMode;
|
||||
_squibOutputCurrent = copy._squibOutputCurrent;
|
||||
TagsBlobBytes = copy.TagsBlobBytes;
|
||||
DoNotUse = copy.DoNotUse;
|
||||
Broken = copy.Broken;
|
||||
DbTimeStamp = copy.DbTimeStamp;
|
||||
if (null != copy.Calibration)
|
||||
{
|
||||
Calibration = new SensorCalibration(copy.Calibration);
|
||||
}
|
||||
try
|
||||
{
|
||||
AxisNumber = copy.AxisNumber;
|
||||
BridgeLegMode = copy.BridgeLegMode;
|
||||
BridgeResistance = copy.BridgeResistance;
|
||||
Bridge = copy.Bridge;
|
||||
ByPassFilter = copy.ByPassFilter;
|
||||
CheckCalibrationSignal = copy.CheckCalibrationSignal;
|
||||
CalInterval = copy.CalInterval;
|
||||
Capacity = copy.Capacity;
|
||||
CheckOffset = copy.CheckOffset;
|
||||
Comment = copy.Comment;
|
||||
CouplingMode = copy.CouplingMode;
|
||||
Created = copy.Created;
|
||||
ExternalShuntResistance = copy.ExternalShuntResistance;
|
||||
Filter = copy.Filter;
|
||||
Id = copy.Id;
|
||||
InternalShuntResistance = copy.InternalShuntResistance;
|
||||
Invert = copy.Invert;
|
||||
ISOCode = copy.ISOCode;
|
||||
LastModified = copy.LastModified;
|
||||
_localOnly = copy.LocalOnly;
|
||||
Manufacturer = copy.Manufacturer;
|
||||
DisplayUnit = copy.DisplayUnit;
|
||||
Model = copy.Model;
|
||||
LastUpdatedBy = copy.LastUpdatedBy;
|
||||
NumberOfAxes = copy.NumberOfAxes;
|
||||
OffsetToleranceHigh = copy.OffsetToleranceHigh;
|
||||
OffsetToleranceLow = copy.OffsetToleranceLow;
|
||||
RangeMedium = copy.RangeMedium;
|
||||
RangeHigh = copy.RangeHigh;
|
||||
RangeLow = copy.RangeLow;
|
||||
SensorCategory = copy.SensorCategory;
|
||||
SerialNumber = copy.SerialNumber;
|
||||
Shunt = copy.Shunt;
|
||||
Status = copy.Status;
|
||||
TimesUsed = copy.TimesUsed;
|
||||
UniPolar = copy.UniPolar;
|
||||
UserSerialNumber = copy.UserSerialNumber;
|
||||
UserValue1 = copy.UserValue1;
|
||||
UserValue2 = copy.UserValue2;
|
||||
UserValue3 = copy.UserValue3;
|
||||
DiagnosticsMode = copy.DiagnosticsMode;
|
||||
Version = copy.Version;
|
||||
SetSupportedExcitationFromString(copy.GetSerializedSupportedExcitation());
|
||||
TagsBlobBytes = copy.TagsBlobBytes;
|
||||
DoNotUse = copy.DoNotUse;
|
||||
Broken = copy.Broken;
|
||||
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//APILogger.Log(ex);
|
||||
}
|
||||
|
||||
FilterClassIso = copy.FilterClassIso;
|
||||
MeasureExcitation = copy.MeasureExcitation;
|
||||
MeasureNoise = copy.MeasureNoise;
|
||||
}
|
||||
private static Test.Module.Channel.Sensor.BridgeType ConvertToBridge(int bridge)
|
||||
{
|
||||
switch (bridge)
|
||||
{
|
||||
case 0: return Test.Module.Channel.Sensor.BridgeType.IEPE;
|
||||
case 4: return Test.Module.Channel.Sensor.BridgeType.HalfBridge_SigPlus;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
//added an option parameter to prevent querying cals one by one by passing in a dictionary
|
||||
//17991 calspan speed ups for opening a test setup
|
||||
public SensorData(IDataRecord reader, IReadOnlyDictionary<string, SensorCalibration> calLookup = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
AxisNumber = Convert.ToInt16(reader[DbOperations.SensorDB.SensorDataFields.AxisNumber.ToString()]);
|
||||
BridgeLegMode = (BridgeLeg)Convert.ToInt32(reader[DbOperations.SensorDB.SensorDataFields.BridgeLegMode.ToString()]);
|
||||
BridgeResistance = Convert.ToDouble(reader[DbOperations.SensorDB.SensorDataFields.BridgeResistance.ToString()]);
|
||||
Bridge = ConvertToBridge(Convert.ToInt32(reader[DbOperations.SensorDB.SensorDataFields.BridgeType.ToString()]));
|
||||
ByPassFilter = Convert.ToBoolean(reader[DbOperations.SensorDB.SensorDataFields.BypassFilter.ToString()]);
|
||||
CheckCalibrationSignal = Convert.ToBoolean(reader[DbOperations.SensorDB.SensorDataFields.CalibrationSignal.ToString()]);
|
||||
CalInterval = Convert.ToInt32(reader[DbOperations.SensorDB.SensorDataFields.CalInterval.ToString()]);
|
||||
Capacity = Convert.ToDouble(reader[DbOperations.SensorDB.SensorDataFields.Capacity.ToString()]);
|
||||
CheckOffset = Convert.ToBoolean(reader[DbOperations.SensorDB.SensorDataFields.CheckOffset.ToString()]);
|
||||
Comment = Convert.ToString(reader[DbOperations.SensorDB.SensorDataFields.Comment.ToString()]);
|
||||
CouplingMode = (CouplingModes)Convert.ToInt32(reader[DbOperations.SensorDB.SensorDataFields.CouplingMode.ToString()]);
|
||||
Created = (DateTime)reader[DbOperations.SensorDB.SensorDataFields.Created.ToString()];
|
||||
ExternalShuntResistance = Convert.ToDouble(reader[DbOperations.SensorDB.SensorDataFields.ExternalShuntResistance.ToString()]);
|
||||
Filter = new FilterClass(Convert.ToString(reader[DbOperations.SensorDB.SensorDataFields.FilterClass.ToString()]));
|
||||
Id = Convert.ToString(reader[DbOperations.SensorDB.SensorDataFields.eId.ToString()]);
|
||||
InternalShuntResistance = Convert.ToDouble(reader[DbOperations.SensorDB.SensorDataFields.InternalShuntResistance.ToString()]);
|
||||
Invert = Convert.ToBoolean(reader[DbOperations.SensorDB.SensorDataFields.Invert.ToString()]);
|
||||
ISOCode = Convert.ToString(reader[DbOperations.SensorDB.SensorDataFields.IsoCode.ToString()]);
|
||||
LastModified = (DateTime)reader[DbOperations.SensorDB.SensorDataFields.LastModified.ToString()];
|
||||
_localOnly = Convert.ToBoolean(reader[DbOperations.SensorDB.SensorDataFields.LocalOnly.ToString()]);
|
||||
Manufacturer = Convert.ToString(reader[DbOperations.SensorDB.SensorDataFields.Manufacturer.ToString()]);
|
||||
DisplayUnit = Convert.ToString(reader[DbOperations.SensorDB.SensorDataFields.MeasurementUnit.ToString()]);
|
||||
Model = Convert.ToString(reader[DbOperations.SensorDB.SensorDataFields.Model.ToString()]);
|
||||
LastUpdatedBy = Convert.ToString(reader[DbOperations.SensorDB.SensorDataFields.ModifiedBy.ToString()]);
|
||||
NumberOfAxes = Convert.ToInt16(reader[DbOperations.SensorDB.SensorDataFields.NumberOfAxes.ToString()]);
|
||||
OffsetToleranceHigh = Convert.ToDouble(reader[DbOperations.SensorDB.SensorDataFields.OffsetToleranceHigh.ToString()]);
|
||||
OffsetToleranceLow = Convert.ToDouble(reader[DbOperations.SensorDB.SensorDataFields.OffsetToleranceLow.ToString()]);
|
||||
RangeMedium = Convert.ToDouble(reader[DbOperations.SensorDB.SensorDataFields.RangeAve.ToString()]);
|
||||
RangeHigh = Convert.ToDouble(reader[DbOperations.SensorDB.SensorDataFields.RangeHigh.ToString()]);
|
||||
RangeLow = Convert.ToDouble(reader[DbOperations.SensorDB.SensorDataFields.RangeLow.ToString()]);
|
||||
SensorCategory = Convert.ToInt32(reader[DbOperations.SensorDB.SensorDataFields.SensorCategory.ToString()]);
|
||||
SerialNumber = Convert.ToString(reader[DbOperations.SensorDB.SensorDataFields.SerialNumber.ToString()]);
|
||||
Shunt = (ShuntMode)Convert.ToInt32(reader[DbOperations.SensorDB.SensorDataFields.Shunt.ToString()]);
|
||||
var oStatus = reader[DbOperations.SensorDB.SensorDataFields.Status.ToString()];
|
||||
if (oStatus is string s)
|
||||
{
|
||||
if (Enum.TryParse(s, out SensorStatus newStatus))
|
||||
{
|
||||
Status = newStatus;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Status = (SensorStatus)Convert.ToInt32(oStatus);
|
||||
}
|
||||
TimesUsed = Convert.ToInt32(reader[DbOperations.SensorDB.SensorDataFields.TimesUsed.ToString()]);
|
||||
UniPolar = Convert.ToBoolean(reader[DbOperations.SensorDB.SensorDataFields.UniPolar.ToString()]);
|
||||
UserSerialNumber = Convert.ToString(reader[DbOperations.SensorDB.SensorDataFields.UserSerialNumber.ToString()]);
|
||||
DiagnosticsMode = Convert.ToBoolean(reader[DbOperations.SensorDB.SensorDataFields.DiagnosticsMode.ToString()]);
|
||||
UserValue1 = Convert.ToString(reader[DbOperations.SensorDB.SensorDataFields.UserValue1.ToString()]);
|
||||
UserValue2 = Convert.ToString(reader[DbOperations.SensorDB.SensorDataFields.UserValue2.ToString()]);
|
||||
UserValue3 = Convert.ToString(reader[DbOperations.SensorDB.SensorDataFields.UserValue3.ToString()]);
|
||||
Version = Convert.ToInt32(reader[DbOperations.SensorDB.SensorDataFields.Version.ToString()]);
|
||||
SetSupportedExcitationFromString(Convert.ToString(reader[DbOperations.SensorDB.SensorDataFields.SupportedExcitation.ToString()]));
|
||||
TagsBlobBytes = (byte[])reader[DbOperations.SensorDB.SensorDataFields.UserTags.ToString()];
|
||||
DoNotUse = Convert.ToBoolean(reader[DbOperations.SensorDB.SensorDataFields.DoNotUse.ToString()]);
|
||||
Broken = Convert.ToBoolean(reader[DbOperations.SensorDB.SensorDataFields.Broken.ToString()]);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//APILogger.Log("Failed to process: ", ex);
|
||||
}
|
||||
}
|
||||
private string _serialNumber = "";
|
||||
public string SerialNumber
|
||||
{
|
||||
get => _serialNumber;
|
||||
set => SetProperty(ref _serialNumber, value, "SerialNumber");
|
||||
}
|
||||
private string _userSerialNumber = "";
|
||||
public string UserSerialNumber
|
||||
{
|
||||
get => _userSerialNumber;
|
||||
set
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
value = "";
|
||||
}
|
||||
SetProperty(ref _userSerialNumber, value, "UserSerialNumber");
|
||||
}
|
||||
}
|
||||
|
||||
private SensorStatus _status = SensorStatus.Available;
|
||||
public SensorStatus Status
|
||||
{
|
||||
get => _status;
|
||||
set => _status = value;
|
||||
}
|
||||
|
||||
|
||||
private string _id = "";
|
||||
public string Id
|
||||
{
|
||||
get => _id;
|
||||
set
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
value = "";
|
||||
}
|
||||
SetProperty(ref _id, value, "Id");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private string _comment = "";
|
||||
public string Comment
|
||||
{
|
||||
get => _comment;
|
||||
set
|
||||
{
|
||||
if (string.IsNullOrEmpty(value)) { value = ""; }
|
||||
SetProperty(ref _comment, value, "Comment");
|
||||
}
|
||||
}
|
||||
private double _internalShuntResistance;
|
||||
public double InternalShuntResistance
|
||||
{
|
||||
get => _internalShuntResistance;
|
||||
set => SetProperty(ref _internalShuntResistance, value, "InternalShuntResistance");
|
||||
}
|
||||
|
||||
private double _externalShuntResistance;
|
||||
public double ExternalShuntResistance
|
||||
{
|
||||
get => _externalShuntResistance;
|
||||
set => SetProperty(ref _externalShuntResistance, value, "ExternalShuntResistance");
|
||||
}
|
||||
|
||||
private BridgeLeg _bridgeLegMode = BridgeLeg.First;
|
||||
public BridgeLeg BridgeLegMode
|
||||
{
|
||||
get => _bridgeLegMode;
|
||||
set => SetProperty(ref _bridgeLegMode, value, "BridgeLegMode");
|
||||
}
|
||||
|
||||
|
||||
private string _userValue1 = "";
|
||||
public string UserValue1
|
||||
{
|
||||
get => _userValue1;
|
||||
set { if (value == null) { value = ""; } SetProperty(ref _userValue1, value, "UserValue1"); }
|
||||
}
|
||||
|
||||
private string _userValue2 = "";
|
||||
public string UserValue2
|
||||
{
|
||||
get => _userValue2;
|
||||
set { if (value == null) { value = ""; } SetProperty(ref _userValue2, value, "UserValue2"); }
|
||||
}
|
||||
|
||||
private string _userValue3 = "";
|
||||
public string UserValue3
|
||||
{
|
||||
get => _userValue3;
|
||||
set { if (value == null) { value = ""; } SetProperty(ref _userValue3, value, "UserValue3"); }
|
||||
}
|
||||
|
||||
|
||||
public string GetSerializedSupportedExcitation()
|
||||
{
|
||||
return string.Join(System.Globalization.CultureInfo.InvariantCulture.TextInfo.ListSeparator, SupportedExcitation.Select(sp => sp.ToString()).ToArray());
|
||||
}
|
||||
public void SetSupportedExcitationFromString(string s)
|
||||
{
|
||||
var excitations = new List<ExcitationVoltageOptions.ExcitationVoltageOption>();
|
||||
|
||||
var tokens = s.Split(new[] { System.Globalization.CultureInfo.InvariantCulture.TextInfo.ListSeparator }, StringSplitOptions.None);
|
||||
foreach (var token in tokens)
|
||||
{
|
||||
if (Enum.TryParse(token, out ExcitationVoltageOptions.ExcitationVoltageOption option)) { excitations.Add(option); }
|
||||
}
|
||||
SupportedExcitation = excitations.ToArray();
|
||||
}
|
||||
|
||||
private DateTime _created = (DateTime)System.Data.SqlTypes.SqlDateTime.MinValue;
|
||||
public DateTime Created
|
||||
{
|
||||
get => _created;
|
||||
set => SetProperty(ref _created, value, "Created");
|
||||
}
|
||||
|
||||
private int _timesUsed;
|
||||
public int TimesUsed
|
||||
{
|
||||
get => _timesUsed;
|
||||
set => SetProperty(ref _timesUsed, value, "TimesUsed");
|
||||
}
|
||||
|
||||
private int _sensorCategory;
|
||||
public int SensorCategory
|
||||
{
|
||||
get => _sensorCategory;
|
||||
set => SetProperty(ref _sensorCategory, value, "SensorCategory");
|
||||
}
|
||||
|
||||
private bool _bypassFilter;
|
||||
public bool ByPassFilter
|
||||
{
|
||||
get => _bypassFilter;
|
||||
set => SetProperty(ref _bypassFilter, value, "BypassFilter");
|
||||
}
|
||||
|
||||
private bool _checkCalibrationSignal;
|
||||
public bool CheckCalibrationSignal
|
||||
{
|
||||
get => _checkCalibrationSignal;
|
||||
set => SetProperty(ref _checkCalibrationSignal, value, "CheckCalibrationSignal");
|
||||
}
|
||||
|
||||
|
||||
public string TestObject
|
||||
{
|
||||
get => new IsoCode(ISOCode).TestObject;
|
||||
set
|
||||
{
|
||||
var ic = new IsoCode(ISOCode) { TestObject = value };
|
||||
ISOCode = ic.StringRepresentation;
|
||||
OnPropertyChanged("TestObject");
|
||||
}
|
||||
}
|
||||
|
||||
public string OriginalPosition { get; set; }
|
||||
|
||||
public string Position
|
||||
{
|
||||
get
|
||||
{
|
||||
var ic = new IsoCode(ISOCode);
|
||||
return ic.Position;
|
||||
}
|
||||
set
|
||||
{
|
||||
var ic = new IsoCode(ISOCode);
|
||||
ic.Position = value;
|
||||
ISOCode = ic.StringRepresentation;
|
||||
OnPropertyChanged("Position");
|
||||
}
|
||||
}
|
||||
public string MainLocation
|
||||
{
|
||||
get
|
||||
{
|
||||
var ic = new IsoCode(ISOCode);
|
||||
return ic.MainLocation;
|
||||
}
|
||||
set
|
||||
{
|
||||
var ic = new IsoCode(ISOCode);
|
||||
ic.MainLocation = value;
|
||||
ISOCode = ic.StringRepresentation;
|
||||
OnPropertyChanged("MainLocation");
|
||||
}
|
||||
}
|
||||
public string FineLocation1
|
||||
{
|
||||
get
|
||||
{
|
||||
var ic = new IsoCode(ISOCode);
|
||||
return ic.FineLocation1;
|
||||
}
|
||||
set
|
||||
{
|
||||
var ic = new IsoCode(ISOCode);
|
||||
ic.FineLocation1 = value;
|
||||
ISOCode = ic.StringRepresentation;
|
||||
OnPropertyChanged("FineLocation1");
|
||||
}
|
||||
}
|
||||
public string FineLocation2
|
||||
{
|
||||
get
|
||||
{
|
||||
var ic = new IsoCode(ISOCode);
|
||||
return ic.FineLocation2;
|
||||
}
|
||||
set
|
||||
{
|
||||
var ic = new IsoCode(ISOCode);
|
||||
ic.FineLocation2 = value;
|
||||
ISOCode = ic.StringRepresentation;
|
||||
OnPropertyChanged("FineLocation2");
|
||||
}
|
||||
}
|
||||
public string FineLocation3
|
||||
{
|
||||
get
|
||||
{
|
||||
var ic = new IsoCode(ISOCode);
|
||||
return ic.FineLocation3;
|
||||
}
|
||||
set
|
||||
{
|
||||
var ic = new IsoCode(ISOCode);
|
||||
ic.FineLocation3 = value;
|
||||
ISOCode = ic.StringRepresentation;
|
||||
OnPropertyChanged("FineLocation3");
|
||||
}
|
||||
}
|
||||
public string FilterClassIso
|
||||
{
|
||||
get
|
||||
{
|
||||
var ic = new IsoCode(ISOCode);
|
||||
return ic.FilterClass;
|
||||
}
|
||||
set
|
||||
{
|
||||
var ic = new IsoCode(ISOCode);
|
||||
ic.FilterClass = value;
|
||||
ISOCode = ic.StringRepresentation;
|
||||
switch (value)
|
||||
{
|
||||
case "A":
|
||||
Filter = new FilterClass(FilterClass.FilterClassType.CFC1000);
|
||||
break;
|
||||
case "B":
|
||||
Filter = new FilterClass(FilterClass.FilterClassType.CFC600);
|
||||
break;
|
||||
case "C":
|
||||
Filter = new FilterClass(FilterClass.FilterClassType.CFC180);
|
||||
break;
|
||||
case "D":
|
||||
Filter = new FilterClass(FilterClass.FilterClassType.CFC60);
|
||||
break;
|
||||
case "P":
|
||||
Filter = new FilterClass(FilterClass.FilterClassType.None);
|
||||
break;
|
||||
case "S":
|
||||
Filter = new FilterClass(FilterClass.FilterClassType.AdHoc);
|
||||
break;
|
||||
}
|
||||
OnPropertyChanged("FilterClassIso");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public SensorData()
|
||||
{
|
||||
ISOCode = BuildIsoCodeFromFilter(null, Filter.FClass);
|
||||
}
|
||||
|
||||
public int CompareTo(SensorData other)
|
||||
{
|
||||
return string.Compare(SerialNumber, other.SerialNumber, StringComparison.Ordinal);
|
||||
}
|
||||
public bool IncompatibleSensorAssignment(string sensorDimension, string channelDimension)
|
||||
{
|
||||
return sensorDimension != channelDimension &&
|
||||
sensorDimension != "00" &&
|
||||
sensorDimension != "SE" &&
|
||||
!sensorDimension.Contains("?") &&
|
||||
channelDimension != "00" &&
|
||||
channelDimension != "SE" &&
|
||||
!channelDimension.Contains("?");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,768 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
|
||||
namespace DatabaseImport
|
||||
{
|
||||
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; }
|
||||
protected bool _checkOffset = true;
|
||||
public bool CheckOffset
|
||||
{
|
||||
get => _checkOffset;
|
||||
set => SetProperty(ref _checkOffset, value, "CheckOffset");
|
||||
}
|
||||
|
||||
|
||||
protected bool _measureNoise = true;
|
||||
public bool MeasureNoise
|
||||
{
|
||||
get => _measureNoise;
|
||||
set => SetProperty(ref _measureNoise, value, "MeasureNoise");
|
||||
}
|
||||
|
||||
protected bool _measureExcitation = true;
|
||||
public bool MeasureExcitation
|
||||
{
|
||||
get => _measureExcitation;
|
||||
set => SetProperty(ref _measureExcitation, value, "MeasureExcitation");
|
||||
}
|
||||
|
||||
protected bool _invert = false;
|
||||
public bool Invert
|
||||
{
|
||||
get => _invert;
|
||||
set => SetProperty(ref _invert, value, "Invert");
|
||||
}
|
||||
|
||||
protected string _Model = "";
|
||||
public string Model
|
||||
{
|
||||
get => _Model;
|
||||
set => SetProperty(ref _Model, value, "Model");
|
||||
}
|
||||
|
||||
protected string _Manufacturer = "";
|
||||
public string Manufacturer
|
||||
{
|
||||
get => _Manufacturer;
|
||||
set => SetProperty(ref _Manufacturer, value, "Manufacturer");
|
||||
}
|
||||
|
||||
protected string _UserPartNumber = "";
|
||||
public string UserPartNumber
|
||||
{
|
||||
get => _UserPartNumber;
|
||||
set => SetProperty(ref _UserPartNumber, value, "UserPartNumber");
|
||||
}
|
||||
|
||||
protected double _Capacity = 2400D;
|
||||
public double Capacity
|
||||
{
|
||||
get => _Capacity;
|
||||
set => SetProperty(ref _Capacity, value, "Capacity");
|
||||
}
|
||||
protected CouplingModes _couplingMode = CouplingModes.AC;
|
||||
public CouplingModes CouplingMode
|
||||
{
|
||||
get => _couplingMode;
|
||||
set => SetProperty(ref _couplingMode, value, "CouplingMode");
|
||||
}
|
||||
|
||||
protected LowHigh _OffsetTolerance = new LowHigh(-100D, 100D);
|
||||
public double OffsetToleranceLow
|
||||
{
|
||||
get => _OffsetTolerance.Low;
|
||||
set { _OffsetTolerance.Low = value; OnPropertyChanged("OffsetToleranceLow"); }
|
||||
}
|
||||
public double OffsetToleranceHigh
|
||||
{
|
||||
get => _OffsetTolerance.High;
|
||||
set { _OffsetTolerance.High = value; OnPropertyChanged("OffsetToleranceHigh"); }
|
||||
}
|
||||
|
||||
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; OnPropertyChanged("RangeLow"); }
|
||||
}
|
||||
public double RangeMedium
|
||||
{
|
||||
get => 0 == _Range.Medium ? Capacity : _Range.Medium;
|
||||
set { _Range.Medium = value; OnPropertyChanged("RangeMedium"); }
|
||||
}
|
||||
public double RangeHigh
|
||||
{
|
||||
get => 0 == _Range.High ? Capacity : _Range.High;
|
||||
set { _Range.High = value; OnPropertyChanged("RangeHigh"); }
|
||||
}
|
||||
|
||||
protected List<ExcitationVoltageOptions.ExcitationVoltageOption> _supportedExcitation = new List<ExcitationVoltageOptions.ExcitationVoltageOption>(
|
||||
new[] { ExcitationVoltageOptions.ExcitationVoltageOption.Volt5 });
|
||||
public ExcitationVoltageOptions.ExcitationVoltageOption[] SupportedExcitation
|
||||
{
|
||||
get => _supportedExcitation.ToArray();
|
||||
set => SetProperty(ref _supportedExcitation, new List<ExcitationVoltageOptions.ExcitationVoltageOption>(value), "SupportedExcitation");
|
||||
}
|
||||
protected SensorCalibration _calibration = new SensorCalibration();
|
||||
/// <summary>
|
||||
/// 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
|
||||
/// </summary>
|
||||
public virtual SensorCalibration Calibration
|
||||
{
|
||||
get => _calibration;
|
||||
set => SetProperty(ref _calibration, value, "Calibration");
|
||||
}
|
||||
|
||||
protected Test.Module.Channel.Sensor.BridgeType _Bridge = Test.Module.Channel.Sensor.BridgeType.FullBridge;
|
||||
public Test.Module.Channel.Sensor.BridgeType Bridge
|
||||
{
|
||||
get => _Bridge;
|
||||
set => SetProperty(ref _Bridge, value, "Bridge");
|
||||
}
|
||||
|
||||
protected ShuntMode _Shunt = ShuntMode.Emulation;
|
||||
public ShuntMode Shunt
|
||||
{
|
||||
get => _Shunt;
|
||||
set => SetProperty(ref _Shunt, value, "Shunt");
|
||||
}
|
||||
|
||||
protected double _BridgeResistance = 350D;
|
||||
|
||||
public double BridgeResistance
|
||||
{
|
||||
get => _BridgeResistance;
|
||||
set => SetProperty(ref _BridgeResistance, value, "BridgeResistance");
|
||||
}
|
||||
|
||||
protected FilterClass _Filter = new FilterClass(FilterClass.FilterClassType.CFC1000);
|
||||
public FilterClass Filter
|
||||
{
|
||||
get => _Filter;
|
||||
set => SetProperty(ref _Filter, value, "Filter");
|
||||
}
|
||||
protected bool _UniPolar = false;
|
||||
public bool UniPolar
|
||||
{
|
||||
get => _UniPolar;
|
||||
set => SetProperty(ref _UniPolar, value, "UniPolar");
|
||||
}
|
||||
|
||||
protected bool _IgnoreRange = false;
|
||||
public bool IgnoreRange
|
||||
{
|
||||
get => _IgnoreRange;
|
||||
set => SetProperty(ref _IgnoreRange, value, "IgnoreRange");
|
||||
}
|
||||
|
||||
protected string _lastUpdatedBy;
|
||||
public string LastUpdatedBy
|
||||
{
|
||||
get => _lastUpdatedBy;
|
||||
set => SetProperty(ref _lastUpdatedBy, value, "LastUpdatedBy");
|
||||
}
|
||||
|
||||
protected int _version = 1;
|
||||
public int Version
|
||||
{
|
||||
get => _version;
|
||||
set => SetProperty(ref _version, value, "Version");
|
||||
}
|
||||
protected bool _localOnly = false;
|
||||
public bool LocalOnly => _localOnly;
|
||||
public void SetLocalOnly(bool bLocalOnly) { SetProperty(ref _localOnly, bLocalOnly, "LocalOnly"); }
|
||||
|
||||
protected short _axisNumber = 0;
|
||||
public short AxisNumber
|
||||
{
|
||||
get => _axisNumber;
|
||||
set => SetProperty(ref _axisNumber, value, "AxisNumber");
|
||||
}
|
||||
|
||||
protected short _numberOfAxes = 1;
|
||||
public short NumberOfAxes
|
||||
{
|
||||
get => _numberOfAxes;
|
||||
set => SetProperty(ref _numberOfAxes, value, "NumberOfAxes");
|
||||
}
|
||||
protected int _calInterval = 365;
|
||||
public int CalInterval
|
||||
{
|
||||
get => _calInterval;
|
||||
set => SetProperty(ref _calInterval, value, "CalInterval");
|
||||
}
|
||||
public string Polarity
|
||||
{
|
||||
get => _invert ? "-" : "+";
|
||||
set { Invert = value == "-"; OnPropertyChanged("Polarity"); }
|
||||
}
|
||||
|
||||
protected DateTime _lastModified = (DateTime)System.Data.SqlTypes.SqlDateTime.MinValue;
|
||||
|
||||
public DateTime LastModified
|
||||
{
|
||||
get => _lastModified;
|
||||
set => SetProperty(ref _lastModified, value, "LastModified");
|
||||
}
|
||||
|
||||
protected IsoCode _isoCode = new IsoCode("");
|
||||
|
||||
public string ISOCode
|
||||
{
|
||||
get => _isoCode.StringRepresentation;
|
||||
set => SetProperty(ref _isoCode, new IsoCode(value), "ISOCode");
|
||||
}
|
||||
|
||||
public string PhysicalDimension
|
||||
{
|
||||
get => _isoCode.PhysicalDimension;
|
||||
set => _isoCode.PhysicalDimension = value;
|
||||
}
|
||||
|
||||
public string Direction
|
||||
{
|
||||
get => _isoCode.Direction;
|
||||
set => _isoCode.Direction = value;
|
||||
}
|
||||
|
||||
|
||||
private bool _doNotUse = false;
|
||||
public bool DoNotUse
|
||||
{
|
||||
get => _doNotUse;
|
||||
set => SetProperty(ref _doNotUse, value, "DoNotUse");
|
||||
}
|
||||
|
||||
private bool _broken = false;
|
||||
public bool Broken
|
||||
{
|
||||
get => _broken;
|
||||
set => SetProperty(ref _broken, value, "Broken");
|
||||
}
|
||||
|
||||
|
||||
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 static 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;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException("fClass", fClass, null);
|
||||
}
|
||||
return isoFilterCode;
|
||||
}
|
||||
|
||||
}
|
||||
public class SensorModel : SensorBase, IComparable<SensorModel>
|
||||
{
|
||||
public enum IRTraccFormats
|
||||
{
|
||||
Manual,
|
||||
DiagnosticZeroMMmV,
|
||||
ZeroMMmV,
|
||||
AverageOverTime,
|
||||
Polynomial
|
||||
}
|
||||
private enum XMLFields
|
||||
{
|
||||
Model,
|
||||
Manufacturer,
|
||||
UserPartNumber,
|
||||
Capacity,
|
||||
OffsetTolerance,
|
||||
MeasurementUnit,
|
||||
SensorRange,
|
||||
Sensitivity,
|
||||
Excitation,
|
||||
IsProportional,
|
||||
Bridge,
|
||||
Shunt,
|
||||
BridgeResistance,
|
||||
RemoveOffset,
|
||||
FilterClass,
|
||||
ZeroMethod,
|
||||
InitialEU,
|
||||
NonLinear,
|
||||
UniPolar,
|
||||
PolynomialStyle,
|
||||
IRTraccFormat,
|
||||
LinearizationFormula,
|
||||
PhysicalDimension,
|
||||
IgnoreRange,
|
||||
Invert,
|
||||
CouplingMode,
|
||||
CheckOffset
|
||||
}
|
||||
public SensorModel(System.Xml.XmlElement node)
|
||||
{
|
||||
var initialEU = 0D;
|
||||
foreach (var childnode in node.ChildNodes)
|
||||
{
|
||||
if (!(childnode is System.Xml.XmlElement elem)) { continue; }
|
||||
try
|
||||
{
|
||||
var field = (XMLFields)Enum.Parse(typeof(XMLFields), elem.Name);
|
||||
var value = elem.InnerText;
|
||||
switch (field)
|
||||
{
|
||||
case XMLFields.Bridge:
|
||||
Bridge = (Test.Module.Channel.Sensor.BridgeType)Enum.Parse(typeof(Test.Module.Channel.Sensor.BridgeType), value);
|
||||
break;
|
||||
case XMLFields.BridgeResistance:
|
||||
BridgeResistance = double.Parse(value, System.Globalization.CultureInfo.InvariantCulture);
|
||||
break;
|
||||
case XMLFields.Capacity:
|
||||
Capacity = double.Parse(value, System.Globalization.CultureInfo.InvariantCulture);
|
||||
break;
|
||||
case XMLFields.Excitation:
|
||||
SupportedExcitation = new ExcitationVoltageOptions.ExcitationVoltageOption[] { (ExcitationVoltageOptions.ExcitationVoltageOption)Enum.Parse(typeof(ExcitationVoltageOptions.ExcitationVoltageOption), value) };
|
||||
break;
|
||||
case XMLFields.FilterClass:
|
||||
Filter = new FilterClass(value);
|
||||
break;
|
||||
case XMLFields.IgnoreRange:
|
||||
IgnoreRange = bool.Parse(value);
|
||||
break;
|
||||
case XMLFields.Invert:
|
||||
Invert = bool.Parse(value);
|
||||
break;
|
||||
case XMLFields.InitialEU:
|
||||
initialEU = double.Parse(value, System.Globalization.CultureInfo.InvariantCulture);
|
||||
//InitialEU = double.Parse(value, System.Globalization.CultureInfo.InvariantCulture);
|
||||
break;
|
||||
case XMLFields.IsProportional:
|
||||
Calibration.IsProportional = bool.Parse(value);
|
||||
break;
|
||||
case XMLFields.LinearizationFormula:
|
||||
Calibration.Records.Records[0].Poly = new LinearizationFormula();
|
||||
Calibration.Records.Records[0].Poly.FromSerializeString(value);
|
||||
break;
|
||||
case XMLFields.Manufacturer:
|
||||
Manufacturer = value;
|
||||
//System.Diagnostics.Trace.WriteLine(Manufacturer);
|
||||
break;
|
||||
case XMLFields.MeasurementUnit:
|
||||
DisplayUnit = value;
|
||||
break;
|
||||
case XMLFields.Model:
|
||||
Model = value;
|
||||
//System.Diagnostics.Trace.WriteLine(Model);
|
||||
break;
|
||||
case XMLFields.NonLinear:
|
||||
Calibration.NonLinear = bool.Parse(value);
|
||||
break;
|
||||
case XMLFields.OffsetTolerance:
|
||||
{
|
||||
var tol = new LowHigh(value);
|
||||
OffsetToleranceHigh = tol.High;
|
||||
OffsetToleranceLow = tol.Low;
|
||||
}
|
||||
break;
|
||||
case XMLFields.PhysicalDimension:
|
||||
PhysicalDimension = value;
|
||||
break;
|
||||
case XMLFields.PolynomialStyle:
|
||||
//var polystyle = (PolynomialStyles)Enum.Parse(typeof(PolynomialStyles), value);
|
||||
//switch (polystyle)
|
||||
//{
|
||||
// case PolynomialStyles.
|
||||
//}
|
||||
//don't need this anymore?
|
||||
break;
|
||||
case XMLFields.IRTraccFormat:
|
||||
var irFormat = (IRTraccFormats)Enum.Parse(typeof(IRTraccFormats), value);
|
||||
switch (irFormat)
|
||||
{
|
||||
case IRTraccFormats.AverageOverTime: Calibration.Records.Records[0].Poly.NonLinearStyle = NonLinearStyles.IRTraccAverageOverTime; break;
|
||||
case IRTraccFormats.DiagnosticZeroMMmV: Calibration.Records.Records[0].Poly.NonLinearStyle = NonLinearStyles.IRTraccDiagnosticsZero; break;
|
||||
case IRTraccFormats.Manual: Calibration.Records.Records[0].Poly.NonLinearStyle = NonLinearStyles.IRTraccManual; break;
|
||||
case IRTraccFormats.ZeroMMmV: Calibration.Records.Records[0].Poly.NonLinearStyle = NonLinearStyles.IRTraccZeroMMmV; break;
|
||||
case IRTraccFormats.Polynomial: Calibration.Records.Records[0].Poly.NonLinearStyle = NonLinearStyles.Polynomial; break;
|
||||
}
|
||||
break;
|
||||
case XMLFields.RemoveOffset:
|
||||
Calibration.RemoveOffset = bool.Parse(value);
|
||||
break;
|
||||
case XMLFields.Sensitivity:
|
||||
Calibration.Records.Records[0].Sensitivity = double.Parse(value, System.Globalization.CultureInfo.InvariantCulture);
|
||||
break;
|
||||
case XMLFields.SensorRange:
|
||||
{
|
||||
var Range = new SensorRange(value);
|
||||
RangeHigh = Range.High;
|
||||
RangeLow = Range.Low;
|
||||
RangeMedium = Range.Medium;
|
||||
}
|
||||
break;
|
||||
case XMLFields.Shunt:
|
||||
Shunt = (ShuntMode)Enum.Parse(typeof(ShuntMode), value);
|
||||
break;
|
||||
case XMLFields.UniPolar:
|
||||
UniPolar = bool.Parse(value);
|
||||
break;
|
||||
case XMLFields.UserPartNumber:
|
||||
UserPartNumber = value;
|
||||
break;
|
||||
case XMLFields.ZeroMethod:
|
||||
{
|
||||
Calibration.ZeroMethod = new ZeroMethod(value);
|
||||
}
|
||||
break;
|
||||
case XMLFields.CouplingMode:
|
||||
CouplingMode = (CouplingModes)Enum.Parse(typeof(CouplingModes), value);
|
||||
break;
|
||||
case XMLFields.CheckOffset:
|
||||
CheckOffset = bool.Parse(value);
|
||||
break;
|
||||
default:
|
||||
throw new NotSupportedException("field :" + field);
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//APILogger.Log("Failed to parse xml", ex, elem.Name, elem.Value);
|
||||
}
|
||||
Calibration.InitialOffset = new InitialOffset(initialEU);
|
||||
}
|
||||
}
|
||||
private Test.Module.Channel.Sensor.BridgeType ConvertToBridge(int bridge)
|
||||
{
|
||||
switch (bridge)
|
||||
{
|
||||
case 0: return Test.Module.Channel.Sensor.BridgeType.IEPE;
|
||||
case 4: return Test.Module.Channel.Sensor.BridgeType.HalfBridge_SigPlus;
|
||||
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(DataRow dr)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
Polarity = (string)dr[DbOperations.SensorDB.SensorModelFields.Polarity.ToString()];
|
||||
AxisNumber = Convert.ToInt16(dr[DbOperations.SensorDB.SensorModelFields.AxisNumber.ToString()]);
|
||||
Bridge = ConvertToBridge(Convert.ToInt32(dr[DbOperations.SensorDB.SensorModelFields.Bridge.ToString()]));
|
||||
BridgeResistance = Convert.ToDouble(dr[DbOperations.SensorDB.SensorModelFields.BridgeResistance.ToString()]);
|
||||
CalInterval = Convert.ToInt32(dr[DbOperations.SensorDB.SensorModelFields.CalInterval.ToString()]);
|
||||
Capacity = Convert.ToDouble(dr[DbOperations.SensorDB.SensorModelFields.Capacity.ToString()]);
|
||||
CouplingMode = (CouplingModes)Convert.ToInt32(dr[DbOperations.SensorDB.SensorModelFields.CouplingMode.ToString()]);
|
||||
Filter = new FilterClass((string)dr[DbOperations.SensorDB.SensorModelFields.FilterClass.ToString()]);
|
||||
IgnoreRange = Convert.ToBoolean(dr[DbOperations.SensorDB.SensorModelFields.IgnoreRange.ToString()]);
|
||||
CheckOffset = Convert.ToBoolean(dr[DbOperations.SensorDB.SensorModelFields.CheckOffset.ToString()]);
|
||||
Invert = Convert.ToBoolean(dr[DbOperations.SensorDB.SensorModelFields.Invert.ToString()]);
|
||||
LastModified = (DateTime)dr[DbOperations.SensorDB.SensorModelFields.LastModified.ToString()];
|
||||
SetLocalOnly(Convert.ToBoolean(dr[DbOperations.SensorDB.SensorModelFields.LocalOnly.ToString()]));
|
||||
Manufacturer = (string)dr[DbOperations.SensorDB.SensorModelFields.Manufacturer.ToString()];
|
||||
DisplayUnit = (string)dr[DbOperations.SensorDB.SensorModelFields.MeasurementUnit.ToString()];
|
||||
Model = (string)dr[DbOperations.SensorDB.SensorModelFields.Model.ToString()];
|
||||
LastUpdatedBy = (string)dr[DbOperations.SensorDB.SensorModelFields.ModifiedBy.ToString()];
|
||||
NumberOfAxes = Convert.ToInt16(dr[DbOperations.SensorDB.SensorModelFields.NumberOfAxes.ToString()]);
|
||||
OffsetToleranceHigh = Convert.ToDouble(dr[DbOperations.SensorDB.SensorModelFields.OffsetToleranceHigh.ToString()]);
|
||||
OffsetToleranceLow = Convert.ToDouble(dr[DbOperations.SensorDB.SensorModelFields.OffsetToleranceLow.ToString()]);
|
||||
RangeMedium = Convert.ToDouble(dr[DbOperations.SensorDB.SensorModelFields.RangeAve.ToString()]);
|
||||
RangeHigh = Convert.ToDouble(dr[DbOperations.SensorDB.SensorModelFields.RangeHigh.ToString()]);
|
||||
RangeLow = Convert.ToDouble(dr[DbOperations.SensorDB.SensorModelFields.RangeLow.ToString()]);
|
||||
Shunt = (ShuntMode)Convert.ToInt32(dr[DbOperations.SensorDB.SensorModelFields.Shunt.ToString()]);
|
||||
UniPolar = Convert.ToBoolean(dr[DbOperations.SensorDB.SensorModelFields.UniPolar.ToString()]);
|
||||
UserPartNumber = (string)dr[DbOperations.SensorDB.SensorModelFields.UserPartNumber.ToString()];
|
||||
Version = Convert.ToInt32(dr[DbOperations.SensorDB.SensorModelFields.Version.ToString()]);
|
||||
ISOCode = (string)dr[DbOperations.SensorDB.SensorModelFields.ISOCode.ToString()];
|
||||
Calibration = new SensorCalibration((string)dr[DbOperations.SensorDB.SensorModelFields.CalibrationRecord.ToString()]);
|
||||
var options = new List<ExcitationVoltageOptions.ExcitationVoltageOption>();
|
||||
var tokens = ((string)dr[DbOperations.SensorDB.SensorModelFields.SupportedExcitation.ToString()]).Split(new[] { System.Globalization.CultureInfo.InvariantCulture.TextInfo.ListSeparator }, StringSplitOptions.None);
|
||||
foreach (var token in tokens)
|
||||
{
|
||||
if (Enum.TryParse(token, out ExcitationVoltageOptions.ExcitationVoltageOption option)) { options.Add(option); }
|
||||
}
|
||||
|
||||
SupportedExcitation = options.ToArray();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//APILogger.Log("Failed to process fields: ", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class SensorModelCollection : INotifyPropertyChanged
|
||||
{
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
protected bool SetProperty<T>(ref T storage, T value, string propertyName = null)
|
||||
{
|
||||
if (Equals(storage, value)) return false;
|
||||
|
||||
storage = value;
|
||||
OnPropertyChanged(propertyName);
|
||||
return true;
|
||||
}
|
||||
protected void OnPropertyChanged(string propertyName = null)
|
||||
{
|
||||
//if (!HookedUp) { return; }
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
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();
|
||||
}
|
||||
// protected SensorModelCollection() { }
|
||||
private static SensorModelCollection _collection = null;
|
||||
public static SensorModelCollection SensorModelList
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
if (null == _collection)
|
||||
{
|
||||
PopulateCollection();
|
||||
}
|
||||
return _collection;
|
||||
}
|
||||
}
|
||||
}
|
||||
private static readonly object _lock = new object();
|
||||
/// <summary>
|
||||
/// deletes all Sensor Models
|
||||
/// originally created so TDM imports could clear all tables except DAS tables
|
||||
/// </summary>
|
||||
public void DeleteAll()
|
||||
{
|
||||
_sensorModels.Clear();
|
||||
try
|
||||
{
|
||||
using (var cmd = DbOperations.GetSQLCommand(true))
|
||||
{
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
cmd.CommandText = DbOperationsEnum.StoredProcedure.sp_SensorModelsDelete.ToString();
|
||||
cmd.Parameters.Add(new SqlParameter("@Model", SqlDbType.NVarChar, 50) { Value = null });
|
||||
cmd.Parameters.Add(new SqlParameter("@Manufacturer", SqlDbType.NVarChar, 50) { Value = null });
|
||||
var errorNumberParam =
|
||||
new SqlParameter("@errorNumber", SqlDbType.Int) { Direction = ParameterDirection.Output };
|
||||
cmd.Parameters.Add(errorNumberParam);
|
||||
var errorMessageParam =
|
||||
new SqlParameter("@errorMessage", SqlDbType.NVarChar, 250)
|
||||
{
|
||||
Direction = ParameterDirection.Output
|
||||
};
|
||||
cmd.Parameters.Add(errorMessageParam);
|
||||
|
||||
cmd.ExecuteNonQuery();
|
||||
if (int.Parse(errorNumberParam.Value.ToString()) != 0)
|
||||
{
|
||||
//errorMessageParam.Value
|
||||
}
|
||||
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
finally
|
||||
{
|
||||
cmd.Connection.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception) { /*APILogger.Log("Failed to delete sensor models, ", ex); */}
|
||||
LoadAllSensorModels();
|
||||
}
|
||||
private const string FILE_NAME = "Model.SensorDB.xml";
|
||||
protected void LoadAllSensorModels(string path)
|
||||
{
|
||||
var filename = System.IO.Path.Combine(path, FILE_NAME);
|
||||
if (!System.IO.File.Exists(filename))
|
||||
{
|
||||
return;
|
||||
}
|
||||
var doc = new System.Xml.XmlDocument();
|
||||
var xml = System.IO.File.ReadAllText(filename);
|
||||
doc.LoadXml(xml);
|
||||
var nodes = doc.GetElementsByTagName("SensorModels");
|
||||
foreach (var node in nodes)
|
||||
{
|
||||
if (!(node is System.Xml.XmlElement element)) { continue; }
|
||||
foreach (var childNode in element.GetElementsByTagName("SensorModel"))
|
||||
{
|
||||
if (!(childNode is System.Xml.XmlElement elem)) { continue; }
|
||||
LoadSensor(elem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void LoadAllSensorModels()
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var cmd = DbOperations.GetSQLCommand(true))
|
||||
{
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
cmd.CommandText = DbOperationsEnum.StoredProcedure.sp_SensorModelsGet.ToString();
|
||||
|
||||
#region params
|
||||
|
||||
cmd.Parameters.Add(new SqlParameter("@Model", SqlDbType.NVarChar, 50) { Value = null });
|
||||
|
||||
#endregion params
|
||||
|
||||
//cmd.ExecuteNonQuery();
|
||||
|
||||
using (var ds = DbOperations.Connection.QueryDataSet(cmd))
|
||||
{
|
||||
if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
|
||||
{
|
||||
foreach (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)
|
||||
{
|
||||
//APILogger.Log("Failed to process a row in the database: ", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
cmd.Connection.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception) { /*APILogger.Log("Failed to retrieve sensor models, ", ex); */}
|
||||
}
|
||||
|
||||
private void LoadSensor(System.Xml.XmlElement node)
|
||||
{
|
||||
try
|
||||
{
|
||||
var sm = new SensorModel(node);
|
||||
if (!_sensorModels.ContainsKey(sm.Manufacturer))
|
||||
{
|
||||
_sensorModels.Add(sm.Manufacturer, new Dictionary<string, SensorModel>());
|
||||
}
|
||||
_sensorModels[sm.Manufacturer][sm.Model] = sm;
|
||||
}
|
||||
catch (Exception) { /*APILogger.Log("failed to get node from sensor model db, ", ex); */}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace DatabaseImport
|
||||
{
|
||||
public class SensorRange : INotifyPropertyChanged
|
||||
{
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
protected bool SetProperty<T>(ref T storage, T value, string propertyName = null)
|
||||
{
|
||||
if (Equals(storage, value)) return false;
|
||||
|
||||
storage = value;
|
||||
OnPropertyChanged(propertyName);
|
||||
return true;
|
||||
}
|
||||
protected void OnPropertyChanged(string propertyName = null)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
|
||||
public double Low { get; set; }
|
||||
|
||||
public double Medium { get; set; }
|
||||
|
||||
public double High { get; set; }
|
||||
public SensorRange(string value)
|
||||
{
|
||||
var values = value.Split(',');
|
||||
if (3 != values.Length) { throw new System.IO.InvalidDataException("bad SensorRange, " + value); }
|
||||
Low = double.Parse(values[0]);
|
||||
Medium = double.Parse(values[1]);
|
||||
High = double.Parse(values[2]);
|
||||
}
|
||||
public SensorRange(double low, double medium, double high)
|
||||
{
|
||||
Low = low;
|
||||
Medium = medium;
|
||||
High = high;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,267 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
|
||||
namespace DatabaseImport
|
||||
{
|
||||
public class SensorsCollection : INotifyPropertyChanged
|
||||
{
|
||||
private readonly SensorData[] _cachedSensors = new SensorData[0];
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
protected bool SetProperty<T>(ref T storage, T value, string propertyName = null)
|
||||
{
|
||||
if (Equals(storage, value)) return false;
|
||||
|
||||
storage = value;
|
||||
OnPropertyChanged(propertyName);
|
||||
return true;
|
||||
}
|
||||
|
||||
private volatile bool _hookedup = true;
|
||||
|
||||
public bool HookedUp
|
||||
{
|
||||
get => _hookedup;
|
||||
set
|
||||
{
|
||||
_hookedup = value;
|
||||
OnPropertyChanged("AllSensors");
|
||||
}
|
||||
}
|
||||
|
||||
protected void OnPropertyChanged(string propertyName = null)
|
||||
{
|
||||
if (!HookedUp)
|
||||
{
|
||||
return;
|
||||
}
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
|
||||
private static readonly object Lock = new object();
|
||||
|
||||
public void Reload()
|
||||
{
|
||||
}
|
||||
|
||||
private static SensorsCollection _sensorCollection;
|
||||
|
||||
public static SensorsCollection SensorsList
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (Lock)
|
||||
{
|
||||
return _sensorCollection ?? (_sensorCollection = new SensorsCollection());
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// deletes all sensors
|
||||
/// originally created so TDM imports could clear all tables except DAS tables.
|
||||
/// </summary>
|
||||
public void DeleteAll()
|
||||
{
|
||||
lock (Lock)
|
||||
{
|
||||
using (var cmd = DbOperations.GetSQLCommand(true))
|
||||
{
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
cmd.CommandText = DbOperationsEnum.StoredProcedure.sp_SensorDeleteAll.ToString(); //Only used in DataPROPre20.mdf, not DataPRO.mdf
|
||||
|
||||
#region params
|
||||
|
||||
var errorNumberParam =
|
||||
new SqlParameter("@errorNumber", SqlDbType.Int) { Direction = ParameterDirection.Output };
|
||||
cmd.Parameters.Add(errorNumberParam);
|
||||
var errorMessageParam =
|
||||
new SqlParameter("@errorMessage", SqlDbType.NVarChar, 250)
|
||||
{
|
||||
Direction = ParameterDirection.Output
|
||||
};
|
||||
cmd.Parameters.Add(errorMessageParam);
|
||||
|
||||
#endregion params
|
||||
|
||||
cmd.ExecuteNonQuery();
|
||||
if (int.Parse(errorNumberParam.Value.ToString()) != 0)
|
||||
{
|
||||
//errorMessageParam.Value
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
cmd.Connection.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
//OnSensorsChanged?.Invoke(_sensorCollection.AllSensors.ToArray(), true);
|
||||
|
||||
SensorCalibrationList.DeleteAll();
|
||||
OnPropertyChanged("AllSensors");
|
||||
}
|
||||
}
|
||||
public SensorData GetSensorBySerialNumber(string serialNumber, bool excludeBroken = true, bool bUseCache = true)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(serialNumber))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
try
|
||||
{
|
||||
if (bUseCache)
|
||||
{
|
||||
var matches = from s in _cachedSensors where s.SerialNumber == serialNumber select s;
|
||||
if (matches.Any())
|
||||
{
|
||||
return matches.First();
|
||||
}
|
||||
}
|
||||
using (var cmd = DbOperations.GetSQLCommand(true))
|
||||
{
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
cmd.CommandText = DbOperationsEnum.StoredProcedure.sp_SensorsAnalogGet.ToString();
|
||||
|
||||
#region params
|
||||
|
||||
cmd.Parameters.Add(new SqlParameter("@sensorID", SqlDbType.Int) { Value = null });
|
||||
cmd.Parameters.Add(
|
||||
new SqlParameter("@SerialNumber", SqlDbType.NVarChar) { Value = serialNumber });
|
||||
|
||||
#endregion
|
||||
|
||||
var reader = cmd.ExecuteReader();
|
||||
while (reader.Read())
|
||||
{
|
||||
var sd = new SensorData(reader);
|
||||
reader.Close();
|
||||
cmd.Connection.Dispose();
|
||||
return sd;
|
||||
}
|
||||
reader.Close();
|
||||
}
|
||||
finally { cmd.Connection.Dispose(); }
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//APILogger.Log("Failed to load Sensor: ", ex);
|
||||
}
|
||||
try
|
||||
{
|
||||
using (var cmd = DbOperations.GetSQLCommand(true))
|
||||
{
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
cmd.CommandText = DbOperationsEnum.StoredProcedure.sp_SensorsDigitalInGet.ToString();
|
||||
cmd.Parameters.Add(
|
||||
new SqlParameter("@SerialNumber", SqlDbType.NVarChar, 50) { Value = serialNumber });
|
||||
cmd.Parameters.Add(new SqlParameter("@Id", SqlDbType.NVarChar, 50) { Value = null });
|
||||
var reader = cmd.ExecuteReader();
|
||||
while (reader.Read())
|
||||
{
|
||||
try
|
||||
{
|
||||
var di = new DigitalInputSetting(reader);
|
||||
reader.Close();
|
||||
return di;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//APILogger.Log(ex);
|
||||
}
|
||||
}
|
||||
reader.Close();
|
||||
}
|
||||
finally { cmd.Connection.Dispose(); }
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//APILogger.Log(ex);
|
||||
}
|
||||
try
|
||||
{
|
||||
using (var cmd = DbOperations.GetSQLCommand(true))
|
||||
{
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
cmd.CommandText = DbOperationsEnum.StoredProcedure.sp_SensorsSquibGet.ToString();
|
||||
cmd.Parameters.Add(
|
||||
new SqlParameter("@SerialNumber", SqlDbType.NVarChar, 50) { Value = serialNumber });
|
||||
cmd.Parameters.Add(new SqlParameter("@Id", SqlDbType.NVarChar, 50) { Value = null });
|
||||
var reader = cmd.ExecuteReader();
|
||||
while (reader.Read())
|
||||
{
|
||||
try
|
||||
{
|
||||
var squib = new SquibSetting(reader);
|
||||
reader.Close();
|
||||
return squib;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//APILogger.Log(ex);
|
||||
}
|
||||
}
|
||||
reader.Close();
|
||||
}
|
||||
finally { cmd.Connection.Dispose(); }
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//APILogger.Log(ex);
|
||||
}
|
||||
try
|
||||
{
|
||||
using (var cmd = DbOperations.GetSQLCommand(true))
|
||||
{
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
cmd.CommandText = DbOperationsEnum.StoredProcedure.sp_SensorsDigitalOutGet.ToString();
|
||||
cmd.Parameters.Add(
|
||||
new SqlParameter("@SerialNumber", SqlDbType.NVarChar) { Value = serialNumber });
|
||||
|
||||
var reader = cmd.ExecuteReader();
|
||||
while (reader.Read())
|
||||
{
|
||||
try
|
||||
{
|
||||
var dout = new DigitalOutputSetting(reader);
|
||||
reader.Close();
|
||||
return dout;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//APILogger.Log(ex);
|
||||
}
|
||||
}
|
||||
reader.Close();
|
||||
}
|
||||
finally { cmd.Connection.Dispose(); }
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//APILogger.Log(ex);
|
||||
}
|
||||
if (SensorData.IsTestSpecificDigitalOutSN(serialNumber))
|
||||
{
|
||||
return new DigitalOutputSetting { SerialNumber = serialNumber };
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
using System;
|
||||
using System.Data;
|
||||
|
||||
namespace DatabaseImport
|
||||
{
|
||||
public class SquibSetting : SensorData
|
||||
{
|
||||
public string SquibDescription
|
||||
{
|
||||
get => SerialNumber;
|
||||
set
|
||||
{
|
||||
SerialNumber = value;
|
||||
OnPropertyChanged("SquibDescription");
|
||||
}
|
||||
}
|
||||
|
||||
private bool _bypassCurrentFilter;
|
||||
|
||||
public bool BypassCurrentFilter
|
||||
{
|
||||
get => _bypassCurrentFilter;
|
||||
set => SetProperty(ref _bypassCurrentFilter, value, "BypassCurrentFilter");
|
||||
}
|
||||
|
||||
private bool _bypassVoltageFilter;
|
||||
|
||||
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[]
|
||||
{ExcitationVoltageOptions.ExcitationVoltageOption.Volt5};
|
||||
sd.DisplayUnit = "V";
|
||||
sd.Comment = string.IsNullOrWhiteSpace(sd.UserValue1) ? sd.SerialNumber : sd.UserValue1;
|
||||
}
|
||||
|
||||
public SquibSetting(IDataRecord reader)
|
||||
{
|
||||
try
|
||||
{
|
||||
SetDefaults(this);
|
||||
|
||||
Version = Convert.ToInt32(reader[DbOperations.Squib.Fields.Version.ToString()]);
|
||||
SquibToleranceLow = Convert.ToDouble(reader[DbOperations.Squib.Fields.SquibToleranceLow.ToString()]);
|
||||
SquibToleranceHigh = Convert.ToDouble(reader[DbOperations.Squib.Fields.SquibToleranceHigh.ToString()]);
|
||||
SquibOutputCurrent = Convert.ToDouble(reader[DbOperations.Squib.Fields.SquibOutputCurrent.ToString()]);
|
||||
SquibDescription = Convert.ToString(reader[DbOperations.Squib.Fields.SerialNumber.ToString()]);
|
||||
SquibMeasurementType =
|
||||
(SquibMeasurementType)Convert.ToInt16(
|
||||
reader[DbOperations.Squib.Fields.MeasurementType.ToString()]);
|
||||
_localOnly = Convert.ToBoolean(reader[DbOperations.Squib.Fields.LocalOnly.ToString()]);
|
||||
LimitSquibFireDuration = Convert.ToBoolean(reader[DbOperations.Squib.Fields.LimitDuration.ToString()]);
|
||||
_lastUpdatedBy = Convert.ToString(reader[DbOperations.Squib.Fields.LastModifiedBy.ToString()]);
|
||||
LastModified = Convert.ToDateTime(reader[DbOperations.Squib.Fields.LastModified.ToString()]);
|
||||
ISOCode = Convert.ToString(reader[DbOperations.Squib.Fields.ISOCode.ToString()]);
|
||||
SquibFireMode = (SquibFireMode)Convert.ToInt16(reader[DbOperations.Squib.Fields.FireMode.ToString()]);
|
||||
SquibFireDurationMS = Convert.ToDouble(reader[DbOperations.Squib.Fields.DurationMS.ToString()]);
|
||||
SquibFireDelayMS = Convert.ToDouble(reader[DbOperations.Squib.Fields.DelayMS.ToString()]);
|
||||
BypassVoltageFilter =
|
||||
Convert.ToBoolean(reader[DbOperations.Squib.Fields.BypassVoltageFilter.ToString()]);
|
||||
BypassCurrentFilter =
|
||||
Convert.ToBoolean(reader[DbOperations.Squib.Fields.BypassCurrentFilter.ToString()]);
|
||||
ArticleId = Convert.ToString(reader[DbOperations.Squib.Fields.ArticleId.ToString()]);
|
||||
UserValue1 = Convert.ToString(reader[DbOperations.Squib.Fields.UserValue1.ToString()]);
|
||||
Comment = UserValue1;
|
||||
UserValue2 = Convert.ToString(reader[DbOperations.Squib.Fields.UserValue2.ToString()]);
|
||||
UserValue3 = Convert.ToString(reader[DbOperations.Squib.Fields.UserValue3.ToString()]);
|
||||
TagsBlobBytes = reader[DbOperations.Squib.Fields.UserTags.ToString()] is DBNull
|
||||
? new byte[0]
|
||||
: (byte[])(reader[DbOperations.Squib.Fields.UserTags.ToString()]);
|
||||
Broken = Convert.ToBoolean(reader[DbOperations.Squib.Fields.Broken.ToString()]);
|
||||
DoNotUse = Convert.ToBoolean(reader[DbOperations.Squib.Fields.DoNotUse.ToString()]);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//APILogger.Log("Failed to process: ", ex);
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(Comment))
|
||||
{
|
||||
Comment = SerialNumber;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user