Files
DP44/Common/DTS.Common.DAS.Concepts/.svn/pristine/1d/1d92347339b358a994ffc59df84d5a89c31e61ae.svn-base
2026-04-17 14:55:32 -04:00

173 lines
7.3 KiB
Plaintext

/*
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
{
/// <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
{
private readonly double _Value;
/// <summary>
/// returns voltage magnitude
/// </summary>
public double Value { get { return _Value; } }
/// <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)
{
}
}
}
}
}
}
}