2015-04-15 18:32:56 +00:00
|
|
|
|
///
|
|
|
|
|
|
/// Copyright (c) 2013-2015 Sensus Metering Systems
|
|
|
|
|
|
///
|
|
|
|
|
|
using System;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
using log4net;
|
|
|
|
|
|
using TBF.BenchControl.Generic;
|
|
|
|
|
|
|
|
|
|
|
|
namespace TBF.BenchControl.Elde.PressureMeter
|
|
|
|
|
|
{
|
|
|
|
|
|
public partial class PressureMeterCfgCtrl : UserControl, IComponentCfgCtrl
|
|
|
|
|
|
{
|
|
|
|
|
|
static readonly ILog log = LogManager.GetLogger(typeof(PressureMeterCfgCtrl));
|
|
|
|
|
|
|
|
|
|
|
|
ComponentParametersDlg parent;
|
2015-01-02 22:42:01 +00:00
|
|
|
|
|
|
|
|
|
|
public bool ShowMore { get { return false; } }
|
|
|
|
|
|
|
2014-07-28 07:54:35 +00:00
|
|
|
|
PressureMeterCfg config;
|
|
|
|
|
|
public IComponentCfg Config
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return config as IComponentCfg; }
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
config = value as PressureMeterCfg;
|
|
|
|
|
|
Redraw();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public PressureMeterCfgCtrl()
|
|
|
|
|
|
{
|
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void PressureMeterCfgCtrl_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();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-01-02 22:42:01 +00:00
|
|
|
|
public void Closing()
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-07-28 07:54:35 +00:00
|
|
|
|
void Redraw()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (config == null) return; /// Control was not loaded, settings were not changed
|
|
|
|
|
|
|
|
|
|
|
|
componentNameLabel.Text = config.Factory.ClassName;
|
|
|
|
|
|
nameTextBox.Text = config.Name;
|
|
|
|
|
|
parentNameComboBox.Text = string.IsNullOrEmpty(config.ParentName) ? "---" : config.ParentName;
|
2014-09-10 10:05:49 +00:00
|
|
|
|
positionTextBox.Text = config.Idx0.ToString();
|
2014-07-28 07:54:35 +00:00
|
|
|
|
rs485AddressTextBox.Text = config.RS485Address.ToString();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Unlock()
|
|
|
|
|
|
{
|
|
|
|
|
|
nameTextBox.Enabled = true;
|
|
|
|
|
|
parentNameComboBox.Enabled = true;
|
|
|
|
|
|
positionTextBox.Enabled = true;
|
|
|
|
|
|
rs485AddressTextBox.Enabled = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-01-02 22:42:01 +00:00
|
|
|
|
public CfgUpdateFlags VerifyCfg(ref string message)
|
2014-07-28 07:54:35 +00:00
|
|
|
|
{
|
2015-01-11 04:06:18 +00:00
|
|
|
|
CfgUpdateFlags flags = CfgUpdateFlags.None;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
|
|
|
|
|
int dummy;
|
|
|
|
|
|
if (!parentNameComboBox.Items.Contains(parentNameComboBox.Text))
|
|
|
|
|
|
{
|
2015-01-02 22:42:01 +00:00
|
|
|
|
flags |= CfgUpdateFlags.Error;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
message += Environment.NewLine + "Invalid 'Parent Name'";
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!int.TryParse(positionTextBox.Text, out dummy) || dummy < 0 || dummy > 7)
|
|
|
|
|
|
{
|
2015-01-02 22:42:01 +00:00
|
|
|
|
flags |= CfgUpdateFlags.Error;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
message += Environment.NewLine + "'Position' should be between 0 and 7";
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!int.TryParse(rs485AddressTextBox.Text, out dummy) || dummy < 0 || dummy > 255)
|
|
|
|
|
|
{
|
2015-01-02 22:42:01 +00:00
|
|
|
|
flags |= CfgUpdateFlags.Error;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
message += Environment.NewLine + "'RS485 Address' should be between 0 and 255";
|
|
|
|
|
|
}
|
|
|
|
|
|
return flags;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-01-02 22:42:01 +00:00
|
|
|
|
public CfgUpdateFlags UpdateCfg()
|
2014-07-28 07:54:35 +00:00
|
|
|
|
{
|
2015-01-11 04:06:18 +00:00
|
|
|
|
CfgUpdateFlags flags = CfgUpdateFlags.RestartRqrd;
|
2015-01-02 22:42:01 +00:00
|
|
|
|
|
|
|
|
|
|
if (config == null) return CfgUpdateFlags.Error; /// Control was not loaded, settings were not changed
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
|
|
|
|
|
config.Name = nameTextBox.Text;
|
|
|
|
|
|
config.ParentName = parentNameComboBox.Text.Equals("---") ? string.Empty : parentNameComboBox.Text;
|
2014-09-10 10:05:49 +00:00
|
|
|
|
config.Idx0 = int.Parse(positionTextBox.Text);
|
2014-07-28 07:54:35 +00:00
|
|
|
|
config.RS485Address = (byte)int.Parse(rs485AddressTextBox.Text);
|
2015-01-02 22:42:01 +00:00
|
|
|
|
|
|
|
|
|
|
return flags;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|