TankDraining sequence conditions added (MettlerToledo scales).

This commit is contained in:
Milan Hanajik 2017-05-05 14:18:15 +02:00
parent ed83ae57c5
commit f0140e2bd1
3 changed files with 74 additions and 50 deletions

View File

@ -22,7 +22,7 @@ namespace TBF.BenchControl.MettlerToledo
TankClosed,
}
public class TankDraining : ComponentBase, ITankDraining
public class TankDraining : ComponentBase, ITankDraining, ISequenceCondition
{
private static readonly ILog log = LogManager.GetLogger(typeof(TankDraining));
@ -32,8 +32,9 @@ namespace TBF.BenchControl.MettlerToledo
private IValve drainValve;
public GenericDevices.IValve DrainValve { get { return drainValve; } }
private IOperation openDrainValveOp;
private IOperation closeDrainValveOp;
private IOperation openTheDrainValveOp;
private IOperation closeTheDrainValveOp;
private IOperation waitTankEmptyOp;
DrainState drainState;
@ -42,7 +43,9 @@ namespace TBF.BenchControl.MettlerToledo
public TankDraining()
: base()
{
CreateConditions(false);
openTheDrainValveOp = null;
closeTheDrainValveOp = null;
waitTankEmptyOp = null;
}
public TankDraining(Generic.IComponentCfg cfg)
@ -50,14 +53,19 @@ namespace TBF.BenchControl.MettlerToledo
{
tankDrainingCfg = cfg as GenericDevices.ITankDrainingCfg;
if (tankDrainingCfg == null) throw new Exception(string.Format("Cannot create component {0}", cfg.Name));
CreateConditions(true);
openTheDrainValveOp = null;
closeTheDrainValveOp = null;
waitTankEmptyOp = null;
}
protected void Initalize()
{
drainValve = TbfComponents.FindComponent(tankDrainingCfg.DrainValve) as IValve;
openDrainValveOp = new Elde.SetValvesOp(StateMachine.ControlBoard, drainValve, null);
closeDrainValveOp = new Elde.SetValvesOp(StateMachine.ControlBoard, null, drainValve);
openTheDrainValveOp = new Elde.SetValvesOp(StateMachine.ControlBoard, drainValve, null);
closeTheDrainValveOp = new Elde.SetValvesOp(StateMachine.ControlBoard, null, drainValve);
waitTankEmptyOp = new WaitTankEmptyOp(this);
}
protected void RunBefore()
@ -65,16 +73,16 @@ namespace TBF.BenchControl.MettlerToledo
switch (drainState)
{
case DrainState.OpeningDV_Start:
openDrainValveOp.Start();
openTheDrainValveOp.Start();
drainState = DrainState.OpeningDV_Run;
return;
case DrainState.OpeningDV_Run:
if (openDrainValveOp.Run() == Event.ValvesSet) drainState = DrainState.OpeningDV_Stop;
if (openTheDrainValveOp.Run() == Event.ValvesSet) drainState = DrainState.OpeningDV_Stop;
return;
case DrainState.OpeningDV_Stop:
openDrainValveOp.Stop();
openTheDrainValveOp.Stop();
return;
case DrainState.Draining:
@ -82,16 +90,16 @@ namespace TBF.BenchControl.MettlerToledo
return;
case DrainState.ClosingDV_Start:
closeDrainValveOp.Start();
closeTheDrainValveOp.Start();
drainState = DrainState.ClosingDV_Run;
return;
case DrainState.ClosingDV_Run:
if (closeDrainValveOp.Run() == Event.ValvesSet) drainState = DrainState.ClosingDV_Stop;
if (closeTheDrainValveOp.Run() == Event.ValvesSet) drainState = DrainState.ClosingDV_Stop;
return;
case DrainState.ClosingDV_Stop:
closeDrainValveOp.Stop();
closeTheDrainValveOp.Stop();
return;
default:
@ -105,52 +113,32 @@ namespace TBF.BenchControl.MettlerToledo
public virtual string GetName() { return string.Empty; }
public virtual bool IsEmpty() { return false; }
///
/// ISequenceCondition interface implementation (conditions in transition sequences)
///
IList<string> sequenceConditionNames;
IList<IOperation> sequenceConditions;
public int ConditionsCount { get { return sequenceConditions != null ? sequenceConditions.Count : 0; } }
public int ConditionsCount { get { return 3; } }
/// Strings are added to the combo-box for transition sequence condition selection
public string ConditionName(int i)
{
if (sequenceConditionNames != null && i < sequenceConditionNames.Count && i >= 0)
return sequenceConditionNames[i];
else
return string.Empty;
switch (i)
{
case 0: return string.Format(Strings._0_open_the_drain_valve, Name);
case 1: return string.Format(Strings._0_close_the_drain_valve, Name);
case 2: return string.Format(Strings._0_wait_until_the_tank_is_empty, Name);
default: return string.Empty;
}
}
/// Operations are executed as a part of a transition sequence
/// Operation to be executed as a part of a transition sequence
public IOperation ConditionOp(int i)
{
if (sequenceConditions != null && i < sequenceConditions.Count && i >= 0)
return sequenceConditions[i];
else
return null;
}
void ClearConditions()
{
sequenceConditionNames = new List<string>();
sequenceConditions = new List<IOperation>();
}
void AddCondition(string conditionName, bool createOperation, IOperation conditionOperation)
{
sequenceConditionNames.Add(conditionName);
if (createOperation) sequenceConditions.Add(conditionOperation);
}
/// <summary>
/// Create a list of conditions
/// </summary>
/// <param name="createOps">true = create names and condition operations, false = create names only</param>
void CreateConditions(bool createOps)
{
ClearConditions();
AddCondition(string.Format(Strings.Wait_until_0_tank_is_empty, GetName()), createOps, new WaitTankEmptyOp(this));
switch (i)
{
case 0: return openTheDrainValveOp;
case 1: return closeTheDrainValveOp;
case 2: return waitTankEmptyOp;
default: return null;
}
}
}
}

View File

@ -60,6 +60,33 @@ namespace TBF.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to {0} - close the drain valve.
/// </summary>
internal static string _0_close_the_drain_valve {
get {
return ResourceManager.GetString("_0_close_the_drain_valve", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to {0} - open the drain valve.
/// </summary>
internal static string _0_open_the_drain_valve {
get {
return ResourceManager.GetString("_0_open_the_drain_valve", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to {0} - wait until the tank is empty.
/// </summary>
internal static string _0_wait_until_the_tank_is_empty {
get {
return ResourceManager.GetString("_0_wait_until_the_tank_is_empty", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to &lt;none&gt;.
/// </summary>

View File

@ -1747,4 +1747,13 @@
<data name="Close_the_cover" xml:space="preserve">
<value>Close the cover</value>
</data>
<data name="_0_close_the_drain_valve" xml:space="preserve">
<value>{0} - close the drain valve</value>
</data>
<data name="_0_open_the_drain_valve" xml:space="preserve">
<value>{0} - open the drain valve</value>
</data>
<data name="_0_wait_until_the_tank_is_empty" xml:space="preserve">
<value>{0} - wait until the tank is empty</value>
</data>
</root>