/// <summary> /// Called by the view or view model to set the fault state on the model /// </summary> /// <param name="faultState">The state to fault to</param> /// <returns>A task which completes when set fault is done </returns> public async Task SetFaultStateAsync(FaultState faultState) { var faultService = Host.GetRunTimeService <IFaultService>(); if (Host.IsConnectedToRunningGateway() && !string.IsNullOrEmpty(DutyCycleChannel) && faultService != null) { try { switch (faultState) { case FaultState.Normal: await faultService.ClearFaultAsync(DutyCycleChannel); break; case FaultState.FaultedHigh: await faultService.SetFaultValueAsync(DutyCycleChannel, 100.0); break; case FaultState.FaultedLow: await faultService.SetFaultValueAsync(DutyCycleChannel, 0.0); break; } } catch (CodedException e) { FaultCompleteFailure(e); } } }
/// <summary> /// Raises the FaultStateChanged event. Invoked when the channel value changes. /// </summary> /// <param name="newFaultState">The new fault state.</param> protected virtual void OnFaultStateChanged(FaultState newFaultState) { var faultStateChangedSubscribers = FaultStateChanged; if (faultStateChangedSubscribers != null) { faultStateChangedSubscribers(this, new FaultStateChangeEventArgs(newFaultState)); } }
/// <summary> /// Creates a new instance of the FaultStateChangeEventArgs class /// </summary> /// <param name="newFaultState">The new fault state.</param> public FaultStateChangeEventArgs(FaultState newFaultState) { FaultState = newFaultState; }