137 lines
4.5 KiB
C#
137 lines
4.5 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;
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
|
|
Redraw();
|
|
}
|
|
|
|
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();
|
|
pidCoefTextBox.Text = config.PidCoef.ToString();
|
|
stableTimeTextBox.Text = config.StableTimeMs.ToString();
|
|
storedPosReuseCheckBox.Checked = config.StoredPositionReuse;
|
|
flowStableSecTextBox.Text = config.FlowStableSec.ToString();
|
|
}
|
|
|
|
public void Unlock()
|
|
{
|
|
nameTextBox.Enabled = true;
|
|
parentNameComboBox.Enabled = true;
|
|
positionTextBox.Enabled = true;
|
|
dacClosedTextBox.Enabled = true;
|
|
dacOpenTextBox.Enabled = true;
|
|
pidCoefTextBox.Enabled = true;
|
|
stableTimeTextBox.Enabled = true;
|
|
storedPosReuseCheckBox.Enabled = true;
|
|
flowStableSecTextBox.Enabled = true;
|
|
}
|
|
|
|
public CfgVerifyFlags VerifyCfg(ref string message)
|
|
{
|
|
CfgVerifyFlags flags = CfgVerifyFlags.None;
|
|
|
|
int dummy;
|
|
if (!parentNameComboBox.Items.Contains(parentNameComboBox.Text))
|
|
{
|
|
flags |= CfgVerifyFlags.Error;
|
|
message += Environment.NewLine + "Invalid 'Parent Name'";
|
|
}
|
|
if (!int.TryParse(positionTextBox.Text, out dummy) || dummy < 1 || dummy > 5)
|
|
{
|
|
flags |= CfgVerifyFlags.Error;
|
|
message += Environment.NewLine + "'Position' should be between 1 and 5";
|
|
}
|
|
if (!int.TryParse(dacClosedTextBox.Text, out dummy) || dummy < 0 || dummy > 1023)
|
|
{
|
|
flags |= CfgVerifyFlags.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 |= CfgVerifyFlags.Error;
|
|
message += Environment.NewLine + "'DAC when Open' should be between 0 and 1023";
|
|
}
|
|
if (!int.TryParse(pidCoefTextBox.Text, out dummy) || dummy < 0 || dummy > 100)
|
|
{
|
|
flags |= CfgVerifyFlags.Error;
|
|
message += Environment.NewLine + "'PID Coefficient' should be between 0 and 100";
|
|
}
|
|
if (!int.TryParse(stableTimeTextBox.Text, out dummy) || dummy < 200 || dummy > 1500 || (dummy % 50) != 0)
|
|
{
|
|
flags |= CfgVerifyFlags.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 |= CfgVerifyFlags.Error;
|
|
message += Environment.NewLine + "'Flow stable' should be between 0 and 60 sec";
|
|
}
|
|
|
|
return flags;
|
|
}
|
|
|
|
public void UpdateCfg()
|
|
{
|
|
if (config == null) return; /// Control was not loaded, settings were not changed
|
|
|
|
config.Name = nameTextBox.Text;
|
|
config.ParentName = parentNameComboBox.Text.Equals("---") ? string.Empty : parentNameComboBox.Text;
|
|
config.Idx1 = int.Parse(positionTextBox.Text);
|
|
config.DacValueClosed = int.Parse(dacClosedTextBox.Text);
|
|
config.DacValueOpen = int.Parse(dacOpenTextBox.Text);
|
|
config.PidCoef = int.Parse(pidCoefTextBox.Text);
|
|
config.StableTimeMs = int.Parse(stableTimeTextBox.Text);
|
|
config.StoredPositionReuse = storedPosReuseCheckBox.Checked;
|
|
config.FlowStableSec = int.Parse(flowStableSecTextBox.Text);
|
|
}
|
|
}
|
|
}
|