176 lines
7.6 KiB
Plaintext
176 lines
7.6 KiB
Plaintext
/*
|
|
Test.Module.Channel.Sensor.ExcitationVoltage.cs
|
|
|
|
Copyright © 2008
|
|
Diversified Technical Systems, Inc.
|
|
All Rights Reserved
|
|
*/
|
|
|
|
using System;
|
|
using System.ComponentModel;
|
|
using DTS.Common.Enums;
|
|
using DTS.Common.Utilities;
|
|
using DTS.Common.Utilities.Logging;
|
|
|
|
namespace DTS.Common.DAS.Concepts
|
|
{
|
|
// *** 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 DTS.Common.DAS.Concepts.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="ExcitationVoltageOptions.ExcitationVoltageOption"/> value
|
|
/// to be converted.
|
|
/// </param>
|
|
///
|
|
/// <returns>
|
|
/// The <see cref="double"/> magnitude associated with the specified voltage option.
|
|
/// </returns>
|
|
///
|
|
public static double GetExcitationVoltageMagnitudeFromEnum(ExcitationVoltageOptions.ExcitationVoltageOption target)
|
|
{
|
|
try
|
|
{
|
|
return new ExcitationVoltageOptions.VoltageMagnitudeAttributeCoder().DecodeAttributeValue(target);
|
|
}
|
|
|
|
catch (Exception ex)
|
|
{
|
|
throw new ArgumentException("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="ExcitationVoltageOptions.ExcitationVoltageOption"/> value
|
|
/// associated with the specified magnitude (if it exists).
|
|
/// </returns>
|
|
///
|
|
public static ExcitationVoltageOptions.ExcitationVoltageOption GetExcitationVoltageEnumFromMagnitude(double magnitude)
|
|
{
|
|
try
|
|
{
|
|
return new ExcitationVoltageOptions.VoltageMagnitudeAttributeCoder().EncodeAttributeValue(magnitude);
|
|
}
|
|
|
|
catch (Exception ex)
|
|
{
|
|
APILogger.Log("encountered problem attempting to get excitation voltage enum from magnitude", ex);
|
|
return ExcitationVoltageOptions.ExcitationVoltageOption.Undefined;
|
|
}
|
|
}
|
|
|
|
///// <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: Attribute
|
|
//{
|
|
// /// <summary>
|
|
// /// returns voltage magnitude
|
|
// /// </summary>
|
|
// public double Value { get; }
|
|
|
|
// /// <summary>
|
|
// /// constructs a <see cref="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<ExcitationVoltageOptions.ExcitationVoltageOption, VoltageMagnitudeAttribute, double>
|
|
//{
|
|
// /// <summary>
|
|
// /// Initializes a <see cref="Test.Module.Channel.Sensor.VoltageMagnitudeAttributeCoder"/> object.
|
|
// /// </summary>
|
|
// public VoltageMagnitudeAttributeCoder()
|
|
// : base(attribute => attribute.Value, null)
|
|
// {
|
|
// }
|
|
//}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|