- Part field (int) added to Test and TestResult, shown and processed in UI in ProcedureDlg
301 lines
8.2 KiB
C#
301 lines
8.2 KiB
C#
using System;
|
|
using System.Windows.Forms;
|
|
using log4net;
|
|
using TBF.BenchControl.Generic;
|
|
|
|
namespace TBF.BenchControl.Elde.RegulValve
|
|
{
|
|
public partial class RegulValveCfgCtrl : UserControl, IComponentCfgCtrl
|
|
{
|
|
static readonly ILog log = LogManager.GetLogger(typeof(RegulValveCfgCtrl));
|
|
|
|
ComponentParametersDlg parent;
|
|
|
|
public bool ShowMore { get { return true; } }
|
|
|
|
RegulValveCfg config;
|
|
public IComponentCfg Config
|
|
{
|
|
get { return config as IComponentCfg; }
|
|
set
|
|
{
|
|
config = value as RegulValveCfg;
|
|
Redraw();
|
|
}
|
|
}
|
|
|
|
public RegulValveCfgCtrl()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void RegulationValveCfgCtrl_Load(object sender, EventArgs e)
|
|
{
|
|
parent = ParentForm as ComponentParametersDlg;
|
|
if (parent == null) return;
|
|
|
|
if (parent.TbfComponents != null)
|
|
{
|
|
foreach (var cmpnt in parent.TbfComponents)
|
|
{
|
|
if (TbfComponents.CmpntFactoryFromClassName(cmpnt.ClassName) is Elde.ControlBoardFactory)
|
|
{
|
|
parentNameComboBox.Items.Add(cmpnt.Name);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (config != null)
|
|
{
|
|
adc1 = config.DacValueClosed;
|
|
pct1 = 0;
|
|
adc2 = config.DacValueOpen;
|
|
pct2 = 100;
|
|
}
|
|
|
|
Redraw();
|
|
StartResponseHandler();
|
|
}
|
|
|
|
public void Closing()
|
|
{
|
|
StopResponseHandler();
|
|
}
|
|
|
|
void Redraw()
|
|
{
|
|
if (config == null) return; /// Control was not loaded, settings were not changed
|
|
|
|
classNameLabel.Text = config.Factory.ClassName;
|
|
nameTextBox.Text = config.Name;
|
|
parentNameComboBox.Text = string.IsNullOrEmpty(config.ParentName) ? "---" : config.ParentName;
|
|
positionTextBox.Text = config.Idx1.ToString();
|
|
dacClosedTextBox.Text = config.DacValueClosed.ToString();
|
|
dacOpenTextBox.Text = config.DacValueOpen.ToString();
|
|
stableTimeTextBox.Text = config.StableTimeMs.ToString();
|
|
storedPosReuseCheckBox.Checked = config.StoredPositionReuse;
|
|
flowStableSecTextBox.Text = config.FlowStableSec.ToString();
|
|
|
|
adcTextBox1.Text = adc1.ToString();
|
|
adcTextBox2.Text = adc2.ToString();
|
|
pctTextBox1.Text = pct1.ToString();
|
|
pctTextBox2.Text = pct2.ToString();
|
|
}
|
|
|
|
public void Unlock()
|
|
{
|
|
nameTextBox.Enabled = true;
|
|
parentNameComboBox.Enabled = true;
|
|
positionTextBox.Enabled = true;
|
|
dacClosedTextBox.Enabled = true;
|
|
dacOpenTextBox.Enabled = true;
|
|
stableTimeTextBox.Enabled = true;
|
|
storedPosReuseCheckBox.Enabled = true;
|
|
flowStableSecTextBox.Enabled = true;
|
|
}
|
|
|
|
public CfgUpdateFlags VerifyCfg(ref string message)
|
|
{
|
|
CfgUpdateFlags flags = CfgUpdateFlags.AnyChange;
|
|
|
|
int dummy;
|
|
if (!parentNameComboBox.Items.Contains(parentNameComboBox.Text))
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "Invalid 'Parent Name'";
|
|
}
|
|
if (!int.TryParse(positionTextBox.Text, out dummy) || dummy < 1 || dummy > 5)
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "'Position' should be between 1 and 5";
|
|
}
|
|
if (!int.TryParse(dacClosedTextBox.Text, out dummy) || dummy < 0 || dummy > 1023)
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "'DAC when Closed' should be between 0 and 1023";
|
|
}
|
|
if (!int.TryParse(dacOpenTextBox.Text, out dummy) || dummy < 0 || dummy > 1023)
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "'DAC when Open' should be between 0 and 1023";
|
|
}
|
|
if (!int.TryParse(stableTimeTextBox.Text, out dummy) || dummy < 200 || dummy > 1500 || (dummy % 50) != 0)
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "'Stable time' should be between 200 and 1500 ms in 50 ms steps";
|
|
}
|
|
if (!int.TryParse(flowStableSecTextBox.Text, out dummy) || dummy < 0 || dummy > 60)
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "'Flow stable' should be between 0 and 60 sec";
|
|
}
|
|
|
|
return flags;
|
|
}
|
|
|
|
public CfgUpdateFlags UpdateCfg()
|
|
{
|
|
CfgUpdateFlags flags = CfgUpdateFlags.None;
|
|
|
|
if (config == null) return CfgUpdateFlags.Error; /// Control was not loaded, settings were not changed
|
|
///
|
|
if (!config.Name.Equals(nameTextBox.Text))
|
|
{
|
|
config.Name = nameTextBox.Text;
|
|
flags |= (CfgUpdateFlags.RestartRqrd | CfgUpdateFlags.AnyChange);
|
|
}
|
|
|
|
string parentname = parentNameComboBox.Text.Equals("---") ? string.Empty : parentNameComboBox.Text;
|
|
if (!config.ParentName.Equals(parentname))
|
|
{
|
|
config.ParentName = parentname;
|
|
flags |= (CfgUpdateFlags.RestartRqrd | CfgUpdateFlags.AnyChange);
|
|
}
|
|
|
|
int tmp = int.Parse(positionTextBox.Text);
|
|
if (config.Idx1 != tmp)
|
|
{
|
|
config.Idx1 = tmp;
|
|
flags |= (CfgUpdateFlags.RestartRqrd | CfgUpdateFlags.AnyChange);
|
|
}
|
|
|
|
tmp = int.Parse(dacClosedTextBox.Text);
|
|
if (config.DacValueClosed != tmp)
|
|
{
|
|
config.DacValueClosed = tmp;
|
|
flags |= (CfgUpdateFlags.RestartRqrd | CfgUpdateFlags.AnyChange);
|
|
}
|
|
|
|
tmp = int.Parse(dacOpenTextBox.Text);
|
|
if (config.DacValueOpen != tmp)
|
|
{
|
|
config.DacValueOpen = tmp;
|
|
flags |= (CfgUpdateFlags.RestartRqrd | CfgUpdateFlags.AnyChange);
|
|
}
|
|
|
|
tmp = int.Parse(stableTimeTextBox.Text);
|
|
if (config.StableTimeMs != tmp)
|
|
{
|
|
config.StableTimeMs = tmp;
|
|
flags |= CfgUpdateFlags.AnyChange;
|
|
}
|
|
|
|
bool btmp = storedPosReuseCheckBox.Checked;
|
|
if (config.StoredPositionReuse != btmp)
|
|
{
|
|
config.StoredPositionReuse = btmp;
|
|
flags |= (CfgUpdateFlags.RestartRqrd | CfgUpdateFlags.AnyChange);
|
|
}
|
|
|
|
tmp = int.Parse(flowStableSecTextBox.Text);
|
|
if (config.FlowStableSec != tmp)
|
|
{
|
|
config.FlowStableSec = tmp;
|
|
flags |= CfgUpdateFlags.AnyChange;
|
|
}
|
|
|
|
if ((flags & CfgUpdateFlags.AnyChange) != 0)
|
|
{
|
|
RegulValve.OnCfgChange(this, new CfgChangeArgs(CfgChangeCmd.CfgChange, config));
|
|
}
|
|
|
|
return flags;
|
|
}
|
|
|
|
int adc1;
|
|
int pct1;
|
|
|
|
int adc2;
|
|
int pct2;
|
|
|
|
private void openButton_Click(object sender, EventArgs e)
|
|
{
|
|
RegulValve.OnCfgChange(this, new CfgChangeArgs(CfgChangeCmd.RVOpenStep, config));
|
|
}
|
|
|
|
private void closeButton_Click(object sender, EventArgs e)
|
|
{
|
|
RegulValve.OnCfgChange(this, new CfgChangeArgs(CfgChangeCmd.RVCloseStep, config));
|
|
}
|
|
|
|
//
|
|
private void getButton1_Click(object sender, EventArgs e)
|
|
{
|
|
RegulValve.OnCfgChange(this, new CfgChangeArgs(CfgChangeCmd.GetRVAdc1, config));
|
|
}
|
|
|
|
private void getButton2_Click(object sender, EventArgs e)
|
|
{
|
|
RegulValve.OnCfgChange(this, new CfgChangeArgs(CfgChangeCmd.GetRVAdc2, config));
|
|
}
|
|
|
|
private void setButton1_Click(object sender, EventArgs e)
|
|
{
|
|
setButton2_Click(sender, e); /// Both Save buttons have the same effect
|
|
}
|
|
|
|
private void setButton2_Click(object sender, EventArgs e)
|
|
{
|
|
int tmpPct1;
|
|
int tmpPct2;
|
|
if ((int.TryParse(pctTextBox1.Text, out tmpPct1) && (tmpPct1 >= 0) && (tmpPct1 <= 100)) &&
|
|
(int.TryParse(pctTextBox2.Text, out tmpPct2) && (tmpPct2 >= 0) && (tmpPct2 <= 100)))
|
|
{
|
|
pct1 = tmpPct1;
|
|
pct2 = tmpPct2;
|
|
UpdateValveOpenClose();
|
|
}
|
|
}
|
|
|
|
void UpdateValveOpenClose()
|
|
{
|
|
if ((adc1 == adc2) || (pct1 == pct2)) return;
|
|
|
|
double factor = (float)(adc2 - adc1) / (float)(pct2 - pct1);
|
|
int dacClosed = (int)((float)(0 - pct1) * factor + (float)adc1 + 0.5f);
|
|
int dacOpen = (int)((float)(100 - pct1) * factor + (float)adc1 + 0.5f);
|
|
|
|
if ((dacClosed >= 0) && (dacOpen >= 0))
|
|
{
|
|
dacClosedTextBox.Text = dacClosed.ToString();
|
|
dacOpenTextBox.Text = dacOpen.ToString();
|
|
}
|
|
}
|
|
|
|
#region Configuration Change Handling
|
|
|
|
public static void OnCmdResponse(object sender, CmdResponseArgs args)
|
|
{
|
|
if (CmdResponseHandler == null) return;
|
|
try { CmdResponseHandler(sender, args); }
|
|
catch (Exception e) { log.Error("CmdResponseHandler(...) failed", e); }
|
|
}
|
|
|
|
public static event EventHandler<CmdResponseArgs> CmdResponseHandler;
|
|
|
|
public void StartResponseHandler()
|
|
{
|
|
CmdResponseHandler += delegate(object sender, CmdResponseArgs args)
|
|
{
|
|
if (args.Command == CfgChangeCmd.GetRVAdc1)
|
|
{
|
|
adc1 = args.Response;
|
|
adcTextBox1.Text = adc1.ToString();
|
|
}
|
|
else if (args.Command == CfgChangeCmd.GetRVAdc2)
|
|
{
|
|
adc2 = args.Response;
|
|
adcTextBox2.Text = adc2.ToString();
|
|
}
|
|
};
|
|
}
|
|
|
|
public void StopResponseHandler()
|
|
{
|
|
CmdResponseHandler = null;
|
|
}
|
|
|
|
#endregion Configuration Change Handling
|
|
}
|
|
}
|