226 lines
7.9 KiB
C#
226 lines
7.9 KiB
C#
///
|
|
/// Copyright (c) 2013-2021 Sensus Slovensko a.s.
|
|
///
|
|
using System;
|
|
using System.Windows.Forms;
|
|
using System.IO.Ports;
|
|
using Common;
|
|
using Config.Entities;
|
|
using TBF.Rig.Generic;
|
|
using TBF.UI.Bench.Components;
|
|
|
|
namespace TBF.Rig.MettlerToledo.Standard
|
|
{
|
|
public partial class BalanceCfgCtrl : UserControl, IComponentCfgCtrl
|
|
{
|
|
ComponentParametersDlg parent;
|
|
|
|
public bool ShowMore { get { return false; } }
|
|
|
|
BalanceCfg config;
|
|
public IComponentCfg Config
|
|
{
|
|
get { return config as IComponentCfg; }
|
|
set
|
|
{
|
|
config = value as BalanceCfg;
|
|
Redraw();
|
|
}
|
|
}
|
|
|
|
|
|
public BalanceCfgCtrl()
|
|
{
|
|
InitializeComponent();
|
|
|
|
for (ActionA1D a = 0; a < ActionA1D.Count; a++)
|
|
{
|
|
afterFirstDrainingComboBox.Items.Add(a.ToString());
|
|
}
|
|
|
|
parityComboBox.Items.Add(Parity.None.ToString());
|
|
parityComboBox.Items.Add(Parity.Even.ToString());
|
|
parityComboBox.Items.Add(Parity.Odd.ToString());
|
|
|
|
stopBitsComboBox.Items.Add(StopBits.None.ToString());
|
|
stopBitsComboBox.Items.Add(StopBits.One.ToString());
|
|
stopBitsComboBox.Items.Add(StopBits.OnePointFive.ToString());
|
|
stopBitsComboBox.Items.Add(StopBits.Two.ToString());
|
|
|
|
handshakeComboBox.Items.Add(Handshake.None.ToString());
|
|
handshakeComboBox.Items.Add(Handshake.RequestToSend.ToString());
|
|
handshakeComboBox.Items.Add(Handshake.XOnXOff.ToString());
|
|
}
|
|
|
|
private void BalanceCfgCtrl_Load(object sender, EventArgs e)
|
|
{
|
|
parent = ParentForm as ComponentParametersDlg;
|
|
if (parent == null) return;
|
|
|
|
if (parent.CmpntEntities != null)
|
|
{
|
|
evaporationComboBox.Items.Add("---");
|
|
drainValveComboBox.Items.Add("---");
|
|
foreach (var cmpnt in parent.CmpntEntities)
|
|
{
|
|
if (TbfComponents.CmpntFactoryFromClassName(cmpnt.ClassName) is Elde.Valve.ValveFactory)
|
|
{
|
|
drainValveComboBox.Items.Add(cmpnt.Name);
|
|
}
|
|
else if (TbfComponents.CmpntFactoryFromClassName(cmpnt.ClassName) is DataContainers.Evaporation.Factory)
|
|
{
|
|
evaporationComboBox.Items.Add(cmpnt.Name);
|
|
}
|
|
}
|
|
}
|
|
|
|
Redraw();
|
|
}
|
|
|
|
public void Closing()
|
|
{
|
|
}
|
|
|
|
void Redraw()
|
|
{
|
|
if (config == null) return; /// Control was not loaded, settings were not changed
|
|
|
|
classNameLabel.Text = config.Factory.ClassName;
|
|
nameTextBox.Text = config.Name;
|
|
capacityTextBox.Text = config.Capacity.ToString();
|
|
emptyTextBox.Text = config.Empty.ToString();
|
|
emptyUpTextBox.Text = config.EmptyUp.ToString();
|
|
formatTextBox.Text = (config.Format.Length > 1) ? config.Format.Substring(1) : config.Format;
|
|
evaporationComboBox.Text = string.IsNullOrEmpty(config.Evaporation) ? "---" : config.Evaporation;
|
|
drainValveComboBox.Text = string.IsNullOrEmpty(config.DrainValve) ? "---" : config.DrainValve;
|
|
drainTimeTextBox.Text = config.DrainTimeSec.ToString();
|
|
afterFirstDrainingComboBox.Text = config.ActionAfter1stDraining.ToString();
|
|
|
|
comPortNrTextBox.Text = config.ComPortNr.ToString();
|
|
baudRateTextBox.Text = config.BaudRate.ToString();
|
|
parityComboBox.Text = config.Parity.ToString();
|
|
dataBitsTextBox.Text = config.DataBits.ToString();
|
|
stopBitsComboBox.Text = config.StopBits.ToString();
|
|
handshakeComboBox.Text = config.Handshake.ToString();
|
|
}
|
|
|
|
public void Unlock()
|
|
{
|
|
nameTextBox.Enabled = true;
|
|
capacityTextBox.Enabled = true;
|
|
emptyTextBox.Enabled = true;
|
|
emptyUpTextBox.Enabled = true;
|
|
formatTextBox.Enabled = true;
|
|
evaporationComboBox.Enabled = true;
|
|
drainValveComboBox.Enabled = true;
|
|
drainTimeTextBox.Enabled = true;
|
|
afterFirstDrainingComboBox.Enabled = true;
|
|
|
|
comPortNrTextBox.Enabled = true;
|
|
baudRateTextBox.Enabled = true;
|
|
parityComboBox.Enabled = true;
|
|
dataBitsTextBox.Enabled = true;
|
|
stopBitsComboBox.Enabled = true;
|
|
handshakeComboBox.Enabled = true;
|
|
}
|
|
|
|
public CfgUpdateFlags VerifyCfg(ref string message)
|
|
{
|
|
CfgUpdateFlags flags = CfgUpdateFlags.None;
|
|
|
|
int dummy;
|
|
if (!int.TryParse(comPortNrTextBox.Text, out dummy) || dummy < 1 || dummy > 999)
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "'Serial Port Number' is not valid";
|
|
}
|
|
if (!int.TryParse(baudRateTextBox.Text, out dummy) || dummy < 150 || dummy > 115200)
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "'Baud Rate' is not valid";
|
|
}
|
|
if (!int.TryParse(dataBitsTextBox.Text, out dummy) || dummy < 7 || dummy > 8)
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "'Data Bits' is not valid";
|
|
}
|
|
float mass;
|
|
if (!Utils.TryParseUFloat(capacityTextBox.Text, out mass) || mass <= 0)
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "'Tank Capacity' is not valid";
|
|
}
|
|
if (!Utils.TryParseUFloat(emptyTextBox.Text, out mass) || mass <= 0)
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "'Tank Empty' is not valid";
|
|
}
|
|
if (!Utils.TryParseUFloat(emptyUpTextBox.Text, out mass) || mass <= 0)
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "'Tank Empty Up' is not valid";
|
|
}
|
|
if (!int.TryParse(formatTextBox.Text, out dummy) || dummy < 0 || dummy > 9)
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "'Decimal points' should be between 0 and 9";
|
|
}
|
|
if (!evaporationComboBox.Items.Contains(evaporationComboBox.Text))
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "Invalid 'Evaporation'";
|
|
}
|
|
if (!drainValveComboBox.Items.Contains(drainValveComboBox.Text))
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "Invalid 'Drain valve'";
|
|
}
|
|
if (!int.TryParse(drainTimeTextBox.Text, out dummy) || dummy < 1 || dummy > 999)
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "'Tank drain time' should be between 1 and 999 sec";
|
|
}
|
|
if (!afterFirstDrainingComboBox.Items.Contains(afterFirstDrainingComboBox.Text))
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "Invalid 'Avter 1st draining'";
|
|
}
|
|
|
|
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.Capacity = Utils.ParseUFloat(capacityTextBox.Text);
|
|
config.Empty = Utils.ParseUFloat(emptyTextBox.Text);
|
|
config.EmptyUp = Utils.ParseUFloat(emptyUpTextBox.Text);
|
|
config.Format = "F" + formatTextBox.Text;
|
|
config.Evaporation = evaporationComboBox.Text.Equals("---") ? string.Empty : evaporationComboBox.Text;
|
|
config.DrainTimeSec = int.Parse(drainTimeTextBox.Text);
|
|
config.DrainValve = drainValveComboBox.Text.Equals("---") ? string.Empty : drainValveComboBox.Text;
|
|
for (ActionA1D a = 0; a < ActionA1D.Count; a++)
|
|
{
|
|
if (afterFirstDrainingComboBox.Text == a.ToString())
|
|
{
|
|
config.ActionAfter1stDraining = a;
|
|
break;
|
|
}
|
|
}
|
|
|
|
config.ComPortNr = int.Parse(comPortNrTextBox.Text);
|
|
config.BaudRate = int.Parse(baudRateTextBox.Text);
|
|
config.Parity = Utils.GetParity(parityComboBox.SelectedItem.ToString());
|
|
config.DataBits = int.Parse(dataBitsTextBox.Text);
|
|
config.StopBits = Utils.GetStopBits(stopBitsComboBox.SelectedItem.ToString());
|
|
config.Handshake = Utils.GetHandshake(handshakeComboBox.SelectedItem.ToString());
|
|
|
|
return flags;
|
|
}
|
|
}
|
|
}
|