162 lines
5.1 KiB
C#
162 lines
5.1 KiB
C#
///
|
|
/// Copyright (c) 2015-2017 Sensus Metering Systems
|
|
///
|
|
using System;
|
|
using System.Net;
|
|
using System.Net.Sockets;
|
|
using System.Windows.Forms;
|
|
using log4net;
|
|
using TBF.BenchControl.Generic;
|
|
using TBF.Resources;
|
|
|
|
namespace TBF.BenchControl.TestMethods.iPerlCommunication.iPerlHead
|
|
{
|
|
public partial class IperlHeadCfgCtrl : UserControl, IComponentCfgCtrl
|
|
{
|
|
static readonly ILog log = LogManager.GetLogger(typeof(IperlHeadCfgCtrl));
|
|
|
|
public bool ShowMore { get { return false; } }
|
|
|
|
IperlHeadCfg config;
|
|
public IComponentCfg Config
|
|
{
|
|
get { return config as IComponentCfg; }
|
|
set
|
|
{
|
|
config = value as IperlHeadCfg;
|
|
Redraw();
|
|
}
|
|
}
|
|
|
|
public IperlHeadCfgCtrl()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void WaterMeterCfgCtrl_Load(object sender, EventArgs e)
|
|
{
|
|
nameLabel.Text = Strings.Name;
|
|
classNameLabel.Text = config.Factory.ClassName;
|
|
Redraw();
|
|
}
|
|
|
|
public void Closing()
|
|
{
|
|
}
|
|
|
|
void Redraw()
|
|
{
|
|
if (config == null) return; /// Control was not loaded, settings were not changed
|
|
nameTextBox.Text = config.Name;
|
|
radioButton1.Checked = config.UseTcpIP;
|
|
radioButton2.Checked = !config.UseTcpIP;
|
|
ipAddressTextBox.Text = (config.OptoIPAddress != null) ? config.OptoIPAddress : "0.0.0.0";
|
|
tcpipPortTextBox.Text = config.OptoTcpipPortNr.ToString();
|
|
optoSerialPortTextBox.Text = config.OptoComPortNr.ToString();
|
|
rfidPortNrTextBox.Text = config.RfidComPortNr.ToString();
|
|
muxBoardNrTextBox.Text = config.MuxBoardNr.ToString();
|
|
groupTextBox.Text = config.Group.ToString();
|
|
}
|
|
|
|
public void Unlock()
|
|
{
|
|
nameTextBox.Enabled = true;
|
|
radioButton1.Enabled = true;
|
|
radioButton2.Enabled = true;
|
|
ipAddressTextBox.Enabled = true;
|
|
tcpipPortTextBox.Enabled = true;
|
|
optoSerialPortTextBox.Enabled = true;
|
|
rfidPortNrTextBox.Enabled = true;
|
|
muxBoardNrTextBox.Enabled = true;
|
|
groupTextBox.Enabled = true;
|
|
}
|
|
|
|
public CfgUpdateFlags VerifyCfg(ref string message)
|
|
{
|
|
CfgUpdateFlags flags = CfgUpdateFlags.None;
|
|
|
|
int dummy, dummy2;
|
|
if (radioButton1.Checked)
|
|
{
|
|
IPAddress dummyIPAddress;
|
|
if (!IPAddress.TryParse(ipAddressTextBox.Text, out dummyIPAddress))
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "'IP address' is not valid";
|
|
}
|
|
|
|
ushort sdummy;
|
|
if (!ushort.TryParse(tcpipPortTextBox.Text, out sdummy))
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "'TCP/IP port nr.' is not valid";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (!int.TryParse(optoSerialPortTextBox.Text, out dummy) || dummy < 1 || dummy > 999)
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "'Opto serial port nr.' is not valid";
|
|
}
|
|
}
|
|
|
|
if (!int.TryParse(rfidPortNrTextBox.Text, out dummy) || dummy < 0 || dummy > 999)
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "'RFID serial port nr.' is not valid";
|
|
}
|
|
if (!int.TryParse(muxBoardNrTextBox.Text, out dummy2) || dummy2 < 0 || dummy2 > 4)
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "'Mux. board nr.' is not valid";
|
|
}
|
|
if (dummy == 0 && dummy2 == 0)
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "Either 'RFID serial port nr.' or 'Mux. board nr.' should be nonzero";
|
|
}
|
|
if (dummy != 0 && dummy2 != 0)
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "Either 'RFID serial port nr.' or 'Mux. board nr.' should be zero";
|
|
}
|
|
|
|
if (!int.TryParse(groupTextBox.Text, out dummy) || dummy < 1 || dummy > 10)
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "'Group' is not valid";
|
|
}
|
|
|
|
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;
|
|
|
|
if (radioButton1.Checked)
|
|
{
|
|
config.UseTcpIP = true;
|
|
config.OptoIPAddress = ipAddressTextBox.Text;
|
|
config.OptoTcpipPortNr = ushort.Parse(tcpipPortTextBox.Text);
|
|
}
|
|
else
|
|
{
|
|
config.UseTcpIP = false;
|
|
config.OptoComPortNr = int.Parse(optoSerialPortTextBox.Text);
|
|
}
|
|
|
|
config.RfidComPortNr = int.Parse(rfidPortNrTextBox.Text);
|
|
config.MuxBoardNr = int.Parse(muxBoardNrTextBox.Text);
|
|
config.Group = int.Parse(groupTextBox.Text);
|
|
|
|
return flags;
|
|
}
|
|
}
|
|
}
|