/// /// Copyright (c) 2018 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.Resources; namespace TBF.Rig.RegisterReaders.KPackE.Radio { 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); 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; } 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; } } }