public static ValueOf ( MicrochipPotChannel channel ) : |
||
channel | MicrochipPotChannel | /// The MCP potentiometer channel. /// |
return |
/// <summary> /// Gets the non-volatile wiper's value. /// </summary> /// <returns> /// The non-volatile wiper's value. /// </returns> /// <remarks> /// The visibility of this method is protected because not all /// devices support non-volatile wipers. Any derived class may /// publish this method. /// </remarks> /// <exception cref="System.IO.IOException"> /// Communication with device failed or malformed result. /// </exception> /// <exception cref="InvalidOperationException"> /// The device is not capable of non-volatile wipers. /// </exception> protected Int32 GetNonVolatileValue() { if (!this.IsNonVolatileWiperCapable) { throw new InvalidOperationException("This device is not capable of non-volatile wipers!"); } return(this._controller.GetValue(DeviceControlChannel.ValueOf(this._channel), true)); }
/// <summary> /// Initializes the wiper to a defined status. For devices capable of non-volatile /// wipers, the non-volatile value is loaded. For devices not capable, the given /// value is set in the device. /// </summary> /// <param name="initialValForNonVolWipers"> /// The initial value for devices not capable of non-volatile wipers. /// </param> /// <exception cref="System.IO.IOException"> /// Communication with device failed or malformed result. /// </exception> protected void Initialize(Int32 initialValForNonVolWipers) { DeviceControlChannel ctrlchan = DeviceControlChannel.ValueOf(this._channel); if (this.IsNonVolatileWiperCapable) { this._currentValue = this._controller.GetValue(ctrlchan, false); } else { Int32 newInitialVolWiperVal = this.GetValueAccordingBoundaries(initialValForNonVolWipers); this._controller.SetValue(DeviceControlChannel.ValueOf(this._channel), newInitialVolWiperVal, MicrochipPotDeviceController.VOLATILE_WIPER); this._currentValue = newInitialVolWiperVal; } }
/// <summary> /// Increases the wiper's value by the specified number of steps. /// It is not an error if the wiper hits or already hit the upper /// boundary. In such situations, the wiper sticks to the upper /// boundary or doesn't change. /// </summary> /// <param name="steps"> /// How many steps to increase. /// </param> /// <exception cref="System.IO.IOException"> /// Communication with the device failed. /// </exception> public void Increase(Int32 steps) { Int32 maxVal = this.MaxValue; if (this._currentValue == maxVal) { return; } if (steps < 0) { throw new ArgumentException("Only positive values are permitted.", "steps"); } if (this.NonVolatileMode != MicrochipPotNonVolatileMode.VolatileOnly) { throw new InvalidOperationException("Increase only permitted for volatile-only wipers."); } // Check boundaries. Int32 actualSteps = steps; if ((steps + this._currentValue) > maxVal) { actualSteps = (maxVal - this._currentValue); } Int32 newVal = (this._currentValue + actualSteps); if ((newVal == maxVal) || (steps > 5)) { this.CurrentValue = newVal; } else { this._controller.Increase(DeviceControlChannel.ValueOf(this._channel), actualSteps); this._currentValue = newVal; } }
/// <summary> /// Enables or disables the wiper lock. /// </summary> /// <param name="enabled"> /// Set true to enable. /// </param> /// <exception cref="System.IO.IOException"> /// Communication with device failed or malformed result. /// </exception> public void SetWiperLock(Boolean enabled) { this._controller.SetWiperLock(DeviceControlChannel.ValueOf(this._channel), enabled); }
/// <summary> /// Updates the cache to the wiper's value. /// </summary> /// <returns> /// The wiper's current value. /// </returns> /// <exception cref="System.IO.IOException"> /// Communication with device failed or malformed result. /// </exception> public Int32 UpdateCacheFromDevice() { this._currentValue = this._controller.GetValue(DeviceControlChannel.ValueOf(this._channel), false); return(this._currentValue); }