2015-04-15 18:32:56 +00:00
|
|
|
|
///
|
|
|
|
|
|
/// Copyright (c) 2013-2015 Sensus Metering Systems
|
|
|
|
|
|
///
|
|
|
|
|
|
using System;
|
2015-02-16 12:36:22 +00:00
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
using System.IO.Ports;
|
|
|
|
|
|
using log4net;
|
|
|
|
|
|
using TBF.BenchControl.Generic;
|
|
|
|
|
|
|
|
|
|
|
|
namespace TBF.BenchControl.Danfoss.VLT2800
|
|
|
|
|
|
{
|
|
|
|
|
|
public partial class PumpCfgCtrl : UserControl, IComponentCfgCtrl
|
|
|
|
|
|
{
|
|
|
|
|
|
static readonly ILog log = LogManager.GetLogger(typeof(PumpCfgCtrl));
|
|
|
|
|
|
|
|
|
|
|
|
public bool ShowMore { get { return false; } }
|
|
|
|
|
|
|
|
|
|
|
|
PumpCfg config;
|
|
|
|
|
|
public IComponentCfg Config
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return config as IComponentCfg; }
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
config = value as PumpCfg;
|
|
|
|
|
|
Redraw();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public PumpCfgCtrl()
|
|
|
|
|
|
{
|
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
|
2015-02-18 15:19:37 +00:00
|
|
|
|
protocolComboBox.Items.Add(PumpProtocol.Modbus.ToString());
|
|
|
|
|
|
protocolComboBox.Items.Add(PumpProtocol.FC.ToString());
|
|
|
|
|
|
|
2015-02-16 12:36:22 +00:00
|
|
|
|
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());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int GetParityIx(Parity par)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (par == Parity.None) return 0;
|
|
|
|
|
|
if (par == Parity.Even) return 0;
|
|
|
|
|
|
if (par == Parity.Odd) return 0;
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
Parity GetParity(string str)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (str.Equals(Parity.None.ToString())) return Parity.None;
|
|
|
|
|
|
if (str.Equals(Parity.Even.ToString())) return Parity.Even;
|
|
|
|
|
|
if (str.Equals(Parity.Odd.ToString())) return Parity.Odd;
|
|
|
|
|
|
return (Parity)(-1);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int GetStopBitsIx(StopBits sb)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (sb == StopBits.None) return 0;
|
|
|
|
|
|
if (sb == StopBits.One) return 1;
|
|
|
|
|
|
if (sb == StopBits.OnePointFive) return 2;
|
|
|
|
|
|
if (sb == StopBits.Two) return 3;
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
StopBits GetStopBits(string str)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (str.Equals(StopBits.None.ToString())) return StopBits.None;
|
|
|
|
|
|
if (str.Equals(StopBits.One.ToString())) return StopBits.One;
|
|
|
|
|
|
if (str.Equals(StopBits.OnePointFive.ToString())) return StopBits.OnePointFive;
|
|
|
|
|
|
if (str.Equals(StopBits.Two.ToString())) return StopBits.Two;
|
|
|
|
|
|
return (StopBits)(-1);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int GetHandshakeIx(Handshake par)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (par == Handshake.None) return 0;
|
|
|
|
|
|
if (par == Handshake.RequestToSend) return 0;
|
|
|
|
|
|
if (par == Handshake.XOnXOff) return 0;
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
Handshake GetHandshake(string str)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (str.Equals(Handshake.None.ToString())) return Handshake.None;
|
|
|
|
|
|
if (str.Equals(Handshake.RequestToSend.ToString())) return Handshake.RequestToSend;
|
|
|
|
|
|
if (str.Equals(Handshake.XOnXOff.ToString())) return Handshake.XOnXOff;
|
|
|
|
|
|
return (Handshake)(-1);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void AbbientCfgCtrl_Load(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
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;
|
2015-02-16 20:01:37 +00:00
|
|
|
|
delayTextBox.Text = config.Delay.ToString();
|
2015-02-18 21:50:44 +00:00
|
|
|
|
bitPositionTextBox.Text = config.BitPosition.ToString();
|
2015-02-18 15:19:37 +00:00
|
|
|
|
protocolComboBox.Text = config.Protocol.ToString();
|
|
|
|
|
|
busAddressTextBox.Text = config.BusAddress.ToString();
|
2015-02-16 12:36:22 +00:00
|
|
|
|
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();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Unlock()
|
|
|
|
|
|
{
|
|
|
|
|
|
nameTextBox.Enabled = true;
|
2015-02-16 20:01:37 +00:00
|
|
|
|
delayTextBox.Enabled = true;
|
2015-02-18 21:50:44 +00:00
|
|
|
|
bitPositionTextBox.Enabled = true;
|
2015-02-18 15:19:37 +00:00
|
|
|
|
protocolComboBox.Enabled = true;
|
|
|
|
|
|
busAddressTextBox.Enabled = true;
|
2015-02-16 12:36:22 +00:00
|
|
|
|
comPortNrTextBox.Enabled = true;
|
|
|
|
|
|
baudRateTextBox.Enabled = true;
|
|
|
|
|
|
parityComboBox.Enabled = true;
|
|
|
|
|
|
dataBitsTextBox.Enabled = true;
|
|
|
|
|
|
stopBitsComboBox.Enabled = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
2015-02-16 20:01:37 +00:00
|
|
|
|
config.Delay = int.Parse(delayTextBox.Text);
|
2015-02-18 21:50:44 +00:00
|
|
|
|
config.BitPosition = int.Parse(bitPositionTextBox.Text);
|
2015-02-18 15:19:37 +00:00
|
|
|
|
config.Protocol = protocolComboBox.Text.Equals(PumpProtocol.Modbus.ToString()) ? PumpProtocol.Modbus : PumpProtocol.FC;
|
|
|
|
|
|
config.BusAddress = int.Parse(busAddressTextBox.Text);
|
2015-02-16 12:36:22 +00:00
|
|
|
|
config.ComPortNr = int.Parse(comPortNrTextBox.Text);
|
|
|
|
|
|
config.BaudRate = int.Parse(baudRateTextBox.Text);
|
|
|
|
|
|
config.Parity = GetParity(parityComboBox.SelectedItem.ToString());
|
|
|
|
|
|
config.DataBits = int.Parse(dataBitsTextBox.Text);
|
|
|
|
|
|
config.StopBits = GetStopBits(stopBitsComboBox.SelectedItem.ToString());
|
|
|
|
|
|
|
|
|
|
|
|
return flags;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public CfgUpdateFlags VerifyCfg(ref string message)
|
|
|
|
|
|
{
|
|
|
|
|
|
CfgUpdateFlags flags = CfgUpdateFlags.None;
|
|
|
|
|
|
|
|
|
|
|
|
int dummy;
|
2015-02-16 20:01:37 +00:00
|
|
|
|
if (!int.TryParse(delayTextBox.Text, out dummy) || dummy < 0 || dummy > 300)
|
|
|
|
|
|
{
|
|
|
|
|
|
flags |= CfgUpdateFlags.Error;
|
|
|
|
|
|
message += Environment.NewLine + "'Delay' is not valid";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-02-18 21:50:44 +00:00
|
|
|
|
if (!int.TryParse(bitPositionTextBox.Text, out dummy) || dummy < 0 || dummy >= 64)
|
|
|
|
|
|
{
|
|
|
|
|
|
flags |= CfgUpdateFlags.Error;
|
|
|
|
|
|
message += Environment.NewLine + "'Bit Position' should be between 0 and 63";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-02-18 15:19:37 +00:00
|
|
|
|
if (!protocolComboBox.Items.Contains(protocolComboBox.Text))
|
|
|
|
|
|
{
|
|
|
|
|
|
flags |= CfgUpdateFlags.Error;
|
|
|
|
|
|
message += Environment.NewLine + "'Protocol' should Modbus or FC";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!int.TryParse(busAddressTextBox.Text, out dummy) || dummy < 1 || dummy > 247)
|
2015-02-16 20:01:37 +00:00
|
|
|
|
{
|
|
|
|
|
|
flags |= CfgUpdateFlags.Error;
|
2015-02-18 15:19:37 +00:00
|
|
|
|
message += Environment.NewLine + "'Bus Address' should be in range 1..247";
|
2015-02-16 20:01:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2015-02-16 12:36:22 +00:00
|
|
|
|
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";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return flags;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|