init
This commit is contained in:
@@ -0,0 +1,147 @@
|
||||
using System;
|
||||
|
||||
namespace DatabaseExport
|
||||
{
|
||||
/// <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>
|
||||
public class DigitalInputScaleMultiplier
|
||||
{
|
||||
/// <summary>
|
||||
/// these are the different input modes for the data
|
||||
/// </summary>
|
||||
public enum InputModes
|
||||
{
|
||||
TLH = 1 << 1, //Transition Low to High
|
||||
THL = 1 << 2, //Transition High to Low
|
||||
CCNO = 1 << 3, //set to contact closure normally open
|
||||
CCNC = 1 << 4 //set to contact closure normally closed
|
||||
}
|
||||
/// <summary>
|
||||
/// the format the scaler is in
|
||||
/// </summary>
|
||||
public enum Forms { ArbitraryLowAndHigh };
|
||||
|
||||
public Forms Form { get; set; } = Forms.ArbitraryLowAndHigh;
|
||||
|
||||
// /// <summary>
|
||||
// /// for arbirary low/high, this is the low value, the value 0 should be displayed as (OFF)
|
||||
// /// </summary>
|
||||
public double DefaultValue { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// for arbitrary low/high, this is the high value, the value 1 should be displayed as (ON)
|
||||
/// </summary>
|
||||
public double ActiveValue { get; set; } = 1D;
|
||||
|
||||
// public bool SimpleEquals(DigitalInputScaleMultiplier rhs)
|
||||
// {
|
||||
// return Form == rhs.Form && DefaultValue == rhs.DefaultValue && ActiveValue == rhs.ActiveValue;
|
||||
// }
|
||||
// public override bool Equals(object obj)
|
||||
// {
|
||||
// if (obj is DigitalInputScaleMultiplier)
|
||||
// {
|
||||
// var b = obj as DigitalInputScaleMultiplier;
|
||||
// return b.Form == Form
|
||||
// && b.ActiveValue == ActiveValue
|
||||
// && b.DefaultValue == DefaultValue;
|
||||
// }
|
||||
// else { return false; }
|
||||
// }
|
||||
|
||||
// public override int GetHashCode()
|
||||
// {
|
||||
// //the idea here is to use two primes to avoid collisions, it's not perfect but should work in general and we can predict when it won't
|
||||
// if (ActiveValue == 31 || DefaultValue == 31 || DefaultValue == 79 || ActiveValue == 79)
|
||||
// {
|
||||
// return (int)Form + Convert.ToInt32(ActiveValue * 127) + Convert.ToInt32(DefaultValue * 23);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// return (int)Form + Convert.ToInt32(ActiveValue * 31) + Convert.ToInt32(DefaultValue * 79);
|
||||
// }
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// constructor and copy constructor
|
||||
// /// </summary>
|
||||
public DigitalInputScaleMultiplier()
|
||||
{
|
||||
DefaultValue = 0D;
|
||||
}
|
||||
|
||||
public DigitalInputScaleMultiplier(DigitalInputScaleMultiplier copy)
|
||||
{
|
||||
Form = copy.Form;
|
||||
DefaultValue = copy.DefaultValue;
|
||||
ActiveValue = copy.ActiveValue;
|
||||
}
|
||||
/// <summary>
|
||||
/// serializes scaler to a string
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string ToSerializeDbString()
|
||||
{
|
||||
switch (Form)
|
||||
{
|
||||
case Forms.ArbitraryLowAndHigh: return ToSerializeDbStringLowAndHigh();
|
||||
default: throw new NotSupportedException("DigitalScaleMultiplier::ToSerializeDbString unsupported form: " + Form.ToString());
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// serializes an ArbitraryLowHigh to a string
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private string ToSerializeDbStringLowAndHigh() { return string.Format("{1}{0}{2}{0}{3}", System.Globalization.CultureInfo.InvariantCulture.TextInfo.ListSeparator, Form.ToString(), DefaultValue.ToString(System.Globalization.CultureInfo.InvariantCulture), ActiveValue.ToString(System.Globalization.CultureInfo.InvariantCulture)); }
|
||||
// /// <summary>
|
||||
// /// deserializes an arbitrary low/high from a string
|
||||
// /// </summary>
|
||||
// /// <param name="tokens"></param>
|
||||
// private void FromDbSerializeStringLowAndHigh(string[] tokens)
|
||||
// {
|
||||
// if (tokens.Length < 3) { throw new NotSupportedException("DigitalInputScaleMultiplier::FromDbSerializeStringLowAndHigh invalid format for scale multiplier"); }
|
||||
// double d;
|
||||
// if (double.TryParse(tokens[1], System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out d))
|
||||
// {
|
||||
// DefaultValue = d;
|
||||
// }
|
||||
// else { throw new NotSupportedException("DigitalInputScaleMultiplier::FromDbSerializeStringLowAndHigh invalid format for low value: " + tokens[1]); }
|
||||
|
||||
// if (double.TryParse(tokens[2], System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out d))
|
||||
// {
|
||||
// ActiveValue = d;
|
||||
// }
|
||||
// else { throw new NotSupportedException("DigitalInputScaleMultiplier::FromDbSerializeStringLowAndHigh invalid format for high value: " + tokens[2]); }
|
||||
// }
|
||||
/// <summary>
|
||||
/// deserializes a scaler from a string, regardless of format
|
||||
/// </summary>
|
||||
/// <param name="s"></param>
|
||||
public void FromDbSerializeString(string s)
|
||||
{
|
||||
if (null == s)
|
||||
{
|
||||
//Utilities.Logging.APILogger.Log("Unable to serialize Db. String is null.");
|
||||
|
||||
//FIXME is this the right thing to do?
|
||||
return;
|
||||
//throw new NotSupportedException("DigitalINputScaleMultiplier::FromDbSerializeString nothing to parse");
|
||||
}
|
||||
|
||||
// string[] tokens = s.Split(new[] { System.Globalization.CultureInfo.InvariantCulture.TextInfo.ListSeparator }, StringSplitOptions.None);
|
||||
// Forms form;
|
||||
// if (Enum.TryParse(tokens[0], out form))
|
||||
// {
|
||||
// Form = form;
|
||||
// switch (form)
|
||||
// {
|
||||
// case Forms.ArbitraryLowAndHigh: FromDbSerializeStringLowAndHigh(tokens); break;
|
||||
// default: throw new NotSupportedException("DigitalInputScaleMultiplier::FromDbSerializeString unsupported form " + form.ToString());
|
||||
// }
|
||||
// }
|
||||
// else { throw new NotSupportedException("DigitalINputScaleMultiplier::FromDbSerializeString unsupported format: " + s); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,210 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace DatabaseExport
|
||||
{
|
||||
/// <summary>
|
||||
/// InitialOffset is the replacement for InitialEU
|
||||
/// it encompasses the old InitialOffset specified in EU with a method of specifying it in mV @EU
|
||||
/// Initial EU is a post data collection adjustment to engineering units recorded
|
||||
/// </summary>
|
||||
public class InitialOffset
|
||||
{
|
||||
/// <summary>
|
||||
/// copy constructor
|
||||
/// </summary>
|
||||
/// <param name="copy"></param>
|
||||
public InitialOffset(InitialOffset copy)
|
||||
{
|
||||
if (null == copy) { return; }
|
||||
_eu = copy.EU;
|
||||
_mv = copy.MV;
|
||||
_form = copy.Form;
|
||||
}
|
||||
/// <summary>
|
||||
/// default constructor
|
||||
/// </summary>
|
||||
public InitialOffset()
|
||||
{
|
||||
_form = Forms.None;
|
||||
_eu = 0D;
|
||||
_mv = 0D;
|
||||
}
|
||||
// /// <summary>
|
||||
// /// constructor for the old format Initial EU (a single double represting offset in EU)
|
||||
// /// </summary>
|
||||
// /// <param name="d"></param>
|
||||
// public InitialOffset(double d)
|
||||
// {
|
||||
// _form = Forms.EU;
|
||||
// _eu = d;
|
||||
// _mv = 0D;
|
||||
// }
|
||||
/// <summary>
|
||||
/// serializes to a db safe string
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string ToDbSerializeString()
|
||||
{
|
||||
var s = new List<string>();
|
||||
s.Add(Form.ToString());
|
||||
s.Add(EU.ToString(System.Globalization.CultureInfo.InvariantCulture));
|
||||
s.Add(MV.ToString(System.Globalization.CultureInfo.InvariantCulture));
|
||||
return string.Join(System.Globalization.CultureInfo.InvariantCulture.TextInfo.ListSeparator, s.ToArray());
|
||||
}
|
||||
|
||||
// /// <summary>
|
||||
// /// deserializes from a string suitable for db storage
|
||||
// /// </summary>
|
||||
// /// <param name="input"></param>
|
||||
public void FromDbSerializeString(string input)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(input))
|
||||
{
|
||||
Form = Forms.None;
|
||||
EU = 0;
|
||||
MV = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
var tokens = input.Split(new string[] { System.Globalization.CultureInfo.InvariantCulture.TextInfo.ListSeparator }, StringSplitOptions.None);
|
||||
|
||||
Forms form;
|
||||
|
||||
if (Enum.TryParse(tokens[0], out form))
|
||||
{
|
||||
_form = form;
|
||||
double d;
|
||||
if (tokens.Length < 3)
|
||||
{
|
||||
throw new System.IO.InvalidDataException("Invalid InitialOffset number of parameters: " + input);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (double.TryParse(tokens[1], System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out d))
|
||||
{
|
||||
_eu = d;
|
||||
}
|
||||
else { throw new FormatException("Invalid InitialOffset EU format: " + tokens[1]); }
|
||||
if (double.TryParse(tokens[2], System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out d))
|
||||
{
|
||||
_mv = d;
|
||||
}
|
||||
else { throw new FormatException("Invalid InitialOffset MV format: " + tokens[2]); }
|
||||
}
|
||||
}
|
||||
else { throw new System.IO.InvalidDataException("Invalid InitialOffset form: " + tokens[0]); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// the format Initial Offset is in
|
||||
/// </summary>
|
||||
public enum Forms
|
||||
{
|
||||
None = 0,
|
||||
EU = 1,
|
||||
EUAtMV = 2
|
||||
}
|
||||
|
||||
// /// <summary>
|
||||
// /// the format this intial offset instance is in
|
||||
// /// </summary>
|
||||
private Forms _form;
|
||||
public Forms Form
|
||||
{
|
||||
get => _form;
|
||||
set => _form = value;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// EU value. In the case of Form == EU, this is the offset in EU
|
||||
/// In. the form of EU@mV, this is the EU@mV value, and offset in EU still needs to be calculated
|
||||
/// GetInitialEUValue calculates the offset in eu
|
||||
/// this value is not used for InitialOffset format None
|
||||
/// </summary>
|
||||
private double _eu = 0;
|
||||
public double EU
|
||||
{
|
||||
get => _eu;
|
||||
set => _eu = value;
|
||||
}
|
||||
/// <summary>
|
||||
/// mV value, only applies for the format EU@mV
|
||||
/// this is the value in mV that The value in EU is observed at by a calibrated instrument
|
||||
/// </summary>
|
||||
private double _mv = 0;
|
||||
public double MV
|
||||
{
|
||||
get => _mv;
|
||||
set => _mv = value;
|
||||
}
|
||||
|
||||
// private enum Fields
|
||||
// {
|
||||
// Form,
|
||||
// EU,
|
||||
// MV
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// Displays initial offset structure to string
|
||||
// /// created for FB5429
|
||||
// /// </summary>
|
||||
// /// <param name="NONEFormatString">string resource similar to "None"</param>
|
||||
// /// <param name="EUFormatString">string resource similar to "EU"</param>
|
||||
// /// <param name="mVFormatString">string resource similar to "mV"</param>
|
||||
// /// <returns></returns>
|
||||
// public string ToDisplayString(string NONEFormatString, string EUFormatString, string mVFormatString)
|
||||
// {
|
||||
|
||||
// StringBuilder sb = new StringBuilder();
|
||||
// switch (Form)
|
||||
// {
|
||||
// case Forms.EU:
|
||||
// sb.AppendFormat("{0} {1}", EU, EUFormatString);
|
||||
// break;
|
||||
// case Forms.EUAtMV:
|
||||
// sb.AppendFormat("{0} {1} @ {2} {3}", EU, EUFormatString, MV, mVFormatString);
|
||||
// break;
|
||||
// case Forms.None:
|
||||
// sb.AppendFormat("{0}", NONEFormatString);
|
||||
// break;
|
||||
// default:
|
||||
// break;
|
||||
// }
|
||||
// return sb.ToString();
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// Compares attributes to another InitialOffset object
|
||||
// /// created for FB5429
|
||||
// /// </summary>
|
||||
// /// <param name="obj">an InitialOffset object</param>
|
||||
// /// <returns>if contents are equal</returns>
|
||||
// public override bool Equals(object obj)
|
||||
// {
|
||||
// if (obj is InitialOffset)
|
||||
// {
|
||||
// InitialOffset io = obj as InitialOffset;
|
||||
// Fields[] fields = Enum.GetValues(typeof(Fields)).Cast<Fields>().ToArray();
|
||||
// foreach (var field in fields)
|
||||
// {
|
||||
// switch (field)
|
||||
// {
|
||||
// case Fields.Form: if (io.Form != Form) { return false; } break;
|
||||
// case Fields.EU: if (io.EU != EU) { return false; } break;
|
||||
// case Fields.MV: if (io.MV != MV) { return false; } break;
|
||||
// default:
|
||||
// throw new NotSupportedException("InitialOffset::Equals Unknown field " + field.ToString());
|
||||
// }
|
||||
// }
|
||||
// return true;
|
||||
// }
|
||||
// return base.Equals(obj);
|
||||
// }
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,702 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace DatabaseExport
|
||||
{
|
||||
public class LinearizationFormula
|
||||
{
|
||||
private bool _bIsValid;
|
||||
public bool IsValid() { return _bIsValid; }
|
||||
public void MarkValid(bool bValid)
|
||||
{
|
||||
_bIsValid = bValid;
|
||||
}
|
||||
public enum Styles
|
||||
{
|
||||
IRTraccManual,
|
||||
IRTraccDiagnosticsZero,
|
||||
IRTraccZeroMMmV,
|
||||
IRTraccAverageOverTime,
|
||||
Polynomial,
|
||||
IRTraccCalFactor
|
||||
}
|
||||
// public enum SLICEWareStyles
|
||||
// {
|
||||
// Manual,
|
||||
// DiagnosticZeroMMmV,
|
||||
// ZeroMMmV,
|
||||
// AverageOverTime,
|
||||
// Polynomial
|
||||
// }
|
||||
|
||||
// // Translation
|
||||
// public SLICEWareStyles SLICEWareStyle
|
||||
// {
|
||||
// get { return (SLICEWareStyles)_style; }
|
||||
// set { _style = (Styles)value; }
|
||||
// }
|
||||
|
||||
public Styles Style { get; set; } = Styles.IRTraccDiagnosticsZero;
|
||||
|
||||
public double PolynomialSensitivity { get; set; } = 1D;
|
||||
|
||||
public double LinearizationExponent { get; set; } = 1D;
|
||||
|
||||
// THIS IS MM/V, (UI has already been updated, we need to update the variable name)
|
||||
public double MMPerV { get; set; }
|
||||
|
||||
public double MVAt0MM { get; set; }
|
||||
|
||||
public double Slope { get; set; }
|
||||
|
||||
public double Intercept { get; set; }
|
||||
|
||||
public double CalibrationFactor { get; set; }
|
||||
|
||||
public double ZeroPositionIntercept { get; set; }
|
||||
|
||||
public LinearizationFormula()
|
||||
{
|
||||
ZeroPositionIntercept = 0D;
|
||||
CalibrationFactor = 0D;
|
||||
Intercept = 0D;
|
||||
_coefficients = new List<double>(new double[] { 0, 0, 0, 0 });
|
||||
_exponents = new List<double>(new double[] { 0, 1, 2, 3 });
|
||||
}
|
||||
|
||||
public LinearizationFormula(LinearizationFormula copy)
|
||||
{
|
||||
UsemVOverVForPolys = copy.UsemVOverVForPolys;
|
||||
_bIsValid = copy._bIsValid;
|
||||
_coefficients = new List<double>(copy._coefficients.ToArray());
|
||||
_exponents = new List<double>(copy._exponents.ToArray());
|
||||
Intercept = copy.Intercept;
|
||||
LinearizationExponent = copy.LinearizationExponent;
|
||||
MMPerV = copy.MMPerV;
|
||||
MVAt0MM = copy.MVAt0MM;
|
||||
Slope = copy.Slope;
|
||||
Style = copy.Style;
|
||||
_coefficients = new List<double>(copy._coefficients);
|
||||
_exponents = new List<double>(copy._exponents);
|
||||
PolynomialSensitivity = copy.PolynomialSensitivity;
|
||||
ZeroPositionIntercept = copy.ZeroPositionIntercept;
|
||||
CalibrationFactor = copy.CalibrationFactor;
|
||||
}
|
||||
// public double GetCoefficient(double exponent)
|
||||
// {
|
||||
// for (int i = 0; i < _exponents.Count && i < _coefficients.Count; i++)
|
||||
// {
|
||||
// if (_exponents[i] == exponent) { return _coefficients[i]; }
|
||||
// }
|
||||
// return 0;
|
||||
// }
|
||||
// public void SetCoefficient(double exponent, double coefficient)
|
||||
// {
|
||||
// for (int i = 0; i < _exponents.Count && i < _coefficients.Count; i++)
|
||||
// {
|
||||
// if (_exponents[i] == exponent) { _coefficients[i] = coefficient; return; }
|
||||
// }
|
||||
// }
|
||||
// public double GetLinearizedValue(double input, double excitation)
|
||||
// {
|
||||
// if (Style != Styles.Polynomial && input <= 0)
|
||||
// {
|
||||
// //ir-tracc should never be < 0, however we may get readings less than zero due to
|
||||
// //noise and other factors, treat these as positive near to zero
|
||||
// input = .001;
|
||||
// }
|
||||
// //first linearize
|
||||
// input /= 1000D;//assume input is in mV and we want it in Volts
|
||||
// input = Math.Pow(input, LinearizationExponent);
|
||||
|
||||
// switch (Style)
|
||||
// {
|
||||
// case Styles.IRTraccDiagnosticsZero:
|
||||
// return GetEUDiagnosticsZero(input);
|
||||
// case Styles.IRTraccManual:
|
||||
// return GetEUIRTraccManual(input);
|
||||
// case Styles.IRTraccZeroMMmV:
|
||||
// return GetEUZeroMMmV(input);
|
||||
// case Styles.IRTraccAverageOverTime:
|
||||
// return GetEUAverageOverTime(input);
|
||||
// case Styles.Polynomial:
|
||||
// return GetEUPolynomial(input, excitation);
|
||||
// case Styles.IRTraccCalFactor:
|
||||
// return GetEUIRTraccCalFactor(input);
|
||||
// default:
|
||||
// throw new NotSupportedException("unknown format: " + Style.ToString());
|
||||
// }
|
||||
// }
|
||||
// private double GetEUIRTraccCalFactor(double volts)
|
||||
// {
|
||||
// return volts * CalibrationFactor + ZeroPositionIntercept;
|
||||
// }
|
||||
// private double GetEUIRTraccManual(double volts)
|
||||
// {
|
||||
// return (volts - Intercept) / Slope;
|
||||
// }
|
||||
public bool UsemVOverVForPolys { get; set; } = true;
|
||||
// private double GetEUZeroMMmV(double volts)
|
||||
// {
|
||||
// double input = MVAt0MM / 1000D;
|
||||
// input = Math.Pow(input, LinearizationExponent);
|
||||
// if (double.IsNaN(input) || double.IsNegativeInfinity(input) || double.IsPositiveInfinity(input))
|
||||
// {
|
||||
// return volts * MMPerV;
|
||||
// }
|
||||
// else { return (volts * MMPerV - MMPerV * input); }
|
||||
// }
|
||||
private List<double> _coefficients = new List<double>();
|
||||
private List<double> _exponents = new List<double>();
|
||||
// private double GetEUPolynomial(double volts, double excitation)
|
||||
// {
|
||||
// //per J2517
|
||||
// //3.4 Use of the Calibration Coefficients
|
||||
// //The potentiometer assembly should be re-installed in the dummy without any mechanical adjustment of the
|
||||
// //potentiometer. Prior to a crash test, the original zero offset level must be preserved by either not zeroing the
|
||||
// //potentiometer (by signal conditioning or post-processing) or the amount that was zeroed must be added during postprocessing.
|
||||
// //During the test the absolute voltage output time history should be recorded. This voltage signal is then
|
||||
// //converted to engineering units by:
|
||||
// //1. Convert voltage signal to mV/V at the sensor. This is the sensor reading S.
|
||||
// //2. Convert the sensor reading S to displacement D by using the equation:
|
||||
// //D = A*S^3 + B*S^2 + C*S + M (Eq. 2)
|
||||
// //where:
|
||||
// //D is the displacement relative to the thorax design position in mm
|
||||
// //S is the sensor output reading in mV/V
|
||||
// //A, B, C, and M are the calibration coefficients
|
||||
// //NOTE: Make sure to use sufficient significant digits on all coefficients to assure accuracy of the conversion to
|
||||
// //engineering units. It is recommended to use 5 significant digits (example 0.000012345).
|
||||
|
||||
// //double mV = volts * 1000D;
|
||||
// //double gain = 1D;
|
||||
// //mV = mV / (gain * excitation);
|
||||
|
||||
// //if (0 != PolynomialSensitivity && 1!= PolynomialSensitivity) { mV /= PolynomialSensitivity; }
|
||||
// //double eu = 0D;
|
||||
// //for (int i = 0; i < _coefficients.Count && i < _exponents.Count; i++)
|
||||
// //{
|
||||
// // eu += _coefficients[i] * Math.Pow(mV, _exponents[i]);
|
||||
// //}
|
||||
// //return eu;
|
||||
|
||||
// //CHANGED FOR GM TESTING
|
||||
|
||||
// if (0 != PolynomialSensitivity && 1 != PolynomialSensitivity)
|
||||
// {
|
||||
// volts /= PolynomialSensitivity;
|
||||
// }
|
||||
|
||||
// double voltsOverV = 0D;
|
||||
// if (UsemVOverVForPolys)
|
||||
// {
|
||||
// //convert to mV first
|
||||
// voltsOverV = (volts * 1000D) / excitation;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// //used by GM
|
||||
// voltsOverV = volts / excitation;
|
||||
// }
|
||||
// double eu = 0;
|
||||
|
||||
// for (int i = 0; i < _coefficients.Count && i < _exponents.Count; i++)
|
||||
// {
|
||||
// if (_exponents[i] != 0)
|
||||
// {
|
||||
// eu += _coefficients[i] * Math.Pow(voltsOverV, _exponents[i]);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// eu += _coefficients[i];
|
||||
// }
|
||||
// }
|
||||
// return eu;
|
||||
// }
|
||||
// /// <summary>
|
||||
// /// MvAt0MM set at diagnostics
|
||||
// /// </summary>
|
||||
// /// <param name="volts"></param>
|
||||
// /// <returns></returns>
|
||||
// private double GetEUDiagnosticsZero(double volts)
|
||||
// {
|
||||
// //double input = MVAt0MM/1000D;
|
||||
// //input = System.Math.Pow(input,LinearizationExponent);
|
||||
// double input = double.NaN;
|
||||
// if (double.IsNaN(input) || double.IsPositiveInfinity(input) || double.IsNegativeInfinity(input))
|
||||
// {
|
||||
// return volts * MMPerV;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// return volts * MMPerV - MMPerV * input;
|
||||
// }
|
||||
// }
|
||||
// /// <summary>
|
||||
// /// MVAt0MM set by diagnostics and then later on at
|
||||
// /// Average Over Time
|
||||
// /// </summary>
|
||||
// /// <param name="volts"></param>
|
||||
// /// <returns></returns>
|
||||
// private double GetEUAverageOverTime(double volts)
|
||||
// {
|
||||
// //double input = MVAt0MM / 1000D;
|
||||
// //input = System.Math.Pow(input, LinearizationExponent);
|
||||
// double input = double.NaN;
|
||||
// if (double.IsNaN(input) || double.IsNegativeInfinity(input) || double.IsPositiveInfinity(input))
|
||||
// {
|
||||
// return volts * MMPerV;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// return volts * MMPerV - MMPerV * input;
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
// public string ToSLICEWareSerializeString()
|
||||
// {
|
||||
// if (!_bIsValid) { return ""; }
|
||||
// StringBuilder sb = new StringBuilder();
|
||||
// sb.AppendFormat("{0}_", Style.ToString());
|
||||
|
||||
// switch (Style)
|
||||
// {
|
||||
// case Styles.IRTraccDiagnosticsZero:
|
||||
// sb.Append(ToIRTraccDiagnosticZeroString());
|
||||
// break;
|
||||
// case Styles.IRTraccManual:
|
||||
// sb.Append(ToIRTraccManualString());
|
||||
// break;
|
||||
// case Styles.IRTraccZeroMMmV:
|
||||
// sb.Append(ToIRTraccZeroMMmVString());
|
||||
// break;
|
||||
// case Styles.IRTraccAverageOverTime:
|
||||
// sb.Append(ToIRTraccAverageOverTimeString());
|
||||
// break;
|
||||
// case Styles.Polynomial:
|
||||
// sb.Append(ToSLICEWarePolynomialString());
|
||||
// break;
|
||||
// case Styles.IRTraccCalFactor:
|
||||
// throw new NotSupportedException("CalFactor not supported in SLICEWare");
|
||||
// default:
|
||||
// throw new NotSupportedException("unknown type: " + Style.ToString());
|
||||
// }
|
||||
|
||||
// return sb.ToString();
|
||||
// }
|
||||
|
||||
/// <summary>
|
||||
/// serializes to a string of the format "c0xe0 c1xe1...cnxen"
|
||||
/// this will allow us arbitrary length polynomials and fractional exponents.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string ToSerializeString()
|
||||
{
|
||||
if (!_bIsValid) { return ""; }
|
||||
var sb = new StringBuilder();
|
||||
sb.AppendFormat("{0}_", Style.ToString());
|
||||
|
||||
switch (Style)
|
||||
{
|
||||
case Styles.IRTraccDiagnosticsZero:
|
||||
sb.Append(ToIRTraccDiagnosticZeroString());
|
||||
break;
|
||||
case Styles.IRTraccManual:
|
||||
sb.Append(ToIRTraccManualString());
|
||||
break;
|
||||
case Styles.IRTraccZeroMMmV:
|
||||
sb.Append(ToIRTraccZeroMMmVString());
|
||||
break;
|
||||
case Styles.IRTraccAverageOverTime:
|
||||
sb.Append(ToIRTraccAverageOverTimeString());
|
||||
break;
|
||||
case Styles.Polynomial:
|
||||
sb.Append(ToPolynomialString());
|
||||
break;
|
||||
case Styles.IRTraccCalFactor:
|
||||
sb.Append(ToIRTraccCalFactorString());
|
||||
break;
|
||||
default:
|
||||
throw new NotSupportedException("unknown type: " + Style.ToString());
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
public string ToIRTraccDiagnosticZeroString()
|
||||
{
|
||||
return string.Format("{0}x{1}", MMPerV.ToString(System.Globalization.CultureInfo.InvariantCulture), LinearizationExponent
|
||||
.ToString(System.Globalization.CultureInfo.InvariantCulture));
|
||||
}
|
||||
public string ToIRTraccCalFactorString()
|
||||
{
|
||||
return string.Format("{0}x{1}x{2}", CalibrationFactor.ToString(System.Globalization.CultureInfo.InvariantCulture), LinearizationExponent.ToString(System.Globalization.CultureInfo.InvariantCulture),
|
||||
ZeroPositionIntercept.ToString(System.Globalization.CultureInfo.InvariantCulture));
|
||||
}
|
||||
public void FromIRTraccCalFactorString(string s, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
var tokens = s.Split('x');
|
||||
if (tokens.Length < 3) { throw new NotSupportedException("Invalid CalFactor format: " + s); }
|
||||
|
||||
CalibrationFactor = double.Parse(tokens[0], culture);
|
||||
LinearizationExponent = double.Parse(tokens[1], culture);
|
||||
ZeroPositionIntercept = double.Parse(tokens[2], culture);
|
||||
}
|
||||
public void FromIRTraccDiagnosticZeroString(string s, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
var tokens = s.Split('x');
|
||||
if (tokens.Length < 2) { throw new NotSupportedException("Invalid DiagnosticsZero format: " + s); }
|
||||
MMPerV = double.Parse(tokens[0], culture);
|
||||
LinearizationExponent = double.Parse(tokens[1], culture);
|
||||
}
|
||||
public string ToIRTraccManualString()
|
||||
{
|
||||
return string.Format("{0}x{1}x{2}", Slope.ToString(System.Globalization.CultureInfo.InvariantCulture), Intercept.ToString
|
||||
(System.Globalization.CultureInfo.InvariantCulture), LinearizationExponent.ToString(
|
||||
System.Globalization.CultureInfo.InvariantCulture));
|
||||
}
|
||||
public void FromIRTraccManualString(string s, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
var tokens = s.Split('x');
|
||||
if (tokens.Length < 3) { throw new NotSupportedException("Invalid IRTraccManual format: " + s); }
|
||||
Slope = double.Parse(tokens[0], culture);
|
||||
Intercept = double.Parse(tokens[1], culture);
|
||||
LinearizationExponent = double.Parse(tokens[2], culture);
|
||||
}
|
||||
public string ToIRTraccZeroMMmVString()
|
||||
{
|
||||
return string.Format("{0}x{1}x{2}", MMPerV.ToString(System.Globalization.CultureInfo.InvariantCulture),
|
||||
MVAt0MM.ToString(System.Globalization.CultureInfo.InvariantCulture),
|
||||
LinearizationExponent.ToString(System.Globalization.CultureInfo.InvariantCulture));
|
||||
}
|
||||
// public string ToSLICEWarePolynomialString()
|
||||
// {
|
||||
// //SLICEWare is the reverse order of our DataPRO Database
|
||||
// StringBuilder sb = new StringBuilder();
|
||||
// for (int i = _exponents.Count - 1; i >= 0; i--)
|
||||
// {
|
||||
// if (i != _exponents.Count - 1) { sb.Append(","); }
|
||||
// sb.AppendFormat("{0}x{1}", _coefficients[i].ToString(System.Globalization.CultureInfo.InvariantCulture),
|
||||
// _exponents[i].ToString(System.Globalization.CultureInfo.InvariantCulture));
|
||||
// }
|
||||
|
||||
// sb.AppendFormat(",S={0}", PolynomialSensitivity.ToString(System.Globalization.CultureInfo.InvariantCulture));
|
||||
// return sb.ToString();
|
||||
// }
|
||||
public string ToPolynomialString()
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
for (var i = 0; i < _coefficients.Count && i < _exponents.Count; i++)
|
||||
{
|
||||
if (i > 0) { sb.Append(","); }
|
||||
sb.AppendFormat("{0}x{1}", _coefficients[i].ToString(System.Globalization.CultureInfo.InvariantCulture),
|
||||
_exponents[i].ToString(System.Globalization.CultureInfo.InvariantCulture));
|
||||
}
|
||||
|
||||
sb.AppendFormat(",S={0},mV={1}",
|
||||
PolynomialSensitivity.ToString(System.Globalization.CultureInfo.InvariantCulture),
|
||||
UsemVOverVForPolys.ToString(System.Globalization.CultureInfo.InvariantCulture));
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
// public double[] PolynomialCoefficients
|
||||
// {
|
||||
// get { return _coefficients.ToArray(); }
|
||||
// set { _coefficients = new List<double>(value); }
|
||||
// }
|
||||
// public double[] PolynomialExponents
|
||||
// {
|
||||
// get { return _exponents.ToArray(); }
|
||||
// set { _exponents = new List<double>(value); }
|
||||
// }
|
||||
public string ToIRTraccAverageOverTimeString()
|
||||
{
|
||||
return string.Format("{0}x{1}", MMPerV.ToString(System.Globalization.CultureInfo.InvariantCulture),
|
||||
LinearizationExponent.ToString(System.Globalization.CultureInfo.InvariantCulture));
|
||||
}
|
||||
public void FromIRTraccAverageOverTimeString(string s, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
var tokens = s.Split('x');
|
||||
if (tokens.Length < 2) { throw new NotSupportedException("Invalid IRTRaccAverageOverTime format: " + s); }
|
||||
MMPerV = double.Parse(tokens[0], culture);
|
||||
LinearizationExponent = double.Parse(tokens[1], culture);
|
||||
}
|
||||
public void FromIRTraccZeroMMmVString(string s, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
var tokens = s.Split('x');
|
||||
if (tokens.Length < 3) { throw new NotSupportedException("Invalid IRTraccZeroMMmV format: " + s); }
|
||||
MMPerV = double.Parse(tokens[0], culture);
|
||||
MVAt0MM = double.Parse(tokens[1], culture);
|
||||
LinearizationExponent = double.Parse(tokens[2], culture);
|
||||
}
|
||||
public void FromPolynomialString(string s, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
_coefficients.Clear();
|
||||
_exponents.Clear();
|
||||
|
||||
var tokens = s.Split(',');
|
||||
foreach (var t in tokens)
|
||||
{
|
||||
var subtokens = t.Split('x');
|
||||
if (2 == subtokens.Length)
|
||||
{
|
||||
double d;
|
||||
if (double.TryParse(subtokens[0], System.Globalization.NumberStyles.Float, culture, out d))
|
||||
{
|
||||
_coefficients.Add(d);
|
||||
_exponents.Add(double.Parse(subtokens[1], culture));
|
||||
}
|
||||
else
|
||||
{
|
||||
PolynomialSensitivity = double.Parse(subtokens[1], culture);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
subtokens = t.Split('=');
|
||||
if (subtokens.Length == 2)
|
||||
{
|
||||
switch (subtokens[0])
|
||||
{
|
||||
case "S":
|
||||
PolynomialSensitivity = double.Parse(subtokens[1], culture);
|
||||
break;
|
||||
case "mV":
|
||||
UsemVOverVForPolys = Convert.ToBoolean(subtokens[1], culture);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public void FromSerializeString(string s, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
if (string.IsNullOrEmpty(s)) { _bIsValid = false; return; }
|
||||
if (s.Equals("1") || s.Equals("0") || s.Equals("1 ")) { _bIsValid = false; return; }
|
||||
|
||||
var tokens = s.Split('_');
|
||||
if (tokens.Length < 2) { throw new NotSupportedException("unsupported Linearization Formula Format"); }
|
||||
var style = (Styles)Enum.Parse(typeof(Styles), tokens[0], true);
|
||||
Style = style;
|
||||
switch (Style)
|
||||
{
|
||||
case Styles.IRTraccDiagnosticsZero:
|
||||
FromIRTraccDiagnosticZeroString(tokens[1], culture);
|
||||
_bIsValid = true;
|
||||
break;
|
||||
case Styles.IRTraccManual:
|
||||
FromIRTraccManualString(tokens[1], culture);
|
||||
_bIsValid = true;
|
||||
break;
|
||||
case Styles.IRTraccZeroMMmV:
|
||||
FromIRTraccZeroMMmVString(tokens[1], culture);
|
||||
_bIsValid = true;
|
||||
break;
|
||||
case Styles.Polynomial:
|
||||
FromPolynomialString(tokens[1], culture);
|
||||
_bIsValid = true;
|
||||
break;
|
||||
case Styles.IRTraccAverageOverTime:
|
||||
FromIRTraccAverageOverTimeString(tokens[1], culture);
|
||||
_bIsValid = true;
|
||||
break;
|
||||
case Styles.IRTraccCalFactor:
|
||||
FromIRTraccCalFactorString(tokens[1], culture);
|
||||
_bIsValid = true;
|
||||
break;
|
||||
default:
|
||||
throw new NotSupportedException("Unknown format: " + Style.ToString());
|
||||
}
|
||||
}
|
||||
public void FromSerializeString(string s)
|
||||
{
|
||||
FromSerializeString(s, System.Globalization.CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
// public void FromTDCSerializeString()
|
||||
// {
|
||||
// _bIsValid = true;
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// Will return a display string for a nonlinear calibration based on N4 formating
|
||||
// /// </summary>
|
||||
// public string ToDisplayString()
|
||||
// {
|
||||
// return ToDisplayString("N4");
|
||||
// }
|
||||
// /// <summary>
|
||||
// /// Will return a display string for a nonlinear calibration based on 1st paramater formating string
|
||||
// /// </summary>
|
||||
// /// <param name="nonlinearFormat"></param>
|
||||
// /// <returns></returns>
|
||||
// public string ToDisplayString(string nonlinearFormat)
|
||||
// {
|
||||
// if (string.IsNullOrEmpty(nonlinearFormat)) { nonlinearFormat = "N4"; }
|
||||
// switch (Style)
|
||||
// {
|
||||
// case Styles.Polynomial:
|
||||
// {
|
||||
// return ToPolynomial(nonlinearFormat);
|
||||
// }
|
||||
// case Styles.IRTraccZeroMMmV:
|
||||
// {
|
||||
// return string.Format("mV = {0:n4}, {1:n4}*(V^{2})", MVAt0MM, MMPerV, ToSuperScript(LinearizationExponent.ToString(nonlinearFormat)));
|
||||
// }
|
||||
// case Styles.IRTraccManual:
|
||||
// {
|
||||
// return string.Format("((V^{0})-{1:n4})/{2:n4}", ToSuperScript(LinearizationExponent.ToString(nonlinearFormat)), Intercept, Slope);
|
||||
// }
|
||||
// case Styles.IRTraccDiagnosticsZero:
|
||||
// {
|
||||
// return string.Format("{0:n4}*(V^{1})", MMPerV, ToSuperScript(LinearizationExponent.ToString(nonlinearFormat)));
|
||||
// }
|
||||
// case Styles.IRTraccAverageOverTime:
|
||||
// {
|
||||
// return string.Format("{0:n4}*(V^{1})", MMPerV, ToSuperScript(LinearizationExponent.ToString(nonlinearFormat)));
|
||||
// }
|
||||
// case Styles.IRTraccCalFactor:
|
||||
// {
|
||||
// return string.Format("{2:n4}+{1:n4}*(V^{0})", ToSuperScript(LinearizationExponent.ToString(nonlinearFormat)), CalibrationFactor, ZeroPositionIntercept);
|
||||
// }
|
||||
// default:
|
||||
// return string.Empty;
|
||||
// }
|
||||
// }
|
||||
// private string ToPolynomial(string nonlinearFormat)
|
||||
// {
|
||||
// if (string.IsNullOrEmpty(nonlinearFormat)) { nonlinearFormat = "N4"; }
|
||||
|
||||
// StringBuilder sb = new StringBuilder();
|
||||
|
||||
// int termNumber = PolynomialCoefficients.Length - 1;
|
||||
// foreach (var x in PolynomialCoefficients)
|
||||
// {
|
||||
// if (PolynomialCoefficients[termNumber] != 0)
|
||||
// {
|
||||
// double coeff = PolynomialCoefficients[termNumber];
|
||||
|
||||
// // Let the appended math symbol handle sign unless we're the first term.
|
||||
// if (termNumber != PolynomialCoefficients.Length - 1)
|
||||
// {
|
||||
// coeff = Math.Abs(coeff);
|
||||
// }
|
||||
// sb.Append(coeff.ToString(nonlinearFormat));
|
||||
// if (PolynomialExponents[termNumber] != 0)
|
||||
// {
|
||||
// sb.Append("x");
|
||||
// if (PolynomialExponents[termNumber] != 1)
|
||||
// {
|
||||
// sb.Append(ToSuperScript(PolynomialExponents[termNumber].ToString("N0")));
|
||||
// }
|
||||
// }
|
||||
// if (termNumber > 0)
|
||||
// {
|
||||
// // Coerricients are Displayed in absolute value. We need to combine the sign with the addition symbol
|
||||
// sb.Append(PolynomialCoefficients[termNumber - 1] > 0 ? " + " : " - ");
|
||||
// }
|
||||
// }
|
||||
// termNumber--;
|
||||
// }
|
||||
|
||||
// return sb.ToString();
|
||||
// }
|
||||
// private string ToSuperScript(string source)
|
||||
// {
|
||||
// StringBuilder superScript = new StringBuilder();
|
||||
|
||||
// foreach (char c in source)
|
||||
// {
|
||||
// switch (c)
|
||||
// {
|
||||
// case '-':
|
||||
// superScript.Append('\u207B');
|
||||
// break;
|
||||
// case '.':
|
||||
// superScript.Append('\u00B7');
|
||||
// break;
|
||||
// case '1':
|
||||
// superScript.Append('\u00B9');
|
||||
// break;
|
||||
// case '2':
|
||||
// superScript.Append('\u00B2');
|
||||
// break;
|
||||
// case '3':
|
||||
// superScript.Append('\u00B3');
|
||||
// break;
|
||||
// case '4':
|
||||
// superScript.Append('\u2074');
|
||||
// break;
|
||||
// case '5':
|
||||
// superScript.Append('\u2075');
|
||||
// break;
|
||||
// case '6':
|
||||
// superScript.Append('\u2076');
|
||||
// break;
|
||||
// case '7':
|
||||
// superScript.Append('\u2077');
|
||||
// break;
|
||||
// case '8':
|
||||
// superScript.Append('\u2078');
|
||||
// break;
|
||||
// case '9':
|
||||
// superScript.Append('\u2079');
|
||||
// break;
|
||||
// case '0':
|
||||
// superScript.Append('\u2070');
|
||||
// break;
|
||||
// case '\'':
|
||||
// superScript.Append('\u02C8');
|
||||
// break;
|
||||
// case ',':
|
||||
// superScript.Append('\u22C5'); // there is no unicode superscript comma. this comes close
|
||||
// break;
|
||||
// case '\u00A0':
|
||||
// superScript.Append('\u2009'); // unicode 'thin' space
|
||||
// break;
|
||||
// default:
|
||||
// superScript.Append('\u207F');
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
|
||||
// return superScript.ToString();
|
||||
// }
|
||||
// /*
|
||||
// * we are given an equation in the form of y = ax^1 + b, except x and y are backwards for us (y=V where we'd prefer X was voltage, so we switch it)
|
||||
// * y/a - b/a = x, and then switch y and x, (1/a)x^1 -(b/a)x^0 = y
|
||||
// * now we want to get the coefficient of the first equation, which is "a", we get this by taking the inverse
|
||||
// * we get b on the other hand by taking -1 * (b/a)*a. if we have the "coefficient", we have a
|
||||
// */
|
||||
// /*
|
||||
// public double GetIRTraccCoefficient()
|
||||
// {
|
||||
// foreach (Factor f in Factors)
|
||||
// {
|
||||
// if (f.Exponent == 1D) { return System.Math.Pow(f.Coefficient, -1); }
|
||||
// }
|
||||
// return 1D; //0 doesn't make sense for ir
|
||||
// }
|
||||
// public double GetIRTraccConstant()
|
||||
// {
|
||||
// foreach (Factor f in Factors)
|
||||
// {
|
||||
// if (f.Exponent == 0D) { return -1D * GetIRTraccCoefficient() * f.Coefficient; }
|
||||
// }
|
||||
// return 0D;
|
||||
// }
|
||||
// public void SetIRTraccFactor(double coefficient, double constant)
|
||||
// {
|
||||
// if (0 == coefficient)
|
||||
// {
|
||||
// //well this doesn't make any sense ...
|
||||
// coefficient = 1;
|
||||
// }
|
||||
// Factors = new Factor[]
|
||||
// {
|
||||
// new Factor(1/coefficient,1),
|
||||
// new Factor(-constant/coefficient,0),
|
||||
// };
|
||||
// }*/
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
Test.Module.Channel.Sensor.Bridge.cs
|
||||
|
||||
Copyright © 2008
|
||||
Diversified Technical Systems, Inc.
|
||||
All Rights Reserved
|
||||
*/
|
||||
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace DatabaseExport
|
||||
{
|
||||
// *** see Test.cs ***
|
||||
public partial class Test
|
||||
{
|
||||
/// <summary>
|
||||
/// A container for DTS generic module concepts.
|
||||
/// </summary>
|
||||
public sealed partial class Module
|
||||
{
|
||||
// *** see Test.Module.Channel.cs ***
|
||||
public partial class Channel
|
||||
{
|
||||
//*** see Test.Module.Channel.Sensor.cs ***
|
||||
public partial class Sensor
|
||||
{
|
||||
/// <summary>
|
||||
/// All available bridge types.
|
||||
/// </summary>
|
||||
public enum BridgeType
|
||||
{
|
||||
/// <summary>
|
||||
/// sensor uses IEPE setup
|
||||
/// </summary>
|
||||
[Description("IEPE")]
|
||||
IEPE = 1 << 0,
|
||||
/// <summary>
|
||||
/// sensor uses quarter bridge setup
|
||||
/// </summary>
|
||||
[Description("Quarter")]
|
||||
QuarterBridge = 1 << 1,
|
||||
/// <summary>
|
||||
/// sensor uses half bridge setup
|
||||
/// </summary>
|
||||
[Description("Bridge-Half")]
|
||||
HalfBridge = 1 << 2,
|
||||
/// <summary>
|
||||
/// sensor has a full bridge setup
|
||||
/// </summary>
|
||||
[Description("Bridge-Full")]
|
||||
FullBridge = 1 << 3,
|
||||
[Description("DigitalInput")]
|
||||
DigitalInput = 1 << 4,
|
||||
[Description("SQUIB")]
|
||||
SQUIB = 1 << 5,
|
||||
[Description("TOMDigital")]
|
||||
TOMDigital = 1 << 6
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,171 @@
|
||||
/*
|
||||
Test.Module.Channel.Sensor.ExcitationVoltage.cs
|
||||
|
||||
Copyright © 2008
|
||||
Diversified Technical Systems, Inc.
|
||||
All Rights Reserved
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace DatabaseExport
|
||||
{
|
||||
// *** see Test.cs ***
|
||||
public partial class Test
|
||||
{
|
||||
/// <summary>
|
||||
/// A container for DTS generic module concepts.
|
||||
/// </summary>
|
||||
public sealed partial class Module
|
||||
{
|
||||
// *** see Test.Module.Channel.cs ***
|
||||
public partial class Channel
|
||||
{
|
||||
//*** see Test.Module.Channel.Sensor.cs ***
|
||||
public partial class Sensor
|
||||
{
|
||||
/// <summary>
|
||||
/// All available excitation voltages.
|
||||
/// </summary>
|
||||
public enum ExcitationVoltageOption
|
||||
{
|
||||
/// <summary>
|
||||
/// undefined excitation voltage
|
||||
/// </summary>
|
||||
[VoltageMagnitude(0.0)]
|
||||
[Description("Undefined")]
|
||||
Undefined = 1,
|
||||
/// <summary>
|
||||
/// 2V
|
||||
/// </summary>
|
||||
[VoltageMagnitude(2.0)]
|
||||
[Description("2.0")]
|
||||
Volt2 = 2,
|
||||
/// <summary>
|
||||
/// 2.5V
|
||||
/// </summary>
|
||||
[VoltageMagnitude(2.5)]
|
||||
[Description("2.5")]
|
||||
Volt2_5 = 4,
|
||||
/// <summary>
|
||||
/// 3.0V
|
||||
/// </summary>
|
||||
[VoltageMagnitude(3.0)]
|
||||
[Description("3.0")]
|
||||
Volt3 = 8,
|
||||
/// <summary>
|
||||
/// 5V
|
||||
/// </summary>
|
||||
[VoltageMagnitude(5.0)]
|
||||
[Description("5.0")]
|
||||
Volt5 = 16,
|
||||
/// <summary>
|
||||
/// 10V
|
||||
/// </summary>
|
||||
[VoltageMagnitude(10.0)]
|
||||
[Description("10.0")]
|
||||
Volt10 = 32,
|
||||
/// <summary>
|
||||
/// 1V
|
||||
/// </summary>
|
||||
[VoltageMagnitude(1.0)]
|
||||
[Description("1.0")]
|
||||
Volt1 = 64
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a specified excitation voltage option into its associated numeric value.
|
||||
/// </summary>
|
||||
///
|
||||
/// <param name="target">
|
||||
/// The <see cref="DTS.DAS.Concepts.Test.Module.Channel.Sensor.ExcitationVoltageOption"/> value
|
||||
/// to be converted.
|
||||
/// </param>
|
||||
///
|
||||
/// <returns>
|
||||
/// The <see cref="double"/> magnitude associated with the specified voltage option.
|
||||
/// </returns>
|
||||
///
|
||||
public static double GetExcitationVoltageMagnitudeFromEnum(ExcitationVoltageOption target)
|
||||
{
|
||||
try
|
||||
{
|
||||
return new VoltageMagnitudeAttributeCoder().DecodeAttributeValue(target);
|
||||
}
|
||||
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception("encountered problem attempting to get excitation voltage magnitude from enum", ex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a specified voltage magnitude to the associated numeric value (if it exists;
|
||||
/// otherwise an exception is thrown).
|
||||
/// </summary>
|
||||
///
|
||||
/// <param name="magnitude">
|
||||
/// The <see cref="double"/> magnitude to be converted.
|
||||
/// </param>
|
||||
///
|
||||
/// <returns>
|
||||
/// The <see cref="DTS.DAS.Concepts.Test.Module.Channel.Sensor.ExcitationVoltageOption"/> value
|
||||
/// associated with the specified magnitude (if it exists).
|
||||
/// </returns>
|
||||
///
|
||||
public static ExcitationVoltageOption GetExcitationVoltageEnumFromMagnitude(double magnitude)
|
||||
{
|
||||
try
|
||||
{
|
||||
return new VoltageMagnitudeAttributeCoder().EncodeAttributeValue(magnitude);
|
||||
}
|
||||
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
throw new NotSupportedException("encountered problem attempting to get excitation voltage enum from magnitude", ex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attribute for specifying the numerical magnitude of the attached field's
|
||||
/// "representation". Intended to be used with enumerations whose members represent
|
||||
/// voltage magnitude options so that the enum item can have a corresponding numerical
|
||||
/// value that can be extracted and used in calculations.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Field)]
|
||||
public class VoltageMagnitudeAttribute : System.Attribute
|
||||
{
|
||||
/// <summary>
|
||||
/// returns voltage magnitude
|
||||
/// </summary>
|
||||
public double Value { get; }
|
||||
|
||||
/// <summary>
|
||||
/// constructs a <see cref="DTS.DAS.Concepts.Test.Module.Channel.Sensor.VoltageMagnitudeAttribute" />
|
||||
/// with a given value
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
public VoltageMagnitudeAttribute(double value) { Value = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Object for manipulating voltage option enumeration-attached
|
||||
/// <see cref="double"/> magnitude values.
|
||||
/// </summary>
|
||||
public class VoltageMagnitudeAttributeCoder
|
||||
: AttributeCoder<ExcitationVoltageOption, VoltageMagnitudeAttribute, double>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a <see cref="DTS.DAS.Concepts.Test.Module.Channel.Sensor.VoltageMagnitudeAttributeCoder"/> object.
|
||||
/// </summary>
|
||||
public VoltageMagnitudeAttributeCoder()
|
||||
: base(attribute => attribute.Value, null)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
Test.Module.Channel.Sensor.ExcitationVoltage.cs
|
||||
|
||||
Copyright © 2008
|
||||
Diversified Technical Systems, Inc.
|
||||
All Rights Reserved
|
||||
*/
|
||||
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace DatabaseExport
|
||||
{
|
||||
// *** see Test.cs ***
|
||||
public partial class Test
|
||||
{
|
||||
/// <summary>
|
||||
/// A container for DTS generic module concepts.
|
||||
/// </summary>
|
||||
public sealed partial class Module
|
||||
{
|
||||
// *** see Test.Module.Channel.cs ***
|
||||
public partial class Channel
|
||||
{
|
||||
//*** see Test.Module.Channel.Sensor.cs ***
|
||||
public partial class Sensor
|
||||
{
|
||||
/// <summary>
|
||||
/// All available Sensitivity Unit types.
|
||||
/// </summary>
|
||||
public enum SensUnits
|
||||
{
|
||||
/// <summary>
|
||||
/// No Sensitivity Units (Polynomial Sensor)
|
||||
/// </summary>
|
||||
[Description("NONE")]
|
||||
NONE = 0,
|
||||
/// <summary>
|
||||
/// Sensitivity expressed in mV with output at Capacity EU
|
||||
/// </summary>
|
||||
[Description("mV")]
|
||||
mV = 1,
|
||||
/// <summary>
|
||||
/// Excitation proportional sensitivity expressed in mV/V with output at Capacity EU
|
||||
/// </summary>
|
||||
[Description("mV/V")]
|
||||
mVperV = 2,
|
||||
/// <summary>
|
||||
/// Excitation proportional sensitivity expressed in mV/V/EU
|
||||
/// </summary>
|
||||
[Description("mV/V/EU")]
|
||||
mVperVperEU = 3,
|
||||
/// <summary>
|
||||
/// Sensitivity expressed in mV/EU
|
||||
/// </summary>
|
||||
[Description("mV/EU")]
|
||||
mVperEU = 4
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
Test.Module.Channel.Sensor.ZeroMethod.cs
|
||||
|
||||
Copyright © 2008
|
||||
Diversified Technical Systems, Inc.
|
||||
All Rights Reserved
|
||||
*/
|
||||
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace DatabaseExport
|
||||
{
|
||||
// *** see Test.cs ***
|
||||
public partial class Test
|
||||
{
|
||||
/// <summary>
|
||||
/// A container for DTS generic module concepts.
|
||||
/// </summary>
|
||||
public sealed partial class Module
|
||||
{
|
||||
// *** see Test.Module.Channel.cs ***
|
||||
public partial class Channel
|
||||
{
|
||||
//*** see Test.Module.Channel.Sensor.cs ***
|
||||
public partial class Sensor
|
||||
{
|
||||
/// <summary>
|
||||
/// All available zero method types.
|
||||
/// </summary>
|
||||
public enum ZeroMethodType
|
||||
{
|
||||
// Lots of legacy compatibility (e.g. importing GM ISF) depends on the order/value of this enum.
|
||||
|
||||
/// <summary>
|
||||
/// calculate electrical zero using an average over time
|
||||
/// </summary>
|
||||
[Description("Average Over Time")]
|
||||
AverageOverTime = 0,
|
||||
/// <summary>
|
||||
/// calculate zero using time in pre-event
|
||||
/// </summary>
|
||||
[Description("Use Diagnostics Zero")]
|
||||
UsePreEventDiagnosticsZero = 1,
|
||||
/// <summary>
|
||||
/// calculate zero using injected value
|
||||
/// </summary>
|
||||
[Description("Absolute Zero")]
|
||||
None = 2
|
||||
}
|
||||
/// <summary>
|
||||
/// Original version of all available zero method types.
|
||||
/// </summary>
|
||||
public enum OriginalZeroMethodType
|
||||
{
|
||||
/// <summary>
|
||||
/// calculate electrical zero using an average over time
|
||||
/// </summary>
|
||||
[Description("Average Over Time")]
|
||||
AverageOverTime,
|
||||
/// <summary>
|
||||
/// calculate zero using time in pre-event
|
||||
/// </summary>
|
||||
[Description("Use Diagnostics Zero")]
|
||||
UsePreCalZero,
|
||||
/// <summary>
|
||||
/// calculate zero using injected value
|
||||
/// </summary>
|
||||
[Description("Absolute Zero")]
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user