Refactoring : TestBenchFramework --> TBF ver. 2.18.789
This commit is contained in:
@@ -0,0 +1,197 @@
|
||||
///
|
||||
/// Copyright (c) 2013-2018 Sensus Slovensko a.s.
|
||||
///
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using log4net;
|
||||
using Dirichlet.Numerics;
|
||||
using TBF.BenchControl.Generic;
|
||||
using TBF.Resources;
|
||||
|
||||
namespace TBF.BenchControl.Elde.Diverter
|
||||
{
|
||||
public class Diverter : ComponentBase, IDevice, GenericDevices.IDiverter, GenericDevices.ISequenceCondition
|
||||
{
|
||||
private static readonly ILog log = LogManager.GetLogger(typeof(Diverter));
|
||||
public override string ToString() { return string.Format("Diverter({0})", Cfg.ToString(1)); }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Enumeration of balances via static fields and methods
|
||||
/// </summary>
|
||||
static int nextIdx = 0;
|
||||
public static new void ResetStaticProperties()
|
||||
{
|
||||
nextIdx = 0;
|
||||
}
|
||||
public static int DivertersCount { get { return nextIdx; } }
|
||||
public static GenericDevices.IDiverter[] Diverters;
|
||||
public static int[] DivStartingLevelPct;
|
||||
public static int[] DivStoppingLevelPct;
|
||||
|
||||
protected int diverterNr; /// 0-based diverter number
|
||||
|
||||
|
||||
|
||||
readonly DiverterCfg diverterCfg;
|
||||
readonly ControlBoardDev controlBoard;
|
||||
readonly UInt128 mask; /// derived from bitPosition in the constructor
|
||||
public int AdcNr { get { return diverterCfg.AdcNr; } }
|
||||
|
||||
readonly IOperation diverterToTankOp;
|
||||
readonly IOperation diverterToSinkOp;
|
||||
|
||||
|
||||
public bool State
|
||||
{
|
||||
get { return (controlBoard.Route & mask) != 0; }
|
||||
}
|
||||
|
||||
public Diverter()
|
||||
{
|
||||
}
|
||||
|
||||
public Diverter(Generic.IComponentCfg cfg, IList<Generic.IComponent> components)
|
||||
: base(cfg)
|
||||
{
|
||||
diverterCfg = cfg as DiverterCfg;
|
||||
|
||||
controlBoard = (ControlBoardDev)TbfComponents.FindComponent(cfg.ParentName, components);
|
||||
if (controlBoard == null) throw new Exception("Cannot find " + Name + " parent");
|
||||
|
||||
if (diverterCfg.BitPosition < 0 || diverterCfg.BitPosition >= 64) throw new ArgumentOutOfRangeException("position");
|
||||
this.mask = (((UInt128)1) << diverterCfg.BitPosition);
|
||||
|
||||
|
||||
|
||||
diverterNr = nextIdx++;
|
||||
///
|
||||
if (Diverters == null || Diverters.Length < nextIdx)
|
||||
{
|
||||
GenericDevices.IDiverter[] divertersSoFar = Diverters;
|
||||
int[] startingLevelsSoFar = DivStartingLevelPct;
|
||||
int[] stoppingLevelsSoFar = DivStoppingLevelPct;
|
||||
|
||||
Diverters = new GenericDevices.IDiverter[nextIdx];
|
||||
DivStartingLevelPct = new int[nextIdx];
|
||||
DivStoppingLevelPct = new int[nextIdx];
|
||||
|
||||
if (divertersSoFar != null)
|
||||
{
|
||||
for (int i = 0; i < divertersSoFar.Length; i++)
|
||||
{
|
||||
Diverters[i] = divertersSoFar[i];
|
||||
DivStartingLevelPct[i] = startingLevelsSoFar[i];
|
||||
DivStoppingLevelPct[i] = stoppingLevelsSoFar[i];
|
||||
}
|
||||
}
|
||||
|
||||
Diverters[nextIdx - 1] = this;
|
||||
DivStartingLevelPct[nextIdx - 1] = diverterCfg.StartingLevel;
|
||||
DivStoppingLevelPct[nextIdx - 1] = diverterCfg.StoppingLevel;
|
||||
}
|
||||
|
||||
/// Prepare arguments of SendCalibData()
|
||||
if (diverterCfg.AdcNr >= 0 && diverterCfg.AdcNr < controlBoard.RegValveCalib.GetLength(0))
|
||||
{
|
||||
controlBoard.RegValveCalib[diverterCfg.AdcNr, 0] = (uint)diverterCfg.AdcValueToSink;
|
||||
controlBoard.RegValveCalib[diverterCfg.AdcNr, 1] = (uint)diverterCfg.AdcValueToTank;
|
||||
}
|
||||
else
|
||||
{
|
||||
log.ErrorFormat("Unable to set {0} ADC levels: RegValveCalib array size={1}, diverter AdcNr={2}",
|
||||
Name, controlBoard.RegValveCalib.GetLength(0), diverterCfg.AdcNr);
|
||||
}
|
||||
|
||||
diverterToTankOp = new SwitchDiverterOp(controlBoard, true, Name.Contains("1") ? 1 : 3);
|
||||
diverterToSinkOp = new SwitchDiverterOp(controlBoard, false, Name.Contains("1") ? 1 : 3);
|
||||
|
||||
log.Debug(this.ToString());
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// IDevice interface implementation
|
||||
///
|
||||
public void Initialize() { }
|
||||
public void RunDeviceBefore()
|
||||
{
|
||||
int adc = (int)StateMachine.ControlBoard.AnalogInputRaw(diverterCfg.AdcNr, 0);
|
||||
Handlers.OnAdcChanged(this, new CmdResponseArgs(CfgChangeCmd.GetAdc, diverterCfg.BitPosition, adc));
|
||||
}
|
||||
public void RunDeviceAfter() { }
|
||||
public void StopDevice() { }
|
||||
public void StopDevice2() { }
|
||||
|
||||
|
||||
///
|
||||
/// ISequenceCondition interface implementation
|
||||
///
|
||||
public int ConditionsCount { get { return 2; } }
|
||||
|
||||
/// Returned strings are added to the combo-box
|
||||
public string ConditionName(int i)
|
||||
{
|
||||
if (i == 0) return string.Format("{0} {1}", Name, Strings.Start);
|
||||
else return string.Format("{0} {1}", Name, Strings.End);
|
||||
}
|
||||
|
||||
public IOperation ConditionOp(int i)
|
||||
{
|
||||
if (i == 0) return diverterToTankOp;
|
||||
else return diverterToSinkOp;
|
||||
}
|
||||
|
||||
|
||||
#region Configuration Change Handling
|
||||
|
||||
public static void OnCfgChange(object sender, CfgChangeArgs args)
|
||||
{
|
||||
if (CfgChangeHandler == null) return;
|
||||
try { CfgChangeHandler(sender, args); }
|
||||
catch (Exception e) { log.Error("CfgChangeHandler(...) failed", e); }
|
||||
}
|
||||
|
||||
public static event EventHandler<CfgChangeArgs> CfgChangeHandler;
|
||||
|
||||
public override void StartChangeHandler()
|
||||
{
|
||||
CfgChangeHandler += delegate(object sender, CfgChangeArgs args)
|
||||
{
|
||||
DiverterCfg tmpcfg = args.Cfg as DiverterCfg;
|
||||
if (tmpcfg != null && tmpcfg.Name.Equals(Name))
|
||||
{
|
||||
#if GENESIS
|
||||
int flowMtrNr = int.Parse(Name.Substring(3)) + 1;
|
||||
#else
|
||||
int flowMtrNr = Name.Contains("1") ? 1 : 3;
|
||||
#endif
|
||||
|
||||
if (args.Command == CfgChangeCmd.CfgChange)
|
||||
{
|
||||
}
|
||||
else if (args.Command == CfgChangeCmd.GetAdc1 || args.Command == CfgChangeCmd.GetAdc2)
|
||||
{
|
||||
int adc = (int)controlBoard.AnalogInputRaw(diverterCfg.AdcNr, 0);
|
||||
// TOTEST
|
||||
DiverterCfgCtrl.OnCmdResponse(this, new CmdResponseArgs(args.Command, diverterCfg.BitPosition, adc));
|
||||
}
|
||||
else if (args.Command == CfgChangeCmd.DivToTank)
|
||||
{
|
||||
controlBoard.DiverterToTank(flowMtrNr);
|
||||
}
|
||||
else if (args.Command == CfgChangeCmd.DivToSink)
|
||||
{
|
||||
controlBoard.DiverterToSink(flowMtrNr);
|
||||
}
|
||||
else if (args.Command == CfgChangeCmd.ReadDivTransition)
|
||||
{
|
||||
controlBoard.ReadDiverterTransition(flowMtrNr);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endregion Configuration Change Handling
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
///
|
||||
/// Copyright (c) 2013-2016 Sensus Metering Systems
|
||||
///
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using System.Xml.Serialization;
|
||||
using TBF.BenchControl.Generic;
|
||||
|
||||
namespace TBF.BenchControl.Elde.Diverter
|
||||
{
|
||||
public class DiverterCfg : ComponentCfgBase, IChildComponentCfg
|
||||
{
|
||||
public static XmlSerializer Serializer = XmlSerializer.FromTypes(new[] { typeof(DiverterCfg) })[0];
|
||||
protected override XmlSerializer GetSerializer() { return Serializer; }
|
||||
|
||||
public IComponentCfgCtrl GetControl() { return new DiverterCfgCtrl(); }
|
||||
|
||||
///
|
||||
/// Serialized parameters
|
||||
///
|
||||
public int BitPosition; /// 0..63
|
||||
public int AdcNr; /// 0..15(?), number of the analog input
|
||||
public int AdcValueToSink; /// 0..1023
|
||||
public int AdcValueToTank; /// 0..1023
|
||||
public int StartingLevel; /// 0..100 in %, threshold for the ADC value to start the test
|
||||
public int StoppingLevel; /// 0..100 in %, threshold for the ADC value to start the test
|
||||
|
||||
/// Private parameterless constructor invoked by all other (public) constructors
|
||||
DiverterCfg()
|
||||
{
|
||||
Name = "Div";
|
||||
ParentName = "CB";
|
||||
BitPosition = 0;
|
||||
AdcNr = 5; /// Div1: AdcNr=5 , Div2: AdcNr=6
|
||||
AdcValueToSink = 100;
|
||||
AdcValueToTank = 500;
|
||||
StartingLevel = 50;
|
||||
StoppingLevel = 50;
|
||||
}
|
||||
|
||||
public DiverterCfg(IComponentFactory factory)
|
||||
: this()
|
||||
{
|
||||
this.Factory = factory;
|
||||
}
|
||||
|
||||
public string ToString(int i)
|
||||
{
|
||||
return string.Format("Name={0}, Parent={1}, Bit={2}, ADC#={3}, ADC2Sink={4}, ADC2Tank={5}, StartingLevel={6}%, StoppingLevel={7}%",
|
||||
Name,
|
||||
(string.IsNullOrEmpty(ParentName) ? "-" : ParentName),
|
||||
BitPosition,
|
||||
AdcNr,
|
||||
AdcValueToSink,
|
||||
AdcValueToTank,
|
||||
StartingLevel,
|
||||
StoppingLevel);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,518 @@
|
||||
///
|
||||
/// Copyright (c) 2013-2015 Sensus Metering Systems
|
||||
///
|
||||
namespace TBF.BenchControl.Elde.Diverter
|
||||
{
|
||||
partial class DiverterCfgCtrl
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Component Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.nameTextBox = new System.Windows.Forms.TextBox();
|
||||
this.nameLabel = new System.Windows.Forms.Label();
|
||||
this.classNameLabel = new System.Windows.Forms.Label();
|
||||
this.parentNameLabel = new System.Windows.Forms.Label();
|
||||
this.bitPositionLabel = new System.Windows.Forms.Label();
|
||||
this.bitPositionTextBox = new System.Windows.Forms.TextBox();
|
||||
this.parentNameComboBox = new System.Windows.Forms.ComboBox();
|
||||
this.startingEdgeTextBox = new System.Windows.Forms.TextBox();
|
||||
this.startingEdgeLabel = new System.Windows.Forms.Label();
|
||||
this.stoppingEdgeTextBox = new System.Windows.Forms.TextBox();
|
||||
this.stoppingEdgeLabel = new System.Windows.Forms.Label();
|
||||
this.label2 = new System.Windows.Forms.Label();
|
||||
this.label1 = new System.Windows.Forms.Label();
|
||||
this.startButton = new System.Windows.Forms.Button();
|
||||
this.stopButton = new System.Windows.Forms.Button();
|
||||
this.updateButton = new System.Windows.Forms.Button();
|
||||
this.adcToTankTextBox = new System.Windows.Forms.TextBox();
|
||||
this.adcTankLabel = new System.Windows.Forms.Label();
|
||||
this.adcToSinkTextBox = new System.Windows.Forms.TextBox();
|
||||
this.adcSinkLabel = new System.Windows.Forms.Label();
|
||||
this.groupBox4 = new System.Windows.Forms.GroupBox();
|
||||
this.label4 = new System.Windows.Forms.Label();
|
||||
this.adcTextBox = new System.Windows.Forms.TextBox();
|
||||
this.groupBox2 = new System.Windows.Forms.GroupBox();
|
||||
this.setButton2 = new System.Windows.Forms.Button();
|
||||
this.label3 = new System.Windows.Forms.Label();
|
||||
this.label5 = new System.Windows.Forms.Label();
|
||||
this.getButton2 = new System.Windows.Forms.Button();
|
||||
this.pctTextBox2 = new System.Windows.Forms.TextBox();
|
||||
this.adcTextBox2 = new System.Windows.Forms.TextBox();
|
||||
this.groupBox1 = new System.Windows.Forms.GroupBox();
|
||||
this.setButton1 = new System.Windows.Forms.Button();
|
||||
this.label6 = new System.Windows.Forms.Label();
|
||||
this.ADC = new System.Windows.Forms.Label();
|
||||
this.getButton1 = new System.Windows.Forms.Button();
|
||||
this.pctTextBox1 = new System.Windows.Forms.TextBox();
|
||||
this.adcTextBox1 = new System.Windows.Forms.TextBox();
|
||||
this.adcNrTextBox = new System.Windows.Forms.TextBox();
|
||||
this.label7 = new System.Windows.Forms.Label();
|
||||
this.groupBox4.SuspendLayout();
|
||||
this.groupBox2.SuspendLayout();
|
||||
this.groupBox1.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// nameTextBox
|
||||
//
|
||||
this.nameTextBox.Enabled = false;
|
||||
this.nameTextBox.Location = new System.Drawing.Point(137, 41);
|
||||
this.nameTextBox.Name = "nameTextBox";
|
||||
this.nameTextBox.Size = new System.Drawing.Size(130, 20);
|
||||
this.nameTextBox.TabIndex = 2;
|
||||
//
|
||||
// nameLabel
|
||||
//
|
||||
this.nameLabel.AutoSize = true;
|
||||
this.nameLabel.Location = new System.Drawing.Point(27, 44);
|
||||
this.nameLabel.Name = "nameLabel";
|
||||
this.nameLabel.Size = new System.Drawing.Size(35, 13);
|
||||
this.nameLabel.TabIndex = 1;
|
||||
this.nameLabel.Text = "Name";
|
||||
//
|
||||
// classNameLabel
|
||||
//
|
||||
this.classNameLabel.AutoSize = true;
|
||||
this.classNameLabel.Location = new System.Drawing.Point(134, 17);
|
||||
this.classNameLabel.Name = "classNameLabel";
|
||||
this.classNameLabel.Size = new System.Drawing.Size(83, 13);
|
||||
this.classNameLabel.TabIndex = 0;
|
||||
this.classNameLabel.Text = "ComonentName";
|
||||
//
|
||||
// parentNameLabel
|
||||
//
|
||||
this.parentNameLabel.AutoSize = true;
|
||||
this.parentNameLabel.Location = new System.Drawing.Point(27, 67);
|
||||
this.parentNameLabel.Name = "parentNameLabel";
|
||||
this.parentNameLabel.Size = new System.Drawing.Size(69, 13);
|
||||
this.parentNameLabel.TabIndex = 3;
|
||||
this.parentNameLabel.Text = "Parent Name";
|
||||
//
|
||||
// bitPositionLabel
|
||||
//
|
||||
this.bitPositionLabel.AutoSize = true;
|
||||
this.bitPositionLabel.Location = new System.Drawing.Point(27, 91);
|
||||
this.bitPositionLabel.Name = "bitPositionLabel";
|
||||
this.bitPositionLabel.Size = new System.Drawing.Size(59, 13);
|
||||
this.bitPositionLabel.TabIndex = 5;
|
||||
this.bitPositionLabel.Text = "Bit Position";
|
||||
//
|
||||
// bitPositionTextBox
|
||||
//
|
||||
this.bitPositionTextBox.Enabled = false;
|
||||
this.bitPositionTextBox.Location = new System.Drawing.Point(137, 88);
|
||||
this.bitPositionTextBox.Name = "bitPositionTextBox";
|
||||
this.bitPositionTextBox.Size = new System.Drawing.Size(46, 20);
|
||||
this.bitPositionTextBox.TabIndex = 6;
|
||||
//
|
||||
// parentNameComboBox
|
||||
//
|
||||
this.parentNameComboBox.Enabled = false;
|
||||
this.parentNameComboBox.FormattingEnabled = true;
|
||||
this.parentNameComboBox.Location = new System.Drawing.Point(137, 64);
|
||||
this.parentNameComboBox.Name = "parentNameComboBox";
|
||||
this.parentNameComboBox.Size = new System.Drawing.Size(130, 21);
|
||||
this.parentNameComboBox.TabIndex = 4;
|
||||
//
|
||||
// startingEdgeTextBox
|
||||
//
|
||||
this.startingEdgeTextBox.Enabled = false;
|
||||
this.startingEdgeTextBox.Location = new System.Drawing.Point(137, 180);
|
||||
this.startingEdgeTextBox.Name = "startingEdgeTextBox";
|
||||
this.startingEdgeTextBox.Size = new System.Drawing.Size(46, 20);
|
||||
this.startingEdgeTextBox.TabIndex = 14;
|
||||
//
|
||||
// startingEdgeLabel
|
||||
//
|
||||
this.startingEdgeLabel.AutoSize = true;
|
||||
this.startingEdgeLabel.Location = new System.Drawing.Point(27, 183);
|
||||
this.startingEdgeLabel.Name = "startingEdgeLabel";
|
||||
this.startingEdgeLabel.Size = new System.Drawing.Size(68, 13);
|
||||
this.startingEdgeLabel.TabIndex = 13;
|
||||
this.startingEdgeLabel.Text = "Starting level";
|
||||
//
|
||||
// stoppingEdgeTextBox
|
||||
//
|
||||
this.stoppingEdgeTextBox.Enabled = false;
|
||||
this.stoppingEdgeTextBox.Location = new System.Drawing.Point(137, 203);
|
||||
this.stoppingEdgeTextBox.Name = "stoppingEdgeTextBox";
|
||||
this.stoppingEdgeTextBox.Size = new System.Drawing.Size(46, 20);
|
||||
this.stoppingEdgeTextBox.TabIndex = 17;
|
||||
//
|
||||
// stoppingEdgeLabel
|
||||
//
|
||||
this.stoppingEdgeLabel.AutoSize = true;
|
||||
this.stoppingEdgeLabel.Location = new System.Drawing.Point(27, 206);
|
||||
this.stoppingEdgeLabel.Name = "stoppingEdgeLabel";
|
||||
this.stoppingEdgeLabel.Size = new System.Drawing.Size(74, 13);
|
||||
this.stoppingEdgeLabel.TabIndex = 16;
|
||||
this.stoppingEdgeLabel.Text = "Stopping level";
|
||||
//
|
||||
// label2
|
||||
//
|
||||
this.label2.AutoSize = true;
|
||||
this.label2.Location = new System.Drawing.Point(190, 205);
|
||||
this.label2.Name = "label2";
|
||||
this.label2.Size = new System.Drawing.Size(15, 13);
|
||||
this.label2.TabIndex = 18;
|
||||
this.label2.Text = "%";
|
||||
//
|
||||
// label1
|
||||
//
|
||||
this.label1.AutoSize = true;
|
||||
this.label1.Location = new System.Drawing.Point(190, 183);
|
||||
this.label1.Name = "label1";
|
||||
this.label1.Size = new System.Drawing.Size(15, 13);
|
||||
this.label1.TabIndex = 15;
|
||||
this.label1.Text = "%";
|
||||
//
|
||||
// startButton
|
||||
//
|
||||
this.startButton.Location = new System.Drawing.Point(10, 557);
|
||||
this.startButton.Name = "startButton";
|
||||
this.startButton.Size = new System.Drawing.Size(55, 31);
|
||||
this.startButton.TabIndex = 22;
|
||||
this.startButton.Text = "Start";
|
||||
this.startButton.UseVisualStyleBackColor = true;
|
||||
this.startButton.Click += new System.EventHandler(this.startButton_Click);
|
||||
//
|
||||
// stopButton
|
||||
//
|
||||
this.stopButton.Location = new System.Drawing.Point(71, 557);
|
||||
this.stopButton.Name = "stopButton";
|
||||
this.stopButton.Size = new System.Drawing.Size(55, 31);
|
||||
this.stopButton.TabIndex = 23;
|
||||
this.stopButton.Text = "Stop";
|
||||
this.stopButton.UseVisualStyleBackColor = true;
|
||||
this.stopButton.Click += new System.EventHandler(this.stopButton_Click);
|
||||
//
|
||||
// updateButton
|
||||
//
|
||||
this.updateButton.Enabled = false;
|
||||
this.updateButton.Location = new System.Drawing.Point(206, 557);
|
||||
this.updateButton.Name = "updateButton";
|
||||
this.updateButton.Size = new System.Drawing.Size(85, 31);
|
||||
this.updateButton.TabIndex = 26;
|
||||
this.updateButton.Text = "Update Edge";
|
||||
this.updateButton.UseVisualStyleBackColor = true;
|
||||
this.updateButton.Click += new System.EventHandler(this.updateButton_Click);
|
||||
//
|
||||
// adcToTankTextBox
|
||||
//
|
||||
this.adcToTankTextBox.Enabled = false;
|
||||
this.adcToTankTextBox.Location = new System.Drawing.Point(137, 157);
|
||||
this.adcToTankTextBox.Name = "adcToTankTextBox";
|
||||
this.adcToTankTextBox.Size = new System.Drawing.Size(46, 20);
|
||||
this.adcToTankTextBox.TabIndex = 12;
|
||||
//
|
||||
// adcTankLabel
|
||||
//
|
||||
this.adcTankLabel.AutoSize = true;
|
||||
this.adcTankLabel.Location = new System.Drawing.Point(27, 160);
|
||||
this.adcTankLabel.Name = "adcTankLabel";
|
||||
this.adcTankLabel.Size = new System.Drawing.Size(94, 13);
|
||||
this.adcTankLabel.TabIndex = 11;
|
||||
this.adcTankLabel.Text = "ADC when to tank";
|
||||
//
|
||||
// adcToSinkTextBox
|
||||
//
|
||||
this.adcToSinkTextBox.Enabled = false;
|
||||
this.adcToSinkTextBox.Location = new System.Drawing.Point(137, 134);
|
||||
this.adcToSinkTextBox.Name = "adcToSinkTextBox";
|
||||
this.adcToSinkTextBox.Size = new System.Drawing.Size(46, 20);
|
||||
this.adcToSinkTextBox.TabIndex = 10;
|
||||
//
|
||||
// adcSinkLabel
|
||||
//
|
||||
this.adcSinkLabel.AutoSize = true;
|
||||
this.adcSinkLabel.Location = new System.Drawing.Point(27, 137);
|
||||
this.adcSinkLabel.Name = "adcSinkLabel";
|
||||
this.adcSinkLabel.Size = new System.Drawing.Size(92, 13);
|
||||
this.adcSinkLabel.TabIndex = 9;
|
||||
this.adcSinkLabel.Text = "ADC when to sink";
|
||||
//
|
||||
// groupBox4
|
||||
//
|
||||
this.groupBox4.Controls.Add(this.label4);
|
||||
this.groupBox4.Controls.Add(this.adcTextBox);
|
||||
this.groupBox4.Location = new System.Drawing.Point(10, 352);
|
||||
this.groupBox4.Name = "groupBox4";
|
||||
this.groupBox4.Size = new System.Drawing.Size(279, 40);
|
||||
this.groupBox4.TabIndex = 19;
|
||||
this.groupBox4.TabStop = false;
|
||||
//
|
||||
// label4
|
||||
//
|
||||
this.label4.AutoSize = true;
|
||||
this.label4.Location = new System.Drawing.Point(11, 17);
|
||||
this.label4.Name = "label4";
|
||||
this.label4.Size = new System.Drawing.Size(32, 13);
|
||||
this.label4.TabIndex = 22;
|
||||
this.label4.Text = "ADC:";
|
||||
//
|
||||
// adcTextBox
|
||||
//
|
||||
this.adcTextBox.Location = new System.Drawing.Point(47, 14);
|
||||
this.adcTextBox.Name = "adcTextBox";
|
||||
this.adcTextBox.Size = new System.Drawing.Size(44, 20);
|
||||
this.adcTextBox.TabIndex = 21;
|
||||
//
|
||||
// groupBox2
|
||||
//
|
||||
this.groupBox2.Controls.Add(this.setButton2);
|
||||
this.groupBox2.Controls.Add(this.label3);
|
||||
this.groupBox2.Controls.Add(this.label5);
|
||||
this.groupBox2.Controls.Add(this.getButton2);
|
||||
this.groupBox2.Controls.Add(this.pctTextBox2);
|
||||
this.groupBox2.Controls.Add(this.adcTextBox2);
|
||||
this.groupBox2.Location = new System.Drawing.Point(10, 462);
|
||||
this.groupBox2.Name = "groupBox2";
|
||||
this.groupBox2.Size = new System.Drawing.Size(280, 59);
|
||||
this.groupBox2.TabIndex = 21;
|
||||
this.groupBox2.TabStop = false;
|
||||
this.groupBox2.Text = "Measured value 2";
|
||||
//
|
||||
// setButton2
|
||||
//
|
||||
this.setButton2.Location = new System.Drawing.Point(229, 17);
|
||||
this.setButton2.Name = "setButton2";
|
||||
this.setButton2.Size = new System.Drawing.Size(38, 33);
|
||||
this.setButton2.TabIndex = 5;
|
||||
this.setButton2.Text = "Set";
|
||||
this.setButton2.UseVisualStyleBackColor = true;
|
||||
this.setButton2.Click += new System.EventHandler(this.setButton_Click);
|
||||
//
|
||||
// label3
|
||||
//
|
||||
this.label3.AutoSize = true;
|
||||
this.label3.Location = new System.Drawing.Point(209, 28);
|
||||
this.label3.Name = "label3";
|
||||
this.label3.Size = new System.Drawing.Size(15, 13);
|
||||
this.label3.TabIndex = 4;
|
||||
this.label3.Text = "%";
|
||||
//
|
||||
// label5
|
||||
//
|
||||
this.label5.AutoSize = true;
|
||||
this.label5.Location = new System.Drawing.Point(11, 27);
|
||||
this.label5.Name = "label5";
|
||||
this.label5.Size = new System.Drawing.Size(32, 13);
|
||||
this.label5.TabIndex = 3;
|
||||
this.label5.Text = "ADC:";
|
||||
//
|
||||
// getButton2
|
||||
//
|
||||
this.getButton2.Location = new System.Drawing.Point(101, 18);
|
||||
this.getButton2.Name = "getButton2";
|
||||
this.getButton2.Size = new System.Drawing.Size(38, 33);
|
||||
this.getButton2.TabIndex = 2;
|
||||
this.getButton2.Text = "Get";
|
||||
this.getButton2.UseVisualStyleBackColor = true;
|
||||
this.getButton2.Click += new System.EventHandler(this.getButton2_Click);
|
||||
//
|
||||
// pctTextBox2
|
||||
//
|
||||
this.pctTextBox2.Location = new System.Drawing.Point(160, 24);
|
||||
this.pctTextBox2.Name = "pctTextBox2";
|
||||
this.pctTextBox2.Size = new System.Drawing.Size(46, 20);
|
||||
this.pctTextBox2.TabIndex = 1;
|
||||
//
|
||||
// adcTextBox2
|
||||
//
|
||||
this.adcTextBox2.Location = new System.Drawing.Point(47, 24);
|
||||
this.adcTextBox2.Name = "adcTextBox2";
|
||||
this.adcTextBox2.Size = new System.Drawing.Size(44, 20);
|
||||
this.adcTextBox2.TabIndex = 0;
|
||||
//
|
||||
// groupBox1
|
||||
//
|
||||
this.groupBox1.Controls.Add(this.setButton1);
|
||||
this.groupBox1.Controls.Add(this.label6);
|
||||
this.groupBox1.Controls.Add(this.ADC);
|
||||
this.groupBox1.Controls.Add(this.getButton1);
|
||||
this.groupBox1.Controls.Add(this.pctTextBox1);
|
||||
this.groupBox1.Controls.Add(this.adcTextBox1);
|
||||
this.groupBox1.Location = new System.Drawing.Point(10, 398);
|
||||
this.groupBox1.Name = "groupBox1";
|
||||
this.groupBox1.Size = new System.Drawing.Size(280, 59);
|
||||
this.groupBox1.TabIndex = 20;
|
||||
this.groupBox1.TabStop = false;
|
||||
this.groupBox1.Text = "Measured value 1";
|
||||
//
|
||||
// setButton1
|
||||
//
|
||||
this.setButton1.Location = new System.Drawing.Point(229, 17);
|
||||
this.setButton1.Name = "setButton1";
|
||||
this.setButton1.Size = new System.Drawing.Size(38, 33);
|
||||
this.setButton1.TabIndex = 5;
|
||||
this.setButton1.Text = "Set";
|
||||
this.setButton1.UseVisualStyleBackColor = true;
|
||||
this.setButton1.Click += new System.EventHandler(this.setButton_Click);
|
||||
//
|
||||
// label6
|
||||
//
|
||||
this.label6.AutoSize = true;
|
||||
this.label6.Location = new System.Drawing.Point(209, 28);
|
||||
this.label6.Name = "label6";
|
||||
this.label6.Size = new System.Drawing.Size(15, 13);
|
||||
this.label6.TabIndex = 4;
|
||||
this.label6.Text = "%";
|
||||
//
|
||||
// ADC
|
||||
//
|
||||
this.ADC.AutoSize = true;
|
||||
this.ADC.Location = new System.Drawing.Point(11, 28);
|
||||
this.ADC.Name = "ADC";
|
||||
this.ADC.Size = new System.Drawing.Size(32, 13);
|
||||
this.ADC.TabIndex = 3;
|
||||
this.ADC.Text = "ADC:";
|
||||
//
|
||||
// getButton1
|
||||
//
|
||||
this.getButton1.Location = new System.Drawing.Point(101, 18);
|
||||
this.getButton1.Name = "getButton1";
|
||||
this.getButton1.Size = new System.Drawing.Size(38, 33);
|
||||
this.getButton1.TabIndex = 2;
|
||||
this.getButton1.Text = "Get";
|
||||
this.getButton1.UseVisualStyleBackColor = true;
|
||||
this.getButton1.Click += new System.EventHandler(this.getButton1_Click);
|
||||
//
|
||||
// pctTextBox1
|
||||
//
|
||||
this.pctTextBox1.Location = new System.Drawing.Point(160, 24);
|
||||
this.pctTextBox1.Name = "pctTextBox1";
|
||||
this.pctTextBox1.Size = new System.Drawing.Size(46, 20);
|
||||
this.pctTextBox1.TabIndex = 1;
|
||||
//
|
||||
// adcTextBox1
|
||||
//
|
||||
this.adcTextBox1.Location = new System.Drawing.Point(47, 24);
|
||||
this.adcTextBox1.Name = "adcTextBox1";
|
||||
this.adcTextBox1.Size = new System.Drawing.Size(44, 20);
|
||||
this.adcTextBox1.TabIndex = 0;
|
||||
//
|
||||
// adcNrTextBox
|
||||
//
|
||||
this.adcNrTextBox.Enabled = false;
|
||||
this.adcNrTextBox.Location = new System.Drawing.Point(137, 111);
|
||||
this.adcNrTextBox.Name = "adcNrTextBox";
|
||||
this.adcNrTextBox.Size = new System.Drawing.Size(46, 20);
|
||||
this.adcNrTextBox.TabIndex = 8;
|
||||
//
|
||||
// label7
|
||||
//
|
||||
this.label7.AutoSize = true;
|
||||
this.label7.Location = new System.Drawing.Point(27, 114);
|
||||
this.label7.Name = "label7";
|
||||
this.label7.Size = new System.Drawing.Size(76, 13);
|
||||
this.label7.TabIndex = 7;
|
||||
this.label7.Text = "Analog input #";
|
||||
//
|
||||
// DiverterCfgCtrl
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.Controls.Add(this.adcNrTextBox);
|
||||
this.Controls.Add(this.label7);
|
||||
this.Controls.Add(this.groupBox4);
|
||||
this.Controls.Add(this.groupBox2);
|
||||
this.Controls.Add(this.groupBox1);
|
||||
this.Controls.Add(this.adcToTankTextBox);
|
||||
this.Controls.Add(this.adcTankLabel);
|
||||
this.Controls.Add(this.adcToSinkTextBox);
|
||||
this.Controls.Add(this.adcSinkLabel);
|
||||
this.Controls.Add(this.updateButton);
|
||||
this.Controls.Add(this.stopButton);
|
||||
this.Controls.Add(this.startButton);
|
||||
this.Controls.Add(this.label1);
|
||||
this.Controls.Add(this.label2);
|
||||
this.Controls.Add(this.stoppingEdgeTextBox);
|
||||
this.Controls.Add(this.stoppingEdgeLabel);
|
||||
this.Controls.Add(this.startingEdgeTextBox);
|
||||
this.Controls.Add(this.startingEdgeLabel);
|
||||
this.Controls.Add(this.parentNameComboBox);
|
||||
this.Controls.Add(this.bitPositionTextBox);
|
||||
this.Controls.Add(this.bitPositionLabel);
|
||||
this.Controls.Add(this.parentNameLabel);
|
||||
this.Controls.Add(this.nameTextBox);
|
||||
this.Controls.Add(this.nameLabel);
|
||||
this.Controls.Add(this.classNameLabel);
|
||||
this.Name = "DiverterCfgCtrl";
|
||||
this.Size = new System.Drawing.Size(300, 700);
|
||||
this.Load += new System.EventHandler(this.DiverterCfgCtrl_Load);
|
||||
this.groupBox4.ResumeLayout(false);
|
||||
this.groupBox4.PerformLayout();
|
||||
this.groupBox2.ResumeLayout(false);
|
||||
this.groupBox2.PerformLayout();
|
||||
this.groupBox1.ResumeLayout(false);
|
||||
this.groupBox1.PerformLayout();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.TextBox nameTextBox;
|
||||
private System.Windows.Forms.Label nameLabel;
|
||||
private System.Windows.Forms.Label classNameLabel;
|
||||
private System.Windows.Forms.Label parentNameLabel;
|
||||
private System.Windows.Forms.Label bitPositionLabel;
|
||||
private System.Windows.Forms.TextBox bitPositionTextBox;
|
||||
private System.Windows.Forms.ComboBox parentNameComboBox;
|
||||
private System.Windows.Forms.TextBox startingEdgeTextBox;
|
||||
private System.Windows.Forms.Label startingEdgeLabel;
|
||||
private System.Windows.Forms.TextBox stoppingEdgeTextBox;
|
||||
private System.Windows.Forms.Label stoppingEdgeLabel;
|
||||
private System.Windows.Forms.Label label2;
|
||||
private System.Windows.Forms.Label label1;
|
||||
private System.Windows.Forms.Button startButton;
|
||||
private System.Windows.Forms.Button stopButton;
|
||||
private System.Windows.Forms.Button updateButton;
|
||||
private System.Windows.Forms.TextBox adcToTankTextBox;
|
||||
private System.Windows.Forms.Label adcTankLabel;
|
||||
private System.Windows.Forms.TextBox adcToSinkTextBox;
|
||||
private System.Windows.Forms.Label adcSinkLabel;
|
||||
private System.Windows.Forms.GroupBox groupBox4;
|
||||
private System.Windows.Forms.Label label4;
|
||||
private System.Windows.Forms.TextBox adcTextBox;
|
||||
private System.Windows.Forms.GroupBox groupBox2;
|
||||
private System.Windows.Forms.Button setButton2;
|
||||
private System.Windows.Forms.Label label3;
|
||||
private System.Windows.Forms.Label label5;
|
||||
private System.Windows.Forms.Button getButton2;
|
||||
private System.Windows.Forms.TextBox pctTextBox2;
|
||||
private System.Windows.Forms.TextBox adcTextBox2;
|
||||
private System.Windows.Forms.GroupBox groupBox1;
|
||||
private System.Windows.Forms.Button setButton1;
|
||||
private System.Windows.Forms.Label label6;
|
||||
private System.Windows.Forms.Label ADC;
|
||||
private System.Windows.Forms.Button getButton1;
|
||||
private System.Windows.Forms.TextBox pctTextBox1;
|
||||
private System.Windows.Forms.TextBox adcTextBox1;
|
||||
private System.Windows.Forms.TextBox adcNrTextBox;
|
||||
private System.Windows.Forms.Label label7;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,325 @@
|
||||
///
|
||||
/// Copyright (c) 2013-2015 Sensus Metering Systems
|
||||
///
|
||||
using System;
|
||||
using System.Windows.Forms;
|
||||
using log4net;
|
||||
using TBF.BenchControl.Generic;
|
||||
|
||||
namespace TBF.BenchControl.Elde.Diverter
|
||||
{
|
||||
public partial class DiverterCfgCtrl : UserControl, IComponentCfgCtrl
|
||||
{
|
||||
static readonly ILog log = LogManager.GetLogger(typeof(DiverterCfgCtrl));
|
||||
|
||||
ComponentParametersDlg parent;
|
||||
|
||||
public bool ShowMore { get { return true; } }
|
||||
|
||||
DiverterCfg config;
|
||||
public IComponentCfg Config
|
||||
{
|
||||
get { return config as IComponentCfg; }
|
||||
set
|
||||
{
|
||||
config = value as DiverterCfg;
|
||||
Redraw();
|
||||
}
|
||||
}
|
||||
|
||||
public DiverterCfgCtrl()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void DiverterCfgCtrl_Load(object sender, EventArgs e)
|
||||
{
|
||||
parent = ParentForm as ComponentParametersDlg;
|
||||
if (parent == null) return;
|
||||
|
||||
if (parent.TbfComponents != null)
|
||||
{
|
||||
foreach (var cmpnt in parent.TbfComponents)
|
||||
{
|
||||
if (TbfComponents.CmpntFactoryFromClassName(cmpnt.ClassName) is Elde.ControlBoardFactory)
|
||||
{
|
||||
parentNameComboBox.Items.Add(cmpnt.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (config != null)
|
||||
{
|
||||
adc1 = config.AdcValueToSink;
|
||||
pct1 = 0;
|
||||
adc2 = config.AdcValueToTank;
|
||||
pct2 = 100;
|
||||
}
|
||||
|
||||
Redraw();
|
||||
StartResponseHandler();
|
||||
}
|
||||
|
||||
public void Closing()
|
||||
{
|
||||
StopResponseHandler();
|
||||
}
|
||||
|
||||
void Redraw()
|
||||
{
|
||||
if (config == null) return; /// Control was not loaded, settings were not changed
|
||||
|
||||
classNameLabel.Text = config.Factory.ClassName;
|
||||
parentNameComboBox.Text = string.IsNullOrEmpty(config.ParentName) ? "---" : config.ParentName;
|
||||
nameTextBox.Text = config.Name;
|
||||
bitPositionTextBox.Text = config.BitPosition.ToString();
|
||||
adcNrTextBox.Text = config.AdcNr.ToString();
|
||||
adcToSinkTextBox.Text = config.AdcValueToSink.ToString();
|
||||
adcToTankTextBox.Text = config.AdcValueToTank.ToString();
|
||||
startingEdgeTextBox.Text = config.StartingLevel.ToString();
|
||||
stoppingEdgeTextBox.Text = config.StoppingLevel.ToString();
|
||||
|
||||
adcTextBox1.Text = adc1.ToString();
|
||||
adcTextBox2.Text = adc2.ToString();
|
||||
pctTextBox1.Text = pct1.ToString();
|
||||
pctTextBox2.Text = pct2.ToString();
|
||||
}
|
||||
|
||||
public void Unlock()
|
||||
{
|
||||
nameTextBox.Enabled = true;
|
||||
parentNameComboBox.Enabled = true;
|
||||
bitPositionTextBox.Enabled = true;
|
||||
adcNrTextBox.Enabled = true;
|
||||
adcToSinkTextBox.Enabled = true;
|
||||
adcToTankTextBox.Enabled = true;
|
||||
startingEdgeTextBox.Enabled = true;
|
||||
stoppingEdgeTextBox.Enabled = true;
|
||||
}
|
||||
|
||||
public CfgUpdateFlags VerifyCfg(ref string message)
|
||||
{
|
||||
CfgUpdateFlags flags = CfgUpdateFlags.None;
|
||||
|
||||
int dummy;
|
||||
if (!parentNameComboBox.Items.Contains(parentNameComboBox.Text))
|
||||
{
|
||||
flags |= CfgUpdateFlags.Error;
|
||||
message += Environment.NewLine + "Invalid 'Parent Name'";
|
||||
}
|
||||
|
||||
if (!int.TryParse(bitPositionTextBox.Text, out dummy) || dummy < 0 || dummy > 127)
|
||||
{
|
||||
flags |= CfgUpdateFlags.Error;
|
||||
message += Environment.NewLine + "'Bit Position' should be between 0 and 127";
|
||||
}
|
||||
|
||||
if (!int.TryParse(adcNrTextBox.Text, out dummy) || dummy < 0 || dummy > 15)
|
||||
{
|
||||
flags |= CfgUpdateFlags.Error;
|
||||
message += Environment.NewLine + "'Analog input #' should be between 0 and 15";
|
||||
}
|
||||
|
||||
if (!int.TryParse(adcToSinkTextBox.Text, out dummy) || dummy < 0 || dummy > 1023)
|
||||
{
|
||||
flags |= CfgUpdateFlags.Error;
|
||||
message += Environment.NewLine + "'ADC when to sink' should be between 0 and 1023";
|
||||
}
|
||||
|
||||
if (!int.TryParse(adcToTankTextBox.Text, out dummy) || dummy < 0 || dummy > 1023)
|
||||
{
|
||||
flags |= CfgUpdateFlags.Error;
|
||||
message += Environment.NewLine + "'ADC when to tank' should be between 0 and 1023";
|
||||
}
|
||||
|
||||
if (!int.TryParse(startingEdgeTextBox.Text, out dummy) || dummy < 0 || dummy > 100)
|
||||
{
|
||||
flags |= CfgUpdateFlags.Error;
|
||||
message += Environment.NewLine + "'Starting Edge' should be between 0 and 100%";
|
||||
}
|
||||
if (!int.TryParse(stoppingEdgeTextBox.Text, out dummy) || dummy < 0 || dummy > 100)
|
||||
{
|
||||
flags |= CfgUpdateFlags.Error;
|
||||
message += Environment.NewLine + "'Stopping Edge' should be between 0 and 100%";
|
||||
}
|
||||
return flags;
|
||||
}
|
||||
|
||||
public CfgUpdateFlags UpdateCfg()
|
||||
{
|
||||
CfgUpdateFlags flags = CfgUpdateFlags.None;
|
||||
// CfgUpdateFlags flags = CfgUpdateFlags.RestartRqrd;
|
||||
|
||||
if (config == null) return CfgUpdateFlags.Error; /// Control was not loaded, settings were not changed
|
||||
|
||||
if (!config.Name.Equals(nameTextBox.Text))
|
||||
{
|
||||
config.Name = nameTextBox.Text;
|
||||
flags |= CfgUpdateFlags.RestartRqrd;
|
||||
}
|
||||
|
||||
string parentname = parentNameComboBox.Text.Equals("---") ? string.Empty : parentNameComboBox.Text;
|
||||
if (!config.ParentName.Equals(parentname))
|
||||
{
|
||||
config.ParentName = parentname;
|
||||
flags |= CfgUpdateFlags.RestartRqrd;
|
||||
}
|
||||
|
||||
int tmp = int.Parse(bitPositionTextBox.Text);
|
||||
if (config.BitPosition != tmp)
|
||||
{
|
||||
config.BitPosition = tmp;
|
||||
flags |= CfgUpdateFlags.RestartRqrd;
|
||||
}
|
||||
|
||||
tmp = int.Parse(adcNrTextBox.Text);
|
||||
if (config.AdcNr != tmp)
|
||||
{
|
||||
config.AdcNr = tmp;
|
||||
flags |= CfgUpdateFlags.RestartRqrd;
|
||||
}
|
||||
|
||||
tmp = int.Parse(adcToSinkTextBox.Text);
|
||||
if (config.AdcValueToSink != tmp)
|
||||
{
|
||||
config.AdcValueToSink = tmp;
|
||||
flags |= CfgUpdateFlags.RestartRqrd;
|
||||
}
|
||||
|
||||
tmp = int.Parse(adcToTankTextBox.Text);
|
||||
if (config.AdcValueToTank != tmp)
|
||||
{
|
||||
config.AdcValueToTank = tmp;
|
||||
flags |= CfgUpdateFlags.RestartRqrd;
|
||||
}
|
||||
|
||||
tmp = int.Parse(startingEdgeTextBox.Text);
|
||||
if (config.StartingLevel != tmp)
|
||||
{
|
||||
config.StartingLevel = tmp;
|
||||
flags |= CfgUpdateFlags.RestartRqrd;
|
||||
}
|
||||
|
||||
tmp = int.Parse(stoppingEdgeTextBox.Text);
|
||||
if (config.StoppingLevel != tmp)
|
||||
{
|
||||
config.StoppingLevel = tmp;
|
||||
flags |= CfgUpdateFlags.RestartRqrd;
|
||||
}
|
||||
|
||||
return flags;
|
||||
}
|
||||
|
||||
int adc1;
|
||||
int pct1;
|
||||
|
||||
int adc2;
|
||||
int pct2;
|
||||
|
||||
|
||||
private void getButton1_Click(object sender, EventArgs e)
|
||||
{
|
||||
Diverter.OnCfgChange(this, new CfgChangeArgs(CfgChangeCmd.GetAdc1, config));
|
||||
}
|
||||
|
||||
private void getButton2_Click(object sender, EventArgs e)
|
||||
{
|
||||
Diverter.OnCfgChange(this, new CfgChangeArgs(CfgChangeCmd.GetAdc2, config));
|
||||
}
|
||||
|
||||
private void setButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
int tmpPct1;
|
||||
int tmpPct2;
|
||||
if ((int.TryParse(pctTextBox1.Text, out tmpPct1) && (tmpPct1 >= 0) && (tmpPct1 <= 100)) &&
|
||||
(int.TryParse(pctTextBox2.Text, out tmpPct2) && (tmpPct2 >= 0) && (tmpPct2 <= 100)))
|
||||
{
|
||||
pct1 = tmpPct1;
|
||||
pct2 = tmpPct2;
|
||||
UpdateDivAdc();
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateDivAdc()
|
||||
{
|
||||
if ((adc1 == adc2) || (pct1 == pct2)) return;
|
||||
|
||||
double factor = (float)(adc2 - adc1) / (float)(pct2 - pct1);
|
||||
int adcToSink = (int)((float)(0 - pct1) * factor + (float)adc1 + 0.5f);
|
||||
int adcToTank = (int)((float)(100 - pct1) * factor + (float)adc1 + 0.5f);
|
||||
|
||||
if ((adcToSink >= 0) && (adcToTank >= 0))
|
||||
{
|
||||
adcToSinkTextBox.Text = adcToSink.ToString();
|
||||
adcToTankTextBox.Text = adcToTank.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void startButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
Diverter.OnCfgChange(this, new CfgChangeArgs(CfgChangeCmd.DivToTank, config));
|
||||
}
|
||||
|
||||
private void stopButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
Diverter.OnCfgChange(this, new CfgChangeArgs(CfgChangeCmd.DivToSink, config));
|
||||
|
||||
}
|
||||
|
||||
private void updateButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
Diverter.OnCfgChange(this, new CfgChangeArgs(CfgChangeCmd.ReadDivTransition, config));
|
||||
}
|
||||
|
||||
|
||||
#region Configuration Change Handling
|
||||
|
||||
public static void OnCmdResponse(object sender, CmdResponseArgs args)
|
||||
{
|
||||
if (CmdResponseHandler == null) return;
|
||||
try { CmdResponseHandler(sender, args); }
|
||||
catch (Exception e) { log.Error("CmdResponseHandler(...) failed", e); }
|
||||
}
|
||||
|
||||
public static event EventHandler<CmdResponseArgs> CmdResponseHandler;
|
||||
|
||||
public void StartResponseHandler()
|
||||
{
|
||||
Handlers.AdcChangedHandler += delegate(object sndr, CmdResponseArgs args)
|
||||
{
|
||||
if (InvokeRequired) { Invoke(new EventHandler<CmdResponseArgs>(OnAdcChanged), sndr, args); }
|
||||
else OnAdcChanged(sndr, args);
|
||||
};
|
||||
|
||||
CmdResponseHandler += delegate(object sender, CmdResponseArgs args)
|
||||
{
|
||||
if (args.Command == CfgChangeCmd.GetAdc1)
|
||||
{
|
||||
adc1 = args.Response;
|
||||
adcTextBox1.Text = adc1.ToString();
|
||||
}
|
||||
else if (args.Command == CfgChangeCmd.GetAdc2)
|
||||
{
|
||||
adc2 = args.Response;
|
||||
adcTextBox2.Text = adc2.ToString();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public void StopResponseHandler()
|
||||
{
|
||||
CmdResponseHandler = null;
|
||||
}
|
||||
|
||||
void OnAdcChanged(object sender, CmdResponseArgs data)
|
||||
{
|
||||
if (data.Command == CfgChangeCmd.GetAdc && data.Id == config.BitPosition)
|
||||
{
|
||||
adcTextBox.Text = data.Response.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Configuration Change Handling
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
||||
@@ -0,0 +1,26 @@
|
||||
///
|
||||
/// Copyright (c) 2013-2016 Sensus Metering Systems
|
||||
///
|
||||
using System.Collections.Generic;
|
||||
using TBF.BenchControl.Generic;
|
||||
|
||||
namespace TBF.BenchControl.Elde.Diverter
|
||||
{
|
||||
public class DiverterFactory : IComponentFactory
|
||||
{
|
||||
public string ClassName { get { return "Diverter"; } }
|
||||
|
||||
public void ResetStaticProperties() { Diverter.ResetStaticProperties(); }
|
||||
|
||||
public IComponent DummyComponent() { return new Diverter(); }
|
||||
|
||||
public IComponent GetComponent(IComponentCfg cfg, IList<IComponent> components) { return new Diverter(cfg, components); }
|
||||
|
||||
public IComponentCfg DefaultConfig() { return new DiverterCfg(this); }
|
||||
|
||||
public IComponentCfg CmpntCfgFromCmpntEntity(Config.Entities.Component component)
|
||||
{
|
||||
return ComponentCfgBase.CreateFromDbEntity(DiverterCfg.Serializer, component, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
///
|
||||
/// Copyright (c) 2013-2015 Sensus Metering Systems
|
||||
///
|
||||
using System;
|
||||
using log4net;
|
||||
|
||||
namespace TBF.BenchControl.Elde.Diverter
|
||||
{
|
||||
static class Handlers
|
||||
{
|
||||
static readonly ILog log = LogManager.GetLogger(typeof(Handlers));
|
||||
|
||||
static Handlers()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called from the state machine when a procedure is selected and UI needs to be updated.
|
||||
/// </summary>
|
||||
public static void OnAdcChanged(object sender, CmdResponseArgs data)
|
||||
{
|
||||
if (AdcChangedHandler == null)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
AdcChangedHandler(sender, data);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.Error("AdcChangedHandler(...) failed", e);
|
||||
}
|
||||
}
|
||||
public static event EventHandler<CmdResponseArgs> AdcChangedHandler;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
///
|
||||
/// Copyright (c) 2017 Sensus Metering Systems
|
||||
///
|
||||
using System;
|
||||
|
||||
namespace TBF.BenchControl.Elde.Diverter
|
||||
{
|
||||
public class SwitchDiverterOp : IOperation
|
||||
{
|
||||
ControlBoardDev controlBoard;
|
||||
bool start;
|
||||
int flowMtrNr;
|
||||
|
||||
public SwitchDiverterOp(ControlBoardDev controlBoard, bool start, int flowMtrNr)
|
||||
{
|
||||
this.controlBoard = controlBoard;
|
||||
this.start = start;
|
||||
this.flowMtrNr = flowMtrNr;
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
if (start)
|
||||
{
|
||||
controlBoard.DiverterToTank(flowMtrNr);
|
||||
}
|
||||
else
|
||||
{
|
||||
controlBoard.DiverterToSink(flowMtrNr);
|
||||
}
|
||||
}
|
||||
|
||||
public Event Run()
|
||||
{
|
||||
return Event.ConditionMet;
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user