/// /// 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, Stopped, SendCommandAgain, } 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()); } /// Start this operation public void Start() { controlBoard.SyncRoute(); controlBoard.SendCommand(Command.Stop, 0, /// ref. flowmeter number controlBoard.Route, /// route 0, 0, /// ref. pulses TestMethods.Diverter, 0.0f, 20, 0, StopDevs.Diverter | StopDevs.GatePulse | StopDevs.Reference | StopDevs.RegValveRegulation); opState = OpState.CheckIfStopped; } /// Run this operation /// /// Event.None or Event.PreviousStopped /// public Event Run() { if (opState == OpState.CheckIfStopped) { if (0 == (controlBoard.StatusP & StatusP.TestCompleted)) { opState = OpState.Stopped; return Event.PreviousStopped; } else { //opState = OpState.SendCommandAgain; controlBoard.SyncRoute(); controlBoard.SendCommand(Command.Stop, 0, /// ref. flowmeter number controlBoard.Route, /// route 0, 0, /// ref. pulses TestMethods.Diverter, 0.0f, 20, 0, StopDevs.Diverter | StopDevs.GatePulse | StopDevs.Reference | StopDevs.RegValveRegulation); return Event.None; } } else if (opState == OpState.Stopped) { return Event.PreviousStopped; } else if (opState == OpState.SendCommandAgain) { controlBoard.SyncRoute(); controlBoard.SendCommand(Command.Stop, 0, /// ref. flowmeter number controlBoard.Route, /// route 0, 0, /// ref. pulses TestMethods.Diverter, 0.0f, 20, 0, StopDevs.Diverter | StopDevs.GatePulse | StopDevs.Reference | StopDevs.RegValveRegulation); opState = OpState.CheckIfStopped; return Event.None; } return Event.None; } /// Stop this operation public void Stop() { opState = OpState.Idle; } } }