Refactorization : Common.Utils.GetParity( ) / GetStopBits( ) / GetHandshake( ) ...
This commit is contained in:
parent
f47e7670a3
commit
6e04933eeb
@ -2,6 +2,7 @@
|
|||||||
/// Copyright (c) 2021-2022 Sensus Slovensko a.s.
|
/// Copyright (c) 2021-2022 Sensus Slovensko a.s.
|
||||||
///
|
///
|
||||||
using System;
|
using System;
|
||||||
|
using System.IO.Ports;
|
||||||
|
|
||||||
namespace Common
|
namespace Common
|
||||||
{
|
{
|
||||||
@ -92,5 +93,33 @@ namespace Common
|
|||||||
else return "F5";
|
else return "F5";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Parity GetParity(string str, Parity defaultParity = Parity.None)
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
if (str.Equals(Parity.Mark.ToString())) return Parity.Mark;
|
||||||
|
if (str.Equals(Parity.Space.ToString())) return Parity.Space;
|
||||||
|
return defaultParity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static StopBits GetStopBits(string str, StopBits defaultStopBits = StopBits.One)
|
||||||
|
{
|
||||||
|
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 defaultStopBits;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Handshake GetHandshake(string str, Handshake defaultHandshake = Handshake.None)
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
if (str.Equals(Handshake.RequestToSendXOnXOff.ToString())) return Handshake.RequestToSendXOnXOff;
|
||||||
|
return defaultHandshake;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -88,10 +88,10 @@ namespace TBF.Rig.Ambient.Comet
|
|||||||
config.Name = nameTextBox.Text;
|
config.Name = nameTextBox.Text;
|
||||||
config.ComPortNr = int.Parse(comPortNrTextBox.Text);
|
config.ComPortNr = int.Parse(comPortNrTextBox.Text);
|
||||||
config.BaudRate = int.Parse(baudRateTextBox.Text);
|
config.BaudRate = int.Parse(baudRateTextBox.Text);
|
||||||
config.Parity = Utils.GetParity(parityComboBox.SelectedItem.ToString());
|
config.Parity = Common.Utils.GetParity(parityComboBox.SelectedItem.ToString());
|
||||||
config.DataBits = int.Parse(dataBitsTextBox.Text);
|
config.DataBits = int.Parse(dataBitsTextBox.Text);
|
||||||
config.StopBits = Utils.GetStopBits(stopBitsComboBox.SelectedItem.ToString());
|
config.StopBits = Common.Utils.GetStopBits(stopBitsComboBox.SelectedItem.ToString());
|
||||||
config.Handshake = Utils.GetHandshake(handshakeComboBox.SelectedItem.ToString());
|
config.Handshake = Common.Utils.GetHandshake(handshakeComboBox.SelectedItem.ToString());
|
||||||
config.SetDtrToOne = setDtrCheckBox.Checked;
|
config.SetDtrToOne = setDtrCheckBox.Checked;
|
||||||
|
|
||||||
return flags;
|
return flags;
|
||||||
|
|||||||
@ -86,10 +86,10 @@ namespace TBF.Rig.Ambient.Greco
|
|||||||
config.Name = nameTextBox.Text;
|
config.Name = nameTextBox.Text;
|
||||||
config.ComPortNr = int.Parse(comPortNrTextBox.Text);
|
config.ComPortNr = int.Parse(comPortNrTextBox.Text);
|
||||||
config.BaudRate = int.Parse(baudRateTextBox.Text);
|
config.BaudRate = int.Parse(baudRateTextBox.Text);
|
||||||
config.Parity = Utils.GetParity(parityComboBox.SelectedItem.ToString());
|
config.Parity = Common.Utils.GetParity(parityComboBox.SelectedItem.ToString());
|
||||||
config.DataBits = int.Parse(dataBitsTextBox.Text);
|
config.DataBits = int.Parse(dataBitsTextBox.Text);
|
||||||
config.StopBits = Utils.GetStopBits(stopBitsComboBox.SelectedItem.ToString());
|
config.StopBits = Common.Utils.GetStopBits(stopBitsComboBox.SelectedItem.ToString());
|
||||||
config.Handshake = Utils.GetHandshake(handshakeComboBox.SelectedItem.ToString());
|
config.Handshake = Common.Utils.GetHandshake(handshakeComboBox.SelectedItem.ToString());
|
||||||
|
|
||||||
return flags;
|
return flags;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -96,9 +96,9 @@ namespace TBF.Rig.Danfoss.VLT2800
|
|||||||
config.BusAddress = int.Parse(busAddressTextBox.Text);
|
config.BusAddress = int.Parse(busAddressTextBox.Text);
|
||||||
config.ComPortNr = int.Parse(comPortNrTextBox.Text);
|
config.ComPortNr = int.Parse(comPortNrTextBox.Text);
|
||||||
config.BaudRate = int.Parse(baudRateTextBox.Text);
|
config.BaudRate = int.Parse(baudRateTextBox.Text);
|
||||||
config.Parity = Utils.GetParity(parityComboBox.SelectedItem.ToString());
|
config.Parity = Common.Utils.GetParity(parityComboBox.SelectedItem.ToString());
|
||||||
config.DataBits = int.Parse(dataBitsTextBox.Text);
|
config.DataBits = int.Parse(dataBitsTextBox.Text);
|
||||||
config.StopBits = Utils.GetStopBits(stopBitsComboBox.SelectedItem.ToString());
|
config.StopBits = Common.Utils.GetStopBits(stopBitsComboBox.SelectedItem.ToString());
|
||||||
|
|
||||||
return flags;
|
return flags;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -88,10 +88,10 @@ namespace TBF.Rig.Keithley.Multimeter_2010_RS232
|
|||||||
config.Name = nameTextBox.Text;
|
config.Name = nameTextBox.Text;
|
||||||
config.ComPortNr = int.Parse(comPortNrTextBox.Text);
|
config.ComPortNr = int.Parse(comPortNrTextBox.Text);
|
||||||
config.BaudRate = int.Parse(baudRateTextBox.Text);
|
config.BaudRate = int.Parse(baudRateTextBox.Text);
|
||||||
config.Parity = Utils.GetParity(parityComboBox.SelectedItem.ToString());
|
config.Parity = Common.Utils.GetParity(parityComboBox.SelectedItem.ToString());
|
||||||
config.DataBits = int.Parse(dataBitsTextBox.Text);
|
config.DataBits = int.Parse(dataBitsTextBox.Text);
|
||||||
config.StopBits = Utils.GetStopBits(stopBitsComboBox.SelectedItem.ToString());
|
config.StopBits = Common.Utils.GetStopBits(stopBitsComboBox.SelectedItem.ToString());
|
||||||
config.Handshake = Utils.GetHandshake(handshakeComboBox.SelectedItem.ToString());
|
config.Handshake = Common.Utils.GetHandshake(handshakeComboBox.SelectedItem.ToString());
|
||||||
|
|
||||||
return flags;
|
return flags;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -200,10 +200,10 @@ namespace TBF.Rig.MettlerToledo.Multi
|
|||||||
{
|
{
|
||||||
config.ComPortNr = int.Parse(comPortNrTextBox.Text);
|
config.ComPortNr = int.Parse(comPortNrTextBox.Text);
|
||||||
config.BaudRate = int.Parse(baudRateTextBox.Text);
|
config.BaudRate = int.Parse(baudRateTextBox.Text);
|
||||||
config.Parity = Utils.GetParity(parityComboBox.SelectedItem.ToString());
|
config.Parity = Common.Utils.GetParity(parityComboBox.SelectedItem.ToString());
|
||||||
config.DataBits = int.Parse(dataBitsTextBox.Text);
|
config.DataBits = int.Parse(dataBitsTextBox.Text);
|
||||||
config.StopBits = Utils.GetStopBits(stopBitsComboBox.SelectedItem.ToString());
|
config.StopBits = Common.Utils.GetStopBits(stopBitsComboBox.SelectedItem.ToString());
|
||||||
config.Handshake = Utils.GetHandshake(handshakeComboBox.SelectedItem.ToString());
|
config.Handshake = Common.Utils.GetHandshake(handshakeComboBox.SelectedItem.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
return flags;
|
return flags;
|
||||||
|
|||||||
@ -214,10 +214,10 @@ namespace TBF.Rig.MettlerToledo.Standard
|
|||||||
|
|
||||||
config.ComPortNr = int.Parse(comPortNrTextBox.Text);
|
config.ComPortNr = int.Parse(comPortNrTextBox.Text);
|
||||||
config.BaudRate = int.Parse(baudRateTextBox.Text);
|
config.BaudRate = int.Parse(baudRateTextBox.Text);
|
||||||
config.Parity = Utils.GetParity(parityComboBox.SelectedItem.ToString());
|
config.Parity = Common.Utils.GetParity(parityComboBox.SelectedItem.ToString());
|
||||||
config.DataBits = int.Parse(dataBitsTextBox.Text);
|
config.DataBits = int.Parse(dataBitsTextBox.Text);
|
||||||
config.StopBits = Utils.GetStopBits(stopBitsComboBox.SelectedItem.ToString());
|
config.StopBits = Common.Utils.GetStopBits(stopBitsComboBox.SelectedItem.ToString());
|
||||||
config.Handshake = Utils.GetHandshake(handshakeComboBox.SelectedItem.ToString());
|
config.Handshake = Common.Utils.GetHandshake(handshakeComboBox.SelectedItem.ToString());
|
||||||
|
|
||||||
return flags;
|
return flags;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,7 +5,6 @@ using System;
|
|||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using System.IO.Ports;
|
using System.IO.Ports;
|
||||||
using Common;
|
using Common;
|
||||||
using Config.Entities;
|
|
||||||
using TBF.Rig.Generic;
|
using TBF.Rig.Generic;
|
||||||
using TBF.Resources;
|
using TBF.Resources;
|
||||||
|
|
||||||
@ -88,10 +87,10 @@ namespace TBF.Rig.Modbus.Common
|
|||||||
config.Name = nameTextBox.Text;
|
config.Name = nameTextBox.Text;
|
||||||
config.ComPortNr = int.Parse(comPortNrTextBox.Text);
|
config.ComPortNr = int.Parse(comPortNrTextBox.Text);
|
||||||
config.BaudRate = int.Parse(baudRateTextBox.Text);
|
config.BaudRate = int.Parse(baudRateTextBox.Text);
|
||||||
config.Parity = Utils.GetParity(parityComboBox.SelectedItem.ToString());
|
config.Parity = global::Common.Utils.GetParity(parityComboBox.SelectedItem.ToString());
|
||||||
config.DataBits = int.Parse(dataBitsTextBox.Text);
|
config.DataBits = int.Parse(dataBitsTextBox.Text);
|
||||||
config.StopBits = Utils.GetStopBits(stopBitsComboBox.SelectedItem.ToString());
|
config.StopBits = global::Common.Utils.GetStopBits(stopBitsComboBox.SelectedItem.ToString());
|
||||||
config.Handshake = Utils.GetHandshake(handshakeComboBox.SelectedItem.ToString());
|
config.Handshake = global::Common.Utils.GetHandshake(handshakeComboBox.SelectedItem.ToString());
|
||||||
|
|
||||||
return flags;
|
return flags;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -88,10 +88,10 @@ namespace TBF.Rig.RegisterReaders.KPackE.Radio
|
|||||||
config.Name = nameTextBox.Text;
|
config.Name = nameTextBox.Text;
|
||||||
config.ComPortNr = int.Parse(comPortNrTextBox.Text);
|
config.ComPortNr = int.Parse(comPortNrTextBox.Text);
|
||||||
config.BaudRate = int.Parse(baudRateTextBox.Text);
|
config.BaudRate = int.Parse(baudRateTextBox.Text);
|
||||||
config.Parity = Utils.GetParity(parityComboBox.SelectedItem.ToString());
|
config.Parity = Common.Utils.GetParity(parityComboBox.SelectedItem.ToString());
|
||||||
config.DataBits = int.Parse(dataBitsTextBox.Text);
|
config.DataBits = int.Parse(dataBitsTextBox.Text);
|
||||||
config.StopBits = Utils.GetStopBits(stopBitsComboBox.SelectedItem.ToString());
|
config.StopBits = Common.Utils.GetStopBits(stopBitsComboBox.SelectedItem.ToString());
|
||||||
config.Handshake = Utils.GetHandshake(handshakeComboBox.SelectedItem.ToString());
|
config.Handshake = Common.Utils.GetHandshake(handshakeComboBox.SelectedItem.ToString());
|
||||||
|
|
||||||
return flags;
|
return flags;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -117,13 +117,13 @@ namespace TBF.Rig.RegisterReaders.S640Stream
|
|||||||
{
|
{
|
||||||
switch (i)
|
switch (i)
|
||||||
{
|
{
|
||||||
case 0: Position = int.Parse(str); return CfgUpdateFlags.RestartRqrd;
|
case 0: Position = int.Parse(str); return CfgUpdateFlags.RestartRqrd;
|
||||||
case 1: ComPortNr = int.Parse(str); return CfgUpdateFlags.RestartRqrd;
|
case 1: ComPortNr = int.Parse(str); return CfgUpdateFlags.RestartRqrd;
|
||||||
case 2: BaudRate = int.Parse(str); return CfgUpdateFlags.RestartRqrd;
|
case 2: BaudRate = int.Parse(str); return CfgUpdateFlags.RestartRqrd;
|
||||||
case 3: Parity = Utils.GetParity(str); return CfgUpdateFlags.RestartRqrd;
|
case 3: Parity = Common.Utils.GetParity(str); return CfgUpdateFlags.RestartRqrd;
|
||||||
case 4: DataBits = int.Parse(str); return CfgUpdateFlags.RestartRqrd;
|
case 4: DataBits = int.Parse(str); return CfgUpdateFlags.RestartRqrd;
|
||||||
case 5: StopBits = Utils.GetStopBits(str); return CfgUpdateFlags.RestartRqrd;
|
case 5: StopBits = Common.Utils.GetStopBits(str); return CfgUpdateFlags.RestartRqrd;
|
||||||
case 6: Handshake = Utils.GetHandshake(str); return CfgUpdateFlags.RestartRqrd;
|
case 6: Handshake = Common.Utils.GetHandshake(str); return CfgUpdateFlags.RestartRqrd;
|
||||||
default: return CfgUpdateFlags.None;
|
default: return CfgUpdateFlags.None;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -121,12 +121,12 @@ namespace TBF.Rig.RegisterReaders.SerialStream
|
|||||||
{
|
{
|
||||||
switch (i)
|
switch (i)
|
||||||
{
|
{
|
||||||
case 0: ComPortNr = int.Parse(str); return CfgUpdateFlags.RestartRqrd;
|
case 0: ComPortNr = int.Parse(str); return CfgUpdateFlags.RestartRqrd;
|
||||||
case 1: BaudRate = int.Parse(str); return CfgUpdateFlags.RestartRqrd;
|
case 1: BaudRate = int.Parse(str); return CfgUpdateFlags.RestartRqrd;
|
||||||
case 2: Parity = Utils.GetParity(str); return CfgUpdateFlags.RestartRqrd;
|
case 2: Parity = Common.Utils.GetParity(str); return CfgUpdateFlags.RestartRqrd;
|
||||||
case 3: DataBits = int.Parse(str); return CfgUpdateFlags.RestartRqrd;
|
case 3: DataBits = int.Parse(str); return CfgUpdateFlags.RestartRqrd;
|
||||||
case 4: StopBits = Utils.GetStopBits(str); return CfgUpdateFlags.RestartRqrd;
|
case 4: StopBits = Common.Utils.GetStopBits(str); return CfgUpdateFlags.RestartRqrd;
|
||||||
case 5: Handshake = Utils.GetHandshake(str); return CfgUpdateFlags.RestartRqrd;
|
case 5: Handshake = Common.Utils.GetHandshake(str); return CfgUpdateFlags.RestartRqrd;
|
||||||
default: return CfgUpdateFlags.None;
|
default: return CfgUpdateFlags.None;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
35
TBF/Utils.cs
35
TBF/Utils.cs
@ -4,7 +4,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.IO.Ports;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Config.Entities;
|
using Config.Entities;
|
||||||
using Dirichlet.Numerics;
|
using Dirichlet.Numerics;
|
||||||
@ -354,32 +353,16 @@ namespace TBF
|
|||||||
!fname.Contains('|');
|
!fname.Contains('|');
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Parity GetParity(string str, Parity defaultParity = Parity.None)
|
/// <summary>
|
||||||
|
/// Returns true when component named 'method' exists and it is a hydraulical test method.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="method">Component name</param>
|
||||||
|
/// <returns>true = is a hydraulical test method</returns>
|
||||||
|
public static bool IsHydroTest(string method)
|
||||||
{
|
{
|
||||||
if (str.Equals(Parity.None.ToString())) return Parity.None;
|
if (string.IsNullOrEmpty(method)) return false;
|
||||||
if (str.Equals(Parity.Even.ToString())) return Parity.Even;
|
var tm = TBF.Rig.TbfComponents.FindComponent(method) as TBF.Rig.GenericDevices.ITestMethod;
|
||||||
if (str.Equals(Parity.Odd.ToString())) return Parity.Odd;
|
return (tm != null) && tm.DoTransitions();
|
||||||
if (str.Equals(Parity.Mark.ToString())) return Parity.Mark;
|
|
||||||
if (str.Equals(Parity.Space.ToString())) return Parity.Space;
|
|
||||||
return defaultParity;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static StopBits GetStopBits(string str, StopBits defaultStopBits = StopBits.One)
|
|
||||||
{
|
|
||||||
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 defaultStopBits;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Handshake GetHandshake(string str, Handshake defaultHandshake = Handshake.None)
|
|
||||||
{
|
|
||||||
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;
|
|
||||||
if (str.Equals(Handshake.RequestToSendXOnXOff.ToString())) return Handshake.RequestToSendXOnXOff;
|
|
||||||
return defaultHandshake;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user