- possibility to invert valves (UI as well as the functionality)

- UI prepared for the usage of valve delays
This commit is contained in:
Milan Hanajik
2014-09-06 07:37:27 +02:00
parent 74a6800f9e
commit 6933442e76
7 changed files with 122 additions and 60 deletions
@@ -78,6 +78,8 @@ namespace TBF.BenchControl.Elde
/// <summary> State of valves sent out - buffered by the last SendCommand() </summary>
public ulong Route { get { return route; } }
ulong valvesToInvert; /// Route = valesToInvert ^ RequiredRouteWithoutInvertedVlaves
///
/// Initialization data updated by constructors of children components
/// and sent to 'controlCom2panel' by SendCalibData() method.
@@ -171,7 +173,8 @@ namespace TBF.BenchControl.Elde
#elif FUZHOU300
ControlComponent3F300.UserControl1 ctrlBrdComponent,
#endif
float[] tankCapacities)
ulong valvesToInvert,
float[] tankCapacities)
{
if (controlBoardCfg.DebugLevel == Entities.DebugMode.Simulate)
{
@@ -292,7 +295,7 @@ namespace TBF.BenchControl.Elde
public void SetValves(ulong valvesToOpen, ulong valvesToClose)
{
route = (route | valvesToOpen) & (~valvesToClose);
route = (((route ^ valvesToInvert) | valvesToOpen) & (~valvesToClose)) ^ valvesToInvert;
sendCommandFlag = true;
}
@@ -29,7 +29,7 @@ namespace TBF.BenchControl.Elde.Valve
public string Name { get { return valveCfg.Name; } }
public ValveCategory Category { get { return valveCfg.Category; } }
public IValve CoupledTo { get { return coupledTo; } }
public bool Invert { get { return valveCfg.Invert; } }
public bool Invert { get { return valveCfg.InvertCouple; } }
public int LagOpening { get { return valveCfg.LagOpening; } }
public int LagClosing { get { return valveCfg.LagClosing; } }
@@ -6,10 +6,13 @@ namespace TBF.BenchControl.Elde.Valve
{
public class ValveCfg : ComponentCfgBase, IChildComponentCfg
{
public int BitPosition; /// Bit-position
public int OpenCloseTime; /// Delay for SetValvesOp operations
public int BitPosition; /// Bit-position
public ValveCategory Category; /// None, Feeding, Bench or Output
public bool Inverted; /// The valve is inverted: 0=open, 1=closed
///
public string CoupledToName; /// Name of the coupled valve or null
public bool Invert; /// The coupled valve has inverted position
public bool InvertCouple; /// The coupled valve has inverted position
public int LagOpening; /// Delay (referred to the master valve) when opening this valve in [s]
public int LagClosing; /// Delay (referred to the master valve) when closing this valve in [s]
/// Negative values of delays mean an earlier function of the coupled valve.
@@ -17,37 +20,43 @@ namespace TBF.BenchControl.Elde.Valve
/// Parameterless constructor
public ValveCfg()
{
OpenCloseTime = 1; /// Defaut value
}
/// Constructor 1
public ValveCfg(IComponentFactory factory, string name, string parentName, int bitPosition,
ValveCategory category, string coupledToName, bool invert, int lagOpening, int lagClosing)
public ValveCfg(IComponentFactory factory, string name, string parentName, int bitPosition, bool inverted, int openCloseTime,
ValveCategory category, string coupledToName, bool invertCouple, int lagOpening, int lagClosing)
: base(factory, name, parentName)
{
this.OpenCloseTime = openCloseTime;
this.BitPosition = bitPosition;
this.Category = category;
this.Inverted = inverted;
this.CoupledToName = coupledToName;
this.Invert = invert;
this.InvertCouple = invertCouple;
this.LagOpening = lagOpening;
this.LagClosing = lagClosing;
}
/// Constructor 2 without CoupledTo valve
public ValveCfg(IComponentFactory factory, string name, string parentName, int bitPosition, ValveCategory category)
: this(factory, name, parentName, bitPosition, category, null, false, 0, 0)
public ValveCfg(IComponentFactory factory, string name, string parentName, int bitPosition, bool inverted, int openCloseTime, ValveCategory category)
: this(factory, name, parentName, bitPosition, inverted, openCloseTime, category, null, false, 0, 0)
{
}
public IComponentCfg Clone()
{
return new ValveCfg(Factory, Name, ParentName, BitPosition, Category, CoupledToName, Invert, LagOpening, LagClosing);
return new ValveCfg(Factory, Name, ParentName, BitPosition, Inverted, OpenCloseTime, Category, CoupledToName, InvertCouple, LagOpening, LagClosing);
}
public string ToString(int i)
{
return string.Format("bit={0}, cat={1}, coupledTo={2}, invert={3}, lagOpen={4}, lagClose={5}",
return string.Format("bit={0}, inv.={1}, delay={2}s, cat.={3}, coupledTo={4}, inv.Couple={5}, lagOpen={6}s, lagClose={7}s",
BitPosition,
(Inverted ? "yes" : "no"),
OpenCloseTime,
Category,
(string.IsNullOrEmpty(CoupledToName) ? "---" : CoupledToName),
(Invert ? "yes" : "no"),
(InvertCouple ? "yes" : "no"),
LagOpening,
LagClosing);
}
@@ -35,7 +35,7 @@
this.nameLabel = new System.Windows.Forms.Label();
this.classNameLabel = new System.Windows.Forms.Label();
this.coupledToLabel = new System.Windows.Forms.Label();
this.invertCheckBox = new System.Windows.Forms.CheckBox();
this.invertCoupleCheckBox = new System.Windows.Forms.CheckBox();
this.parentNameComboBox = new System.Windows.Forms.ComboBox();
this.lagOpeningLabel = new System.Windows.Forms.Label();
this.lagClosingLabel = new System.Windows.Forms.Label();
@@ -44,33 +44,36 @@
this.coupledToComboBox = new System.Windows.Forms.ComboBox();
this.categoryLabel = new System.Windows.Forms.Label();
this.categoryComboBox = new System.Windows.Forms.ComboBox();
this.openCloseTimeTextBox = new System.Windows.Forms.TextBox();
this.openCloseTimeLabel = new System.Windows.Forms.Label();
this.invertedCheckBox = new System.Windows.Forms.CheckBox();
this.SuspendLayout();
//
// bitPositionTextBox
//
this.bitPositionTextBox.Enabled = false;
this.bitPositionTextBox.Location = new System.Drawing.Point(138, 77);
this.bitPositionTextBox.Location = new System.Drawing.Point(138, 98);
this.bitPositionTextBox.Name = "bitPositionTextBox";
this.bitPositionTextBox.Size = new System.Drawing.Size(81, 20);
this.bitPositionTextBox.TabIndex = 6;
this.bitPositionTextBox.TabIndex = 10;
//
// bitPositionLabel
//
this.bitPositionLabel.AutoSize = true;
this.bitPositionLabel.Location = new System.Drawing.Point(22, 80);
this.bitPositionLabel.Location = new System.Drawing.Point(22, 101);
this.bitPositionLabel.Name = "bitPositionLabel";
this.bitPositionLabel.Size = new System.Drawing.Size(59, 13);
this.bitPositionLabel.TabIndex = 5;
this.bitPositionLabel.Text = "Bit Position";
this.bitPositionLabel.Size = new System.Drawing.Size(58, 13);
this.bitPositionLabel.TabIndex = 9;
this.bitPositionLabel.Text = "Bit position";
//
// parentNameLabel
//
this.parentNameLabel.AutoSize = true;
this.parentNameLabel.Location = new System.Drawing.Point(22, 55);
this.parentNameLabel.Location = new System.Drawing.Point(22, 54);
this.parentNameLabel.Name = "parentNameLabel";
this.parentNameLabel.Size = new System.Drawing.Size(69, 13);
this.parentNameLabel.Size = new System.Drawing.Size(67, 13);
this.parentNameLabel.TabIndex = 3;
this.parentNameLabel.Text = "Parent Name";
this.parentNameLabel.Text = "Parent name";
//
// nameTextBox
//
@@ -101,28 +104,28 @@
// coupledToLabel
//
this.coupledToLabel.AutoSize = true;
this.coupledToLabel.Location = new System.Drawing.Point(22, 128);
this.coupledToLabel.Location = new System.Drawing.Point(22, 165);
this.coupledToLabel.Name = "coupledToLabel";
this.coupledToLabel.Size = new System.Drawing.Size(56, 13);
this.coupledToLabel.TabIndex = 9;
this.coupledToLabel.Text = "Copled To";
this.coupledToLabel.Size = new System.Drawing.Size(52, 13);
this.coupledToLabel.TabIndex = 12;
this.coupledToLabel.Text = "Copled to";
//
// invertCheckBox
// invertCoupleCheckBox
//
this.invertCheckBox.AutoSize = true;
this.invertCheckBox.Enabled = false;
this.invertCheckBox.Location = new System.Drawing.Point(232, 128);
this.invertCheckBox.Name = "invertCheckBox";
this.invertCheckBox.Size = new System.Drawing.Size(53, 17);
this.invertCheckBox.TabIndex = 11;
this.invertCheckBox.Text = "Invert";
this.invertCheckBox.UseVisualStyleBackColor = true;
this.invertCoupleCheckBox.AutoSize = true;
this.invertCoupleCheckBox.Enabled = false;
this.invertCoupleCheckBox.Location = new System.Drawing.Point(228, 164);
this.invertCoupleCheckBox.Name = "invertCoupleCheckBox";
this.invertCoupleCheckBox.Size = new System.Drawing.Size(53, 17);
this.invertCoupleCheckBox.TabIndex = 14;
this.invertCoupleCheckBox.Text = "Invert";
this.invertCoupleCheckBox.UseVisualStyleBackColor = true;
//
// parentNameComboBox
//
this.parentNameComboBox.Enabled = false;
this.parentNameComboBox.FormattingEnabled = true;
this.parentNameComboBox.Location = new System.Drawing.Point(138, 52);
this.parentNameComboBox.Location = new System.Drawing.Point(138, 51);
this.parentNameComboBox.Name = "parentNameComboBox";
this.parentNameComboBox.Size = new System.Drawing.Size(130, 21);
this.parentNameComboBox.TabIndex = 4;
@@ -130,50 +133,50 @@
// lagOpeningLabel
//
this.lagOpeningLabel.AutoSize = true;
this.lagOpeningLabel.Location = new System.Drawing.Point(22, 153);
this.lagOpeningLabel.Location = new System.Drawing.Point(22, 189);
this.lagOpeningLabel.Name = "lagOpeningLabel";
this.lagOpeningLabel.Size = new System.Drawing.Size(109, 13);
this.lagOpeningLabel.TabIndex = 12;
this.lagOpeningLabel.TabIndex = 15;
this.lagOpeningLabel.Text = "Lag when opening [s]";
//
// lagClosingLabel
//
this.lagClosingLabel.AutoSize = true;
this.lagClosingLabel.Location = new System.Drawing.Point(22, 177);
this.lagClosingLabel.Location = new System.Drawing.Point(22, 212);
this.lagClosingLabel.Name = "lagClosingLabel";
this.lagClosingLabel.Size = new System.Drawing.Size(104, 13);
this.lagClosingLabel.TabIndex = 14;
this.lagClosingLabel.TabIndex = 17;
this.lagClosingLabel.Text = "Lag when closing [s]";
//
// lagOpeningTextBox
//
this.lagOpeningTextBox.Enabled = false;
this.lagOpeningTextBox.Location = new System.Drawing.Point(138, 150);
this.lagOpeningTextBox.Location = new System.Drawing.Point(138, 186);
this.lagOpeningTextBox.Name = "lagOpeningTextBox";
this.lagOpeningTextBox.Size = new System.Drawing.Size(81, 20);
this.lagOpeningTextBox.TabIndex = 13;
this.lagOpeningTextBox.TabIndex = 16;
//
// lagClosingTextBox
//
this.lagClosingTextBox.Enabled = false;
this.lagClosingTextBox.Location = new System.Drawing.Point(138, 174);
this.lagClosingTextBox.Location = new System.Drawing.Point(138, 209);
this.lagClosingTextBox.Name = "lagClosingTextBox";
this.lagClosingTextBox.Size = new System.Drawing.Size(81, 20);
this.lagClosingTextBox.TabIndex = 15;
this.lagClosingTextBox.TabIndex = 18;
//
// coupledToComboBox
//
this.coupledToComboBox.Enabled = false;
this.coupledToComboBox.FormattingEnabled = true;
this.coupledToComboBox.Location = new System.Drawing.Point(138, 125);
this.coupledToComboBox.Location = new System.Drawing.Point(138, 162);
this.coupledToComboBox.Name = "coupledToComboBox";
this.coupledToComboBox.Size = new System.Drawing.Size(81, 21);
this.coupledToComboBox.TabIndex = 10;
this.coupledToComboBox.TabIndex = 13;
//
// categoryLabel
//
this.categoryLabel.AutoSize = true;
this.categoryLabel.Location = new System.Drawing.Point(22, 104);
this.categoryLabel.Location = new System.Drawing.Point(22, 124);
this.categoryLabel.Name = "categoryLabel";
this.categoryLabel.Size = new System.Drawing.Size(49, 13);
this.categoryLabel.TabIndex = 7;
@@ -183,15 +186,46 @@
//
this.categoryComboBox.Enabled = false;
this.categoryComboBox.FormattingEnabled = true;
this.categoryComboBox.Location = new System.Drawing.Point(138, 101);
this.categoryComboBox.Location = new System.Drawing.Point(138, 121);
this.categoryComboBox.Name = "categoryComboBox";
this.categoryComboBox.Size = new System.Drawing.Size(81, 21);
this.categoryComboBox.TabIndex = 8;
//
// openCloseTimeTextBox
//
this.openCloseTimeTextBox.Enabled = false;
this.openCloseTimeTextBox.Location = new System.Drawing.Point(138, 75);
this.openCloseTimeTextBox.Name = "openCloseTimeTextBox";
this.openCloseTimeTextBox.Size = new System.Drawing.Size(81, 20);
this.openCloseTimeTextBox.TabIndex = 6;
//
// openCloseTimeLabel
//
this.openCloseTimeLabel.AutoSize = true;
this.openCloseTimeLabel.Location = new System.Drawing.Point(22, 78);
this.openCloseTimeLabel.Name = "openCloseTimeLabel";
this.openCloseTimeLabel.Size = new System.Drawing.Size(48, 13);
this.openCloseTimeLabel.TabIndex = 5;
this.openCloseTimeLabel.Text = "Delay [s]";
//
// invertedCheckBox
//
this.invertedCheckBox.AutoSize = true;
this.invertedCheckBox.Enabled = false;
this.invertedCheckBox.Location = new System.Drawing.Point(228, 100);
this.invertedCheckBox.Name = "invertedCheckBox";
this.invertedCheckBox.Size = new System.Drawing.Size(65, 17);
this.invertedCheckBox.TabIndex = 11;
this.invertedCheckBox.Text = "Inverted";
this.invertedCheckBox.UseVisualStyleBackColor = true;
//
// ValveCfgCtrl
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.invertedCheckBox);
this.Controls.Add(this.openCloseTimeTextBox);
this.Controls.Add(this.openCloseTimeLabel);
this.Controls.Add(this.categoryComboBox);
this.Controls.Add(this.categoryLabel);
this.Controls.Add(this.coupledToComboBox);
@@ -200,7 +234,7 @@
this.Controls.Add(this.lagClosingLabel);
this.Controls.Add(this.lagOpeningLabel);
this.Controls.Add(this.parentNameComboBox);
this.Controls.Add(this.invertCheckBox);
this.Controls.Add(this.invertCoupleCheckBox);
this.Controls.Add(this.coupledToLabel);
this.Controls.Add(this.bitPositionTextBox);
this.Controls.Add(this.bitPositionLabel);
@@ -209,7 +243,7 @@
this.Controls.Add(this.nameLabel);
this.Controls.Add(this.classNameLabel);
this.Name = "ValveCfgCtrl";
this.Size = new System.Drawing.Size(300, 200);
this.Size = new System.Drawing.Size(300, 250);
this.Load += new System.EventHandler(this.ValveCfgCtrl_Load);
this.ResumeLayout(false);
this.PerformLayout();
@@ -225,7 +259,7 @@
private System.Windows.Forms.Label nameLabel;
private System.Windows.Forms.Label classNameLabel;
private System.Windows.Forms.Label coupledToLabel;
private System.Windows.Forms.CheckBox invertCheckBox;
private System.Windows.Forms.CheckBox invertCoupleCheckBox;
private System.Windows.Forms.ComboBox parentNameComboBox;
private System.Windows.Forms.Label lagOpeningLabel;
private System.Windows.Forms.Label lagClosingLabel;
@@ -234,5 +268,8 @@
private System.Windows.Forms.ComboBox coupledToComboBox;
private System.Windows.Forms.Label categoryLabel;
private System.Windows.Forms.ComboBox categoryComboBox;
private System.Windows.Forms.TextBox openCloseTimeTextBox;
private System.Windows.Forms.Label openCloseTimeLabel;
private System.Windows.Forms.CheckBox invertedCheckBox;
}
}
@@ -65,9 +65,11 @@ namespace TBF.BenchControl.Elde.Valve
nameTextBox.Text = config.Name;
parentNameComboBox.Text = string.IsNullOrEmpty(config.ParentName) ? "---" : config.ParentName;
bitPositionTextBox.Text = config.BitPosition.ToString();
invertedCheckBox.Checked = config.Inverted;
openCloseTimeTextBox.Text = config.OpenCloseTime.ToString();
categoryComboBox.Text = config.Category.ToString();
coupledToComboBox.Text = string.IsNullOrEmpty(config.CoupledToName) ? "---" : config.CoupledToName;
invertCheckBox.Checked = config.Invert;
invertCoupleCheckBox.Checked = config.InvertCouple;
lagOpeningTextBox.Text = config.LagOpening.ToString();
lagClosingTextBox.Text = config.LagClosing.ToString();
}
@@ -77,9 +79,11 @@ namespace TBF.BenchControl.Elde.Valve
nameTextBox.Enabled = true;
parentNameComboBox.Enabled = true;
bitPositionTextBox.Enabled = true;
invertedCheckBox.Enabled = true;
openCloseTimeTextBox.Enabled = true;
categoryComboBox.Enabled = true;
coupledToComboBox.Enabled = true;
invertCheckBox.Enabled = true;
invertCoupleCheckBox.Enabled = true;
lagOpeningTextBox.Enabled = true;
lagClosingTextBox.Enabled = true;
}
@@ -91,15 +95,17 @@ namespace TBF.BenchControl.Elde.Valve
config.Name = nameTextBox.Text;
config.ParentName = parentNameComboBox.Text.Equals("---") ? string.Empty : parentNameComboBox.Text;
config.BitPosition = int.Parse(bitPositionTextBox.Text);
config.OpenCloseTime = int.Parse(openCloseTimeTextBox.Text);
config.Inverted = invertedCheckBox.Checked;
if (categoryComboBox.Text.Equals(ValveCategory.All.ToString())) config.Category = ValveCategory.All;
if (categoryComboBox.Text.Equals(ValveCategory.All.ToString())) config.Category = ValveCategory.All;
else if (categoryComboBox.Text.Equals(ValveCategory.Feeding.ToString())) config.Category = ValveCategory.Feeding;
else if (categoryComboBox.Text.Equals(ValveCategory.Bench.ToString())) config.Category = ValveCategory.Bench;
else if (categoryComboBox.Text.Equals(ValveCategory.Bench.ToString())) config.Category = ValveCategory.Bench;
else if (categoryComboBox.Text.Equals(ValveCategory.Output.ToString())) config.Category = ValveCategory.Output;
else config.Category = ValveCategory.None;
config.CoupledToName = coupledToComboBox.Text.Equals("---") ? string.Empty : coupledToComboBox.Text;
config.Invert = invertCheckBox.Checked;
config.InvertCouple = invertCoupleCheckBox.Checked;
config.LagOpening = int.Parse(lagOpeningTextBox.Text);
config.LagClosing = int.Parse(lagClosingTextBox.Text);
}
@@ -129,7 +135,12 @@ namespace TBF.BenchControl.Elde.Valve
flags |= CfgVerifyFlags.Error;
message += Environment.NewLine + "'Bit Position' should be between 0 and 63";
}
if (!int.TryParse(lagOpeningTextBox.Text, out dummy))
if (!int.TryParse(openCloseTimeTextBox.Text, out dummy) || dummy < 0 || dummy > 300)
{
flags |= CfgVerifyFlags.Error;
message += Environment.NewLine + "'Open/close time' should be between 0 and 300 s";
}
if (!int.TryParse(lagOpeningTextBox.Text, out dummy))
{
flags |= CfgVerifyFlags.Error;
message += Environment.NewLine + "'Delay when opening' error";
@@ -16,7 +16,7 @@ namespace TBF.BenchControl.Elde.Valve
public IComponentCfg DefaultConfig(IList<Entities.Component> components)
{
return new ValveCfg(this, "Valve", "CB", 0, ValveCategory.None);
return new ValveCfg(this, "Valve", "CB", 0, false, 1, ValveCategory.None);
}
public IComponentCfgCtrl CreateCfgCtrl()
@@ -199,6 +199,7 @@ namespace TBF.BenchControl
SequenceBase.RegulValves = new List<IRegulValve>();
SequenceBase.WaterMeters = new List<IWaterMeter>();
SequenceBase.Cameras = new List<ICamera>();
ulong valvesToInvert = 0;
foreach (var cmpnt in components)
{
if (cmpnt is Elde.ControlBoardDev) ControlBoard = cmpnt as Elde.ControlBoardDev;
@@ -216,6 +217,7 @@ namespace TBF.BenchControl
else if (balance.BalanceNr == 1) Balance2 = balance;
else if (balance.BalanceNr == 2) Balance3 = balance;
}
if (cmpnt is Elde.Valve.Valve) valvesToInvert |= (cmpnt as Elde.Valve.Valve).Mask;
}
/// Create an array with tank capacities
@@ -223,7 +225,7 @@ namespace TBF.BenchControl
for (int i = 0; i < tankCapacities.Length; i++) tankCapacities[i] = balances[i].Capacity;
/// Pre-initialize the control board (= buffer the arguments ctrlBrdComponent, tankCapacities)
ControlBoard.InitializeComponent(ctrlBrdComponent, tankCapacities);
ControlBoard.InitializeComponent(ctrlBrdComponent, valvesToInvert, tankCapacities);
}
public static void InitializeDevices()