2015-04-15 18:32:56 +00:00
|
|
|
|
///
|
|
|
|
|
|
/// Copyright (c) 2013-2015 Sensus Metering Systems
|
|
|
|
|
|
///
|
|
|
|
|
|
using System;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
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;
|
|
|
|
|
|
|
2015-12-20 21:14:18 +00:00
|
|
|
|
///
|
|
|
|
|
|
/// Internal states of this operation
|
|
|
|
|
|
///
|
|
|
|
|
|
enum OpState
|
|
|
|
|
|
{
|
|
|
|
|
|
Idle = 0,
|
|
|
|
|
|
CheckIfStopped,
|
|
|
|
|
|
Stopped,
|
|
|
|
|
|
SendCommandAgain,
|
|
|
|
|
|
}
|
|
|
|
|
|
OpState opState;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
|
|
|
|
|
/// <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());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-12-20 21:14:18 +00:00
|
|
|
|
|
2014-07-28 07:54:35 +00:00
|
|
|
|
/// <summary>Start this operation</summary>
|
|
|
|
|
|
public void Start()
|
|
|
|
|
|
{
|
2015-07-03 07:40:34 +00:00
|
|
|
|
controlBoard.SyncRoute();
|
2014-07-28 07:54:35 +00:00
|
|
|
|
controlBoard.SendCommand(Command.Stop,
|
|
|
|
|
|
0, /// ref. flowmeter number
|
2015-07-03 07:40:34 +00:00
|
|
|
|
controlBoard.Route, /// route
|
2016-04-04 07:23:07 +00:00
|
|
|
|
0, 0, /// ref. pulses
|
2014-07-28 07:54:35 +00:00
|
|
|
|
TestMethods.Diverter,
|
|
|
|
|
|
0.0f,
|
|
|
|
|
|
20,
|
|
|
|
|
|
0,
|
|
|
|
|
|
StopDevs.Diverter | StopDevs.GatePulse | StopDevs.Reference | StopDevs.RegValveRegulation);
|
2015-12-20 21:14:18 +00:00
|
|
|
|
|
|
|
|
|
|
opState = OpState.CheckIfStopped;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2015-12-20 21:14:18 +00:00
|
|
|
|
|
2014-07-28 07:54:35 +00:00
|
|
|
|
/// <summary>Run this operation</summary>
|
|
|
|
|
|
/// <returns>
|
|
|
|
|
|
/// Event.None or Event.PreviousStopped
|
|
|
|
|
|
/// </returns>
|
|
|
|
|
|
public Event Run()
|
|
|
|
|
|
{
|
2015-12-20 21:14:18 +00:00
|
|
|
|
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
|
2016-04-04 07:23:07 +00:00
|
|
|
|
0, 0, /// ref. pulses
|
2015-12-20 21:14:18 +00:00
|
|
|
|
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
|
2016-04-04 07:23:07 +00:00
|
|
|
|
0, 0, /// ref. pulses
|
2015-12-20 21:14:18 +00:00
|
|
|
|
TestMethods.Diverter,
|
|
|
|
|
|
0.0f,
|
|
|
|
|
|
20,
|
|
|
|
|
|
0,
|
|
|
|
|
|
StopDevs.Diverter | StopDevs.GatePulse | StopDevs.Reference | StopDevs.RegValveRegulation);
|
|
|
|
|
|
|
|
|
|
|
|
opState = OpState.CheckIfStopped;
|
|
|
|
|
|
return Event.None;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return Event.None;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2015-12-20 21:14:18 +00:00
|
|
|
|
|
2014-07-28 07:54:35 +00:00
|
|
|
|
/// <summary>Stop this operation</summary>
|
|
|
|
|
|
public void Stop()
|
|
|
|
|
|
{
|
2015-12-20 21:14:18 +00:00
|
|
|
|
opState = OpState.Idle;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|