107 lines
2.6 KiB
C#
107 lines
2.6 KiB
C#
///
|
|
/// Copyright (c) 2017 Sensus Metering Systems
|
|
///
|
|
using System;
|
|
using System.Windows.Forms;
|
|
using log4net;
|
|
using TBF.BenchControl.Generic;
|
|
|
|
namespace TBF.BenchControl.Modbus.Easytherm
|
|
{
|
|
public partial class EasythermCfgCtrl : UserControl, IComponentCfgCtrl
|
|
{
|
|
static readonly ILog log = LogManager.GetLogger(typeof(EasythermCfgCtrl));
|
|
|
|
ComponentParametersDlg parent;
|
|
|
|
public bool ShowMore { get { return false; } }
|
|
|
|
EasythermCfg config;
|
|
public IComponentCfg Config
|
|
{
|
|
get { return config as IComponentCfg; }
|
|
set
|
|
{
|
|
config = value as EasythermCfg;
|
|
Redraw();
|
|
}
|
|
}
|
|
|
|
public EasythermCfgCtrl()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void QuidoRSCfgCtrl_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 Modbus.Common.Factory)
|
|
{
|
|
parentNameComboBox.Items.Add(cmpnt.Name);
|
|
}
|
|
}
|
|
}
|
|
|
|
Redraw();
|
|
}
|
|
|
|
public void Closing()
|
|
{
|
|
}
|
|
|
|
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;
|
|
modbusAddressTextBox.Text = config.ModbusAddress.ToString();
|
|
}
|
|
|
|
public void Unlock()
|
|
{
|
|
nameTextBox.Enabled = true;
|
|
parentNameComboBox.Enabled = true;
|
|
modbusAddressTextBox.Enabled = true;
|
|
}
|
|
|
|
public CfgUpdateFlags VerifyCfg(ref string message)
|
|
{
|
|
CfgUpdateFlags flags = CfgUpdateFlags.None;
|
|
|
|
int dummy;
|
|
if (!parentNameComboBox.Items.Contains(parentNameComboBox.Text))
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "Invalid 'Parent Name'";
|
|
}
|
|
if (!int.TryParse(modbusAddressTextBox.Text, out dummy) || dummy < 0 || dummy > 255)
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "'Modbus Address' should be between 0 and 255";
|
|
}
|
|
return flags;
|
|
}
|
|
|
|
public CfgUpdateFlags UpdateCfg()
|
|
{
|
|
CfgUpdateFlags flags = CfgUpdateFlags.RestartRqrd;
|
|
|
|
if (config == null) return CfgUpdateFlags.Error; /// Control was not loaded, settings were not changed
|
|
|
|
config.Name = nameTextBox.Text;
|
|
config.ParentName = parentNameComboBox.Text.Equals("---") ? string.Empty : parentNameComboBox.Text;
|
|
config.ModbusAddress = (byte)int.Parse(modbusAddressTextBox.Text);
|
|
|
|
return flags;
|
|
}
|
|
}
|
|
}
|