/// /// Copyright (c) 2013-2015 Sensus Metering Systems /// using System; using log4net; namespace TBF.BenchControl.Elde { public class StopPreviousOp : IOperation { private static readonly ILog log = LogManager.GetLogger(typeof(StopPreviousOp)); public override string ToString() { return string.Format("StopPreviousOp(.)"); } /// Set by the constructor readonly ControlBoardDev controlBoard; /// /// Internal states of this operation /// enum OpState { Idle = 0, CheckIfStopped, ResendCommand, Stopped, } OpState opState; /// /// Stop the previous control board operation (diverter, gate, etc.) /// Events: None or PreviousStopped /// /// Control board component reference public StopPreviousOp(ControlBoardDev controlBoardDev) { if (controlBoardDev == null) throw new ArgumentNullException("controlBoardDev"); this.controlBoard = controlBoardDev; log.Debug(this.ToString()); } void SendStopCommand() { controlBoard.SendCommand(Command.Stop, 0, 0, 0, TestMethods.Diverter, StopDevs.Diverter | StopDevs.GatePulse | StopDevs.Reference | StopDevs.RegValveRegulation); } /// Start this operation public void Start() { SendStopCommand(); opState = OpState.CheckIfStopped; } /// Run this operation /// /// Event.None or Event.PreviousStopped /// public Event Run() { if (opState == OpState.CheckIfStopped) { if ((controlBoard.StatusP & (StatusP.TestCompleted | StatusP.TestInProgress)) == 0) { opState = OpState.Stopped; return Event.PreviousStopped; } else { opState = OpState.ResendCommand; return Event.None; } } else if (opState == OpState.ResendCommand) { if ((controlBoard.StatusP & (StatusP.TestCompleted | StatusP.TestInProgress)) == 0) { opState = OpState.Stopped; return Event.PreviousStopped; } else { SendStopCommand(); opState = OpState.CheckIfStopped; return Event.None; } } else if (opState == OpState.Stopped) { return Event.PreviousStopped; } return Event.None; } /// Stop this operation public void Stop() { opState = OpState.Idle; } } }