tbf/TestBenchFramework/BenchControl/Elde/StopPreviousOp.cs

124 lines
3.3 KiB
C#
Raw Normal View History

///
/// 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;
/// <summary>
/// Stop the previous control board operation (diverter, gate, etc.)
/// Events: None or PreviousStopped
/// </summary>
/// <param name="controlBoardDev">Control board component reference</param>
public StopPreviousOp(ControlBoardDev controlBoardDev)
{
if (controlBoardDev == null) throw new ArgumentNullException("controlBoardDev");
this.controlBoard = controlBoardDev;
log.Debug(this.ToString());
}
/// <summary>Start this operation</summary>
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;
}
/// <summary>Run this operation</summary>
/// <returns>
/// Event.None or Event.PreviousStopped
/// </returns>
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;
}
/// <summary>Stop this operation</summary>
public void Stop()
{
opState = OpState.Idle;
}
}
}