- RegulValve ADC Open/Close values calibration implemented
- 'More' button added to ComponentCfgCtrl-s - Dataflow from ComponentParametersDlg to components: CfgChangeHandler - Dataflow from components to ComponentParametersDlg: CmdResponseHandler - Detection of parameter changes and appropriate MesssageBox display: 1.warning message when component configuration change requires program restart 2.confirmation message box when any configuration changes would be lost
This commit is contained in:
@@ -10,6 +10,9 @@ namespace TBF.BenchControl.Elde.RegulValve
|
||||
static readonly ILog log = LogManager.GetLogger(typeof(RegulValveCfgCtrl));
|
||||
|
||||
ComponentParametersDlg parent;
|
||||
|
||||
public bool ShowMore { get { return true; } }
|
||||
|
||||
RegulValveCfg config;
|
||||
public IComponentCfg Config
|
||||
{
|
||||
@@ -42,7 +45,21 @@ namespace TBF.BenchControl.Elde.RegulValve
|
||||
}
|
||||
}
|
||||
|
||||
if (config != null)
|
||||
{
|
||||
adc1 = config.DacValueClosed;
|
||||
pct1 = 0;
|
||||
adc2 = config.DacValueOpen;
|
||||
pct2 = 100;
|
||||
}
|
||||
|
||||
Redraw();
|
||||
StartResponseHandler();
|
||||
}
|
||||
|
||||
public void Closing()
|
||||
{
|
||||
StopResponseHandler();
|
||||
}
|
||||
|
||||
void Redraw()
|
||||
@@ -59,7 +76,12 @@ namespace TBF.BenchControl.Elde.RegulValve
|
||||
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()
|
||||
{
|
||||
@@ -74,63 +96,219 @@ namespace TBF.BenchControl.Elde.RegulValve
|
||||
flowStableSecTextBox.Enabled = true;
|
||||
}
|
||||
|
||||
public CfgVerifyFlags VerifyCfg(ref string message)
|
||||
public CfgUpdateFlags VerifyCfg(ref string message)
|
||||
{
|
||||
CfgVerifyFlags flags = CfgVerifyFlags.None;
|
||||
CfgUpdateFlags flags = CfgUpdateFlags.AnyChange;
|
||||
|
||||
int dummy;
|
||||
if (!parentNameComboBox.Items.Contains(parentNameComboBox.Text))
|
||||
{
|
||||
flags |= CfgVerifyFlags.Error;
|
||||
flags |= CfgUpdateFlags.Error;
|
||||
message += Environment.NewLine + "Invalid 'Parent Name'";
|
||||
}
|
||||
if (!int.TryParse(positionTextBox.Text, out dummy) || dummy < 1 || dummy > 5)
|
||||
{
|
||||
flags |= CfgVerifyFlags.Error;
|
||||
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 |= CfgVerifyFlags.Error;
|
||||
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 |= CfgVerifyFlags.Error;
|
||||
flags |= CfgUpdateFlags.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;
|
||||
flags |= CfgUpdateFlags.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;
|
||||
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 |= CfgVerifyFlags.Error;
|
||||
flags |= CfgUpdateFlags.Error;
|
||||
message += Environment.NewLine + "'Flow stable' should be between 0 and 60 sec";
|
||||
}
|
||||
|
||||
return flags;
|
||||
}
|
||||
|
||||
public void UpdateCfg()
|
||||
public CfgUpdateFlags UpdateCfg()
|
||||
{
|
||||
if (config == null) return; /// Control was not loaded, settings were not changed
|
||||
CfgUpdateFlags flags = CfgUpdateFlags.None;
|
||||
|
||||
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);
|
||||
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(pidCoefTextBox.Text);
|
||||
if (config.PidCoef != tmp)
|
||||
{
|
||||
config.PidCoef = tmp;
|
||||
flags |= 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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user