/* Test.Module.Channel.Sensor.ExcitationVoltage.cs Copyright © 2008 Diversified Technical Systems, Inc. All Rights Reserved */ using System; using System.ComponentModel; using DTS.Utilities; namespace DTS.DAS.Concepts { // *** see Test.cs *** public partial class Test { /// /// A container for DTS generic module concepts. /// public sealed partial class Module { // *** see Test.Module.Channel.cs *** public partial class Channel { //*** see Test.Module.Channel.Sensor.cs *** public partial class Sensor { /// /// All available excitation voltages. /// public enum ExcitationVoltageOption { /// /// undefined excitation voltage /// [VoltageMagnitude(0.0)] [Description("Undefined")] Undefined=1, /// /// 2V /// [VoltageMagnitude(2.0)] [Description("2.0")] Volt2=2, /// /// 2.5V /// [VoltageMagnitude(2.5)] [Description("2.5")] Volt2_5=4, /// /// 3.0V /// [VoltageMagnitude(3.0)] [Description("3.0")] Volt3=8, /// /// 5V /// [VoltageMagnitude( 5.0 )] [Description("5.0")] Volt5=16, /// /// 10V /// [VoltageMagnitude( 10.0 )] [Description("10.0")] Volt10=32, /// /// 1V /// [VoltageMagnitude(1.0)] [Description("1.0")] Volt1 = 64 } /// /// Converts a specified excitation voltage option into its associated numeric value. /// /// /// /// The value /// to be converted. /// /// /// /// The magnitude associated with the specified voltage option. /// /// 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 ); } } /// /// Converts a specified voltage magnitude to the associated numeric value (if it exists; /// otherwise an exception is thrown). /// /// /// /// The magnitude to be converted. /// /// /// /// The value /// associated with the specified magnitude (if it exists). /// /// 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 ); } } /// /// 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. /// [AttributeUsage(AttributeTargets.Field)] public class VoltageMagnitudeAttribute: System.Attribute { private readonly double _Value; /// /// returns voltage magnitude /// public double Value { get { return _Value; } } /// /// constructs a /// with a given value /// /// public VoltageMagnitudeAttribute(double value) { _Value = value; } } /// /// Object for manipulating voltage option enumeration-attached /// magnitude values. /// public class VoltageMagnitudeAttributeCoder : AttributeCoder { /// /// Initializes a object. /// public VoltageMagnitudeAttributeCoder() : base(attribute => attribute.Value, null) { } } } } } } }