2019-01-16 13:52:20 +00:00
|
|
|
|
///
|
|
|
|
|
|
/// Copyright (c) 2018 Sensus Slovensko a.s.
|
|
|
|
|
|
///
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
using System.IO.Ports;
|
2021-09-23 09:46:40 +00:00
|
|
|
|
using Common;
|
2019-01-16 13:52:20 +00:00
|
|
|
|
using Config.Entities;
|
2021-10-26 09:23:57 +00:00
|
|
|
|
using TBF.Rig.Generic;
|
2019-01-16 13:52:20 +00:00
|
|
|
|
using TBF.Resources;
|
|
|
|
|
|
|
2021-10-26 09:23:57 +00:00
|
|
|
|
namespace TBF.Rig.RegisterReaders.KPackE.Radio
|
2019-01-16 13:52:20 +00:00
|
|
|
|
{
|
|
|
|
|
|
public partial class RadioCfgCtrl : UserControl, IComponentCfgCtrl
|
|
|
|
|
|
{
|
|
|
|
|
|
public bool ShowMore { get { return false; } }
|
|
|
|
|
|
|
|
|
|
|
|
RadioCfg config;
|
|
|
|
|
|
public IComponentCfg Config
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return config as IComponentCfg; }
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
config = value as RadioCfg;
|
|
|
|
|
|
Redraw();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public RadioCfgCtrl()
|
|
|
|
|
|
{
|
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
|
|
|
|
|
|
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 ModbusCfgCtrl_Load(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
nameLabel.Text = Strings.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;
|
|
|
|
|
|
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;
|
|
|
|
|
|
comPortNrTextBox.Enabled = true;
|
|
|
|
|
|
baudRateTextBox.Enabled = true;
|
|
|
|
|
|
parityComboBox.Enabled = true;
|
|
|
|
|
|
dataBitsTextBox.Enabled = true;
|
|
|
|
|
|
stopBitsComboBox.Enabled = true;
|
|
|
|
|
|
handshakeComboBox.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;
|
|
|
|
|
|
config.ComPortNr = int.Parse(comPortNrTextBox.Text);
|
|
|
|
|
|
config.BaudRate = int.Parse(baudRateTextBox.Text);
|
2022-06-22 11:51:39 +00:00
|
|
|
|
config.Parity = Utils.GetParity(parityComboBox.SelectedItem.ToString());
|
2019-01-16 13:52:20 +00:00
|
|
|
|
config.DataBits = int.Parse(dataBitsTextBox.Text);
|
2022-06-22 11:51:39 +00:00
|
|
|
|
config.StopBits = Utils.GetStopBits(stopBitsComboBox.SelectedItem.ToString());
|
|
|
|
|
|
config.Handshake = Utils.GetHandshake(handshakeComboBox.SelectedItem.ToString());
|
2019-01-16 13:52:20 +00:00
|
|
|
|
|
|
|
|
|
|
return flags;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return flags;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|