Draining management under construction

This commit is contained in:
Milan Hanajik 2017-03-27 23:05:02 +02:00
parent 439d98f99d
commit 8fb021da4c
13 changed files with 242 additions and 37 deletions

View File

@ -510,7 +510,7 @@ ControlComponent_Izrael2014.UserControl1 ctrlBrdComponent,
/// <returns>Created operation</returns>
public IOperation SetValvesOp(IValve valveOpen, IValve valveClose)
{
return new Valve.SetValvesOp(this, valveOpen, valveClose);
return new SetValvesOp(this, valveOpen, valveClose);
}
/// <summary>
@ -522,7 +522,7 @@ ControlComponent_Izrael2014.UserControl1 ctrlBrdComponent,
/// <returns>Created operation</returns>
public IOperation SetValvesOp(IList<IValve> valvesOpen, IList<IValve> valvesClose)
{
return new Valve.SetValvesOp(this, valvesOpen, valvesClose);
return new SetValvesOp(this, valvesOpen, valvesClose);
}
/// <summary>

View File

@ -1,5 +1,5 @@
///
/// Copyright (c) 2013-2016 Sensus Metering Systems
/// Copyright (c) 2013-2017 Sensus Metering Systems
///
using System;
using System.Collections.Generic;
@ -7,7 +7,7 @@ using log4net;
using TBF.BenchControl.GenericDevices;
using Dirichlet.Numerics;
namespace TBF.BenchControl.Elde.Valve
namespace TBF.BenchControl.Elde
{
public class SetValvesOp : IOperation
{
@ -21,8 +21,8 @@ namespace TBF.BenchControl.Elde.Valve
public int TimeSec; /// Relative time in [s] from the start of the operation
public IList<IValve> VOpen; /// List of valves to open in this point of time
public IList<IValve> VClose; /// List of valves to close in this point of time
public UInt128 MasksOpen; /// OR-ed bitmasks of valves to open in this point of time
public UInt128 MasksClose; /// OR-ed bitmasks of valves to close in this point of time
public UInt128 MasksOpen; /// OR-ed bitmasks of valves to open in this point of time
public UInt128 MasksClose; /// OR-ed bitmasks of valves to close in this point of time
public SwitchPoint(int time, IList<IValve> vOpen, IList<IValve> vClose)
{
@ -42,9 +42,9 @@ namespace TBF.BenchControl.Elde.Valve
foreach (var vlv in VOpen)
{
/// Skip the delay evaluation and update in case the valve/pump have not changed
if (vlv is Valve && ((vlv as Valve).Mask & changed) == 0) continue;
if (vlv is Pump.Pump && ((vlv as Pump.Pump).Mask & changed) == 0) continue;
if (vlv is PumpWithFM.Pump && ((vlv as PumpWithFM.Pump).Mask & changed) == 0) continue;
if (vlv is Valve.Valve && ((vlv as Valve.Valve).Mask & changed) == 0) continue;
if (vlv is Pump.Pump && ((vlv as Pump.Pump).Mask & changed) == 0) continue;
if (vlv is PumpWithFM.Pump && ((vlv as PumpWithFM.Pump).Mask & changed) == 0) continue;
if (vlv is Danfoss.VLT2800.Pump && ((vlv as Danfoss.VLT2800.Pump).Mask & changed) == 0) continue;
if ((vlv != null) && (vlv.Delay > max)) max = vlv.Delay;
@ -52,9 +52,9 @@ namespace TBF.BenchControl.Elde.Valve
foreach (var vlv in VClose)
{
/// Skip the delay evaluation and update in case the valve/pump have not changed
if (vlv is Valve && ((vlv as Valve).Mask & changed) == 0) continue;
if (vlv is Pump.Pump && ((vlv as Pump.Pump).Mask & changed) == 0) continue;
if (vlv is PumpWithFM.Pump && ((vlv as PumpWithFM.Pump).Mask & changed) == 0) continue;
if (vlv is Valve.Valve && ((vlv as Valve.Valve).Mask & changed) == 0) continue;
if (vlv is Pump.Pump && ((vlv as Pump.Pump).Mask & changed) == 0) continue;
if (vlv is PumpWithFM.Pump && ((vlv as PumpWithFM.Pump).Mask & changed) == 0) continue;
if (vlv is Danfoss.VLT2800.Pump && ((vlv as Danfoss.VLT2800.Pump).Mask & changed) == 0) continue;
if ((vlv != null) && (vlv.Delay > max)) max = vlv.Delay;
@ -152,20 +152,20 @@ namespace TBF.BenchControl.Elde.Valve
point.MasksOpen = 0;
foreach (var valve in point.VOpen)
{
if (valve is Valve) point.MasksOpen |= (valve as Valve).Mask;
if (valve is Pump.Pump) point.MasksOpen |= (valve as Pump.Pump).Mask;
if (valve is PumpWithFM.Pump) point.MasksOpen |= (valve as PumpWithFM.Pump).Mask;
if (valve is Valve.Valve) point.MasksOpen |= (valve as Valve.Valve).Mask;
if (valve is Pump.Pump) point.MasksOpen |= (valve as Pump.Pump).Mask;
if (valve is PumpWithFM.Pump) point.MasksOpen |= (valve as PumpWithFM.Pump).Mask;
if (valve is Danfoss.VLT2800.Pump) point.MasksOpen |= (valve as Danfoss.VLT2800.Pump).Mask;
if (valve is PumpTandem.Pump) point.MasksOpen |= (valve as PumpTandem.Pump).Mask;
if (valve is PumpTandem.Pump) point.MasksOpen |= (valve as PumpTandem.Pump).Mask;
}
point.MasksClose = 0;
foreach (var valve in point.VClose)
{
if (valve is Valve) point.MasksClose |= (valve as Valve).Mask;
if (valve is Pump.Pump) point.MasksClose |= (valve as Pump.Pump).Mask;
if (valve is PumpWithFM.Pump) point.MasksClose |= (valve as PumpWithFM.Pump).Mask;
if (valve is Valve.Valve) point.MasksClose |= (valve as Valve.Valve).Mask;
if (valve is Pump.Pump) point.MasksClose |= (valve as Pump.Pump).Mask;
if (valve is PumpWithFM.Pump) point.MasksClose |= (valve as PumpWithFM.Pump).Mask;
if (valve is Danfoss.VLT2800.Pump) point.MasksClose |= (valve as Danfoss.VLT2800.Pump).Mask;
if (valve is PumpTandem.Pump) point.MasksClose |= (valve as PumpTandem.Pump).Mask;
if (valve is PumpTandem.Pump) point.MasksClose |= (valve as PumpTandem.Pump).Mask;
}
point.TimeSec += timeShift;
}

View File

@ -8,7 +8,8 @@ using System.Text;
namespace TBF.BenchControl.GenericDevices
{
public interface ITankDraining
public interface ITankDraining : ISequenceCondition
{
bool IsEmpty();
}
}

View File

@ -30,6 +30,8 @@ namespace TBF.BenchControl.MettlerToledo.Standard
protected readonly BalanceCfg balanceCfg;
GenericDevices.IValve drainValve;
/// <summary>
/// Enumeration of balances via static fields and methods
/// </summary>
@ -97,11 +99,15 @@ namespace TBF.BenchControl.MettlerToledo.Standard
Balances[nextBalanceIdx - 1] = this;
}
drainValve = TbfComponents.FindComponent(balanceCfg.DrainValve) as GenericDevices.IValve;
log.Debug(this.ToString());
}
public void Initialize()
{
base.Initalize(drainValve);
msrmntState = MsrmntState.Failed; /// Data not valid yet
if (balanceCfg.DebugLevel == DebugMode.Simulate) return;
@ -115,7 +121,12 @@ namespace TBF.BenchControl.MettlerToledo.Standard
log.FatalFormat("Successfully initialized device {0}", ToString());
}
public bool IsEmpty()
public override string GetName()
{
return Name;
}
public override bool IsEmpty()
{
return (this.mass <= balanceCfg.Empty);
}
@ -242,6 +253,8 @@ namespace TBF.BenchControl.MettlerToledo.Standard
/// </summary>
public virtual void RunDeviceBefore()
{
base.RunBefore();
if (balanceCfg.DebugLevel == DebugMode.Simulate)
{
Masses[balanceNr] = TestBenchSim.GetSimMass(balanceNr);
@ -442,7 +455,8 @@ namespace TBF.BenchControl.MettlerToledo.Standard
/// <summary>Run this device</summary>
public void RunDeviceAfter()
{
}
base.RunAfter();
}
/// <summary>Stop this device</summary>
public void StopDevice()

View File

@ -67,6 +67,8 @@ namespace TBF.BenchControl.MettlerToledo.Standard
/// </summary>
public override void RunDeviceBefore()
{
base.RunBefore();
if (balanceCfg.DebugLevel == DebugMode.Simulate)
{
mass = TestBenchSim.GetSimMass(balanceNr);

View File

@ -61,6 +61,8 @@ namespace TBF.BenchControl.MettlerToledo.Standard
/// </summary>
public override void RunDeviceBefore()
{
base.RunBefore();
if (balanceCfg.DebugLevel == DebugMode.Simulate)
{
mass = TestBenchSim.GetSimMass(balanceNr);

View File

@ -2,25 +2,153 @@
/// Copyright (c) 2017 Sensus Metering Systems
///
using System;
using System.Collections.Generic;
using log4net;
using TBF.BenchControl.GenericDevices;
using TBF.Resources;
namespace TBF.BenchControl.MettlerToledo
{
public class TankDraining : ComponentBase
public enum DrainState
{
public GenericDevices.IValve DrainValve;
None,
OpeningDV_Start,
OpeningDV_Run,
OpeningDV_Stop,
Draining,
ClosingDV_Start,
ClosingDV_Run,
ClosingDV_Stop,
TankClosed,
}
public class TankDraining : ComponentBase, ITankDraining
{
private static readonly ILog log = LogManager.GetLogger(typeof(TankDraining));
readonly GenericDevices.ITankDrainingCfg tankDrainingCfg;
private IValve drainValve;
private IOperation openDrainValveOp;
private IOperation closeDrainValveOp;
DrainState drainState;
GenericDevices.ITankDrainingCfg tankManagementCfg;
public TankDraining()
: base()
{
CreateConditions(false);
}
public TankDraining(Generic.IComponentCfg cfg)
: base(cfg)
{
tankManagementCfg = cfg as GenericDevices.ITankDrainingCfg;
if (tankManagementCfg == null) throw new Exception(string.Format("Cannot create component {0}", cfg.Name));
tankDrainingCfg = cfg as GenericDevices.ITankDrainingCfg;
if (tankDrainingCfg == null) throw new Exception(string.Format("Cannot create component {0}", cfg.Name));
CreateConditions(true);
}
protected void Initalize(IValve drainValve)
{
this.drainValve = drainValve;
openDrainValveOp = new Elde.SetValvesOp(StateMachine.ControlBoard, drainValve, null);
closeDrainValveOp = new Elde.SetValvesOp(StateMachine.ControlBoard, null, drainValve);
}
protected void RunBefore()
{
switch (drainState)
{
case DrainState.OpeningDV_Start:
openDrainValveOp.Start();
drainState = DrainState.OpeningDV_Run;
return;
case DrainState.OpeningDV_Run:
if (openDrainValveOp.Run() == Event.ValvesSet) drainState = DrainState.OpeningDV_Stop;
return;
case DrainState.OpeningDV_Stop:
openDrainValveOp.Stop();
return;
case DrainState.Draining:
if (IsEmpty()) drainState = DrainState.ClosingDV_Start;
return;
case DrainState.ClosingDV_Start:
closeDrainValveOp.Start();
drainState = DrainState.ClosingDV_Run;
return;
case DrainState.ClosingDV_Run:
if (closeDrainValveOp.Run() == Event.ValvesSet) drainState = DrainState.ClosingDV_Stop;
return;
case DrainState.ClosingDV_Stop:
closeDrainValveOp.Stop();
return;
default:
return;
}
}
protected void RunAfter() { } /// Not used
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; } }
/// 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;
}
/// Operations are 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));
}
}
}

View File

@ -0,0 +1,50 @@
///
/// Copyright (c) 2017 Sensus Metering Systems
///
using log4net;
namespace TBF.BenchControl.MettlerToledo
{
public class WaitTankEmptyOp : IOperation
{
private static readonly ILog log = LogManager.GetLogger(typeof(WaitTankEmptyOp));
public override string ToString() { return string.Format("WaitTankEmptyOp()"); }
readonly GenericDevices.ITankDraining tankDraining;
bool conditionMet;
/// <summary>
/// Events: ConditionMet, ConditionNotMet
/// </summary>
/// <param name="tankDraining">Tank draining (Balance device) instance</param>
public WaitTankEmptyOp(GenericDevices.ITankDraining tankDraining)
{
this.tankDraining = tankDraining;
log.Debug(this.ToString());
}
/// <summary>Start this operation</summary>
public void Start()
{
conditionMet = tankDraining.IsEmpty();
}
/// <summary>Run this operation</summary>
/// <returns>
/// Event.ConditionMet . . . tank is empty
/// Event.ConditionNotMet . tank is not empty
/// </returns>
public Event Run()
{
conditionMet = conditionMet || tankDraining.IsEmpty();
return conditionMet ? Event.ConditionMet : Event.ConditionNotMet;
}
/// <summary>Stop this operation</summary>
public void Stop()
{
}
}
}

View File

@ -298,26 +298,18 @@ namespace TBF.BenchControl.Modbus.TankSelector
public string ConditionName(int i)
{
if (sequenceConditionNames != null && i < sequenceConditionNames.Count && i >= 0)
{
return sequenceConditionNames[i];
}
else
{
return string.Empty;
}
}
/// Operations are 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()

View File

@ -4662,6 +4662,15 @@ namespace TBF.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Wait until {0} tank is empty.
/// </summary>
internal static string Wait_until_0_tank_is_empty {
get {
return ResourceManager.GetString("Wait_until_0_tank_is_empty", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Warning.
/// </summary>

View File

@ -1392,4 +1392,7 @@
<data name="New_Q_names" xml:space="preserve">
<value>Neue Q</value>
</data>
<data name="Wait_until_0_tank_is_empty" xml:space="preserve">
<value>Warten bis {0} Behälter ist leer</value>
</data>
</root>

View File

@ -1693,4 +1693,7 @@
<data name="New_Q_names" xml:space="preserve">
<value>New Q</value>
</data>
<data name="Wait_until_0_tank_is_empty" xml:space="preserve">
<value>Wait until {0} tank is empty</value>
</data>
</root>

View File

@ -425,6 +425,7 @@
<Compile Include="BenchControl\Elde\PressureMeterInternal\PressureMeterFactory.cs" />
<Compile Include="BenchControl\Elde\PressureMeterInternal\ReadPressureOp.cs" />
<Compile Include="BenchControl\Elde\ExecuteCommandOp.cs" />
<Compile Include="BenchControl\Elde\SetValvesOp.cs" />
<Compile Include="BenchControl\Elde\TempMeterInternal\ReadTempOp.cs" />
<Compile Include="BenchControl\Elde\TempMeterInternal\TempMeter.cs" />
<Compile Include="BenchControl\Elde\TempMeterInternal\TempMeterCfg.cs" />
@ -507,6 +508,7 @@
<Compile Include="BenchControl\MettlerToledo\Standard\SetUnitsOp.cs" />
<Compile Include="BenchControl\MettlerToledo\Standard\TaringOp.cs" />
<Compile Include="BenchControl\MettlerToledo\TankDraining.cs" />
<Compile Include="BenchControl\MettlerToledo\WaitTankEmptyOp.cs" />
<Compile Include="BenchControl\Modbus\Easytherm\Factory.cs" />
<Compile Include="BenchControl\Modbus\Easytherm\Easytherm.cs" />
<Compile Include="BenchControl\Modbus\Easytherm\EasythermCfg.cs" />
@ -1341,7 +1343,6 @@
<Compile Include="BenchControl\Elde\RegulValve\RegulValveCfg.cs" />
<Compile Include="BenchControl\Elde\RegulValve\RegulValveFactory.cs" />
<Compile Include="BenchControl\Elde\RegulValve\SetFlowOp.cs" />
<Compile Include="BenchControl\Elde\Valve\SetValvesOp.cs" />
<Compile Include="BenchControl\Elde\TempMeter\TempMeter.cs" />
<Compile Include="BenchControl\Elde\TempMeter\TempMeterCfg.cs" />
<Compile Include="BenchControl\Elde\TempMeter\TempMeterFactory.cs" />