コード例 #1
0
        /// <summary>
        /// Writes the passed scaled value onto the underlying analog pin of the parent device.
        /// Note: The value is automatically trunacted to fit inside the BinaryScale.
        /// </summary>
        /// <typeparam name="T">Provide a MeasurementContext.</typeparam>
        /// <param name="value">The value to write onto the pin.</param>
        public void Set <T>(double value) where T : MeasurementContext, new()
        {
            T measurementContextOfValue = new T();

            if (!ConfiguredMeasurementContext.IsIdentical(measurementContextOfValue))
            {
                throw new InvalidOperationException("Configured units for the pin and units of passed value do no match.");
            }

            uint rawValue = (uint)ConfiguredMeasurementContext.Scale.ScaleValue(value, BinaryScale);

            ParentDevice.WriteAnalogOutputPin(PinID, rawValue);
        }
コード例 #2
0
ファイル: AnalogInputPin.cs プロジェクト: iobajwa/minlab-cs
        /// <summary>
        /// Reads the current analog value on the pin, scales it using the ConfiguredMeasurementContext scale.
        /// </summary>
        /// <typeparam name="T">Provide a MeasurementContext</typeparam>
        /// <returns>Scaled result.</returns>
        public double Read <T>() where T : MeasurementContext, new()
        {
            T measurementContextOfValue = new T();

            if (!ConfiguredMeasurementContext.IsIdentical(measurementContextOfValue))
            {
                throw new InvalidOperationException("Configured units for the pin and units of passed value do no match.");
            }

            uint rawValue = ParentDevice.ReadAnalogInputPin(PinID);

            return(BinaryScale.ScaleValue(rawValue, ConfiguredMeasurementContext.Scale));
        }