TankSelector component added

This commit is contained in:
Milan Hanajik
2017-02-09 20:58:04 +01:00
parent 7ac1f2d431
commit 46cc618300
12 changed files with 655 additions and 6 deletions
@@ -12,7 +12,7 @@ namespace TBF.BenchControl.Modbus.QuidoRS
public class QuidoRS : ComponentBase, IDevice
{
private static readonly ILog log = LogManager.GetLogger(typeof(QuidoRS));
public override string ToString() { return string.Format("PressureMeter({0})", Cfg.ToString(1)); }
public override string ToString() { return string.Format("QuidoRS({0})", Cfg.ToString(1)); }
readonly QuidoRSCfg quidoRSCfg;
readonly GenericDevices.IModbus modbus;
@@ -32,7 +32,7 @@ namespace TBF.BenchControl.Modbus.QuidoRS
InitializeComponent();
}
private void PressureMeterCfgCtrl_Load(object sender, EventArgs e)
private void QuidoRSCfgCtrl_Load(object sender, EventArgs e)
{
parent = ParentForm as ComponentParametersDlg;
if (parent == null) return;
@@ -114,7 +114,7 @@ namespace TBF.BenchControl.Modbus.QuidoRS
this.Controls.Add(this.componentNameLabel);
this.Name = "ComponentCfgCtrl";
this.Size = new System.Drawing.Size(300, 200);
this.Load += new System.EventHandler(this.PressureMeterCfgCtrl_Load);
this.Load += new System.EventHandler(this.QuidoRSCfgCtrl_Load);
this.ResumeLayout(false);
this.PerformLayout();
@@ -0,0 +1,26 @@
///
/// Copyright (c) 2017 Sensus Metering Systems
///
using System.Collections.Generic;
using TBF.BenchControl.Generic;
namespace TBF.BenchControl.Modbus.QuidoRS.TankSelector
{
public class Factory : IComponentFactory
{
public string ClassName { get { return "TankSelector"; } }
public void ResetStaticProperties() { TankSelector.ResetStaticProperties(); }
public IComponent DummyComponent() { return new TankSelector(); }
public IComponent GetComponent(IComponentCfg cfg, IList<IComponent> components) { return new TankSelector(cfg, components); }
public IComponentCfg DefaultConfig() { return new TankSelectorCfg(this); }
public IComponentCfg CmpntCfgFromCmpntEntity(Config.Entities.Component component)
{
return ComponentCfgBase.CreateFromDbEntity(typeof(TankSelectorCfg), component, this);
}
}
}
@@ -0,0 +1,120 @@
///
/// Copyright (c) 2017 Sensus Metering Systems
///
using System;
using System.Collections.Generic;
using log4net;
using TBF.BenchControl.Generic;
using TBF.Boxes;
namespace TBF.BenchControl.Modbus.QuidoRS.TankSelector
{
public class TankSelector : ComponentBase, IOperation
{
private static readonly ILog log = LogManager.GetLogger(typeof(TankSelector));
public override string ToString() { return string.Format("TankSelector({0})", Cfg.ToString(1)); }
readonly TankSelectorCfg tankSelectorCfg;
readonly QuidoRS quidoRS;
public enum CurrentOp
{
None,
SelectTank,
}
CurrentOp currentOp;
public TankSelector()
{
}
public TankSelector(Generic.IComponentCfg cfg, IList<Generic.IComponent> components)
: base(cfg)
{
tankSelectorCfg = cfg as TankSelectorCfg;
quidoRS = (QuidoRS)TbfComponents.FindComponent(cfg.ParentName, components);
if (quidoRS == null) throw new Exception("Cannot find " + Name + " parent");
log.Debug(this.ToString());
}
/// <summary>
/// Set outputs of QuidoRS board
/// </summary>
/// <param name="outputs">output value</param>
public void SetOutputs(uint outputs)
{
quidoRS.SetOutputs((ushort)outputs);
}
/// <summary>
/// Events: SetOpututsDone, Error
/// </summary>
/// <param name="outValue">Reference to a variable for the pressure in Bar</param>
/// <returns>SetOutputsOp instance reference casted to IOperaton</returns>
//public IOperation SetOutputsOp(ushort outValue)
//{
// return new SetOutputsOp(this, outValue);
//}
/// <summary>
/// Events: pressureDone, Error
/// </summary>
/// <param name="outValue">Reference to a variable for the pressure in Bar</param>
/// <param name="setOutputsDone">Event returned when SetOutput is done</param>
/// <returns>SetOutputsOp instance reference casted to IOperaton</returns>
//public IOperation ReadPressureOp(ushort outValue, Event setOutputsDone)
//{
// return new SetOutputsOp(this, outValue, setOutputsDone);
//}
int tankNo;
///
public IOperation SelectTankOp(int tankNo)
{
if (currentOp != CurrentOp.None)
{
throw new Exception("Cannot start operation 'SelectTankOp'");
}
this.tankNo = tankNo;
currentOp = CurrentOp.SelectTank;
return this;
}
/// <summary>Start this operation</summary>
public void Start()
{
switch (currentOp)
{
case CurrentOp.SelectTank:
SetOutputs((tankNo==1) ? 1u : ((tankNo==2) ? 2u : ((tankNo==3) ? 3u : 0)));
break;
default:
break;
}
}
/// <summary>Run this operation</summary>
public Event Run()
{
switch (currentOp)
{
case CurrentOp.SelectTank:
return Event.Done;
default:
return Event.Done;
}
}
/// <summary>Stop this operation</summary>
public void Stop()
{
currentOp = CurrentOp.None;
}
}
}
@@ -0,0 +1,42 @@
///
/// Copyright (c) 2017 Sensus Metering Systems
///
using System;
using System.Collections.Generic;
using System.IO;
using System.Xml.Serialization;
using TBF.BenchControl.Generic;
namespace TBF.BenchControl.Modbus.QuidoRS.TankSelector
{
public class TankSelectorCfg : ComponentCfgBase, Generic.IChildComponentCfg
{
public IComponentCfgCtrl GetControl() { return new TankSelectorCfgCtrl(); }
///
/// Serialized parameters
///
public string ControlBoard;
/// Private parameterless constructor invoked by all other (public) constructors
TankSelectorCfg()
{
Name = "TankSelector";
ParentName = "QuidoRS";
}
public TankSelectorCfg(IComponentFactory factory)
: this()
{
this.Factory = factory;
}
public string ToString(int i)
{
return string.Format("Name={0}, Parent={1}, CtrlBrd={2}",
Name,
(string.IsNullOrEmpty(ParentName) ? "-" : ParentName),
(string.IsNullOrEmpty(ControlBoard) ? "-" : ControlBoard));
}
}
}
@@ -0,0 +1,127 @@
///
/// Copyright (c) 2017 Sensus Metering Systems
///
using System;
using System.Windows.Forms;
using log4net;
using TBF.BenchControl.Generic;
namespace TBF.BenchControl.Modbus.QuidoRS.TankSelector
{
public partial class TankSelectorCfgCtrl : UserControl, IComponentCfgCtrl
{
static readonly ILog log = LogManager.GetLogger(typeof(TankSelectorCfgCtrl));
ComponentParametersDlg parent;
public bool ShowMore { get { return false; } }
TankSelectorCfg config;
public IComponentCfg Config
{
get { return config as IComponentCfg; }
set
{
config = value as TankSelectorCfg;
Redraw();
}
}
public TankSelectorCfgCtrl()
{
InitializeComponent();
}
private void TankSelectorCfgCtrl_Load(object sender, EventArgs e)
{
parent = ParentForm as ComponentParametersDlg;
if (parent == null) return;
controlBoardComboBox.Items.Add("---");
if (parent.TbfComponents != null)
{
foreach (var cmpnt in parent.TbfComponents)
{
if (TbfComponents.CmpntFactoryFromClassName(cmpnt.ClassName) is Modbus.QuidoRS.Factory)
{
parentNameComboBox.Items.Add(cmpnt.Name);
}
if (TbfComponents.CmpntFactoryFromClassName(cmpnt.ClassName) is Elde.ControlBoardFactory)
{
controlBoardComboBox.Items.Add(cmpnt.Name);
}
}
}
Redraw();
}
public void Closing()
{
}
void Redraw()
{
if (config == null) return; /// Control was not loaded, settings were not changed
componentNameLabel.Text = config.Factory.ClassName;
nameTextBox.Text = config.Name;
parentNameComboBox.Text = string.IsNullOrEmpty(config.ParentName) ? "---" : config.ParentName;
controlBoardComboBox.Text = string.IsNullOrEmpty(config.ControlBoard) ? "---" : config.ControlBoard;
modbusAddressTextBox.Text = "1";
}
public void Unlock()
{
nameTextBox.Enabled = true;
parentNameComboBox.Enabled = true;
controlBoardComboBox.Enabled = true;
modbusAddressTextBox.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 (!controlBoardComboBox.Items.Contains(controlBoardComboBox.Text))
{
flags |= CfgUpdateFlags.Error;
message += Environment.NewLine + "Invalid 'Control board'";
}
if (!int.TryParse(modbusAddressTextBox.Text, out dummy) || dummy < 0 || dummy > 255)
{
flags |= CfgUpdateFlags.Error;
message += Environment.NewLine + "'Modbus Address' should be between 0 and 255";
}
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;
config.ParentName = parentNameComboBox.Text.Equals("---") ? string.Empty : parentNameComboBox.Text;
config.ControlBoard = controlBoardComboBox.Text.Equals("---") ? string.Empty : controlBoardComboBox.Text;
return flags;
}
private void modbusAddressLabel_Click(object sender, EventArgs e)
{
}
private void modbusAddressTextBox_TextChanged(object sender, EventArgs e)
{
}
}
}
@@ -0,0 +1,159 @@
///
/// Copyright (c) 2017 Sensus Metering Systems
///
namespace TBF.BenchControl.Modbus.QuidoRS.TankSelector
{
partial class TankSelectorCfgCtrl
{
/// <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.parentNameLabel = new System.Windows.Forms.Label();
this.nameTextBox = new System.Windows.Forms.TextBox();
this.nameLabel = new System.Windows.Forms.Label();
this.componentNameLabel = new System.Windows.Forms.Label();
this.modbusAddressLabel = new System.Windows.Forms.Label();
this.modbusAddressTextBox = new System.Windows.Forms.TextBox();
this.parentNameComboBox = new System.Windows.Forms.ComboBox();
this.controlBoardComboBox = new System.Windows.Forms.ComboBox();
this.controlBoardLabel = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// parentNameLabel
//
this.parentNameLabel.AutoSize = true;
this.parentNameLabel.Location = new System.Drawing.Point(28, 81);
this.parentNameLabel.Name = "parentNameLabel";
this.parentNameLabel.Size = new System.Drawing.Size(67, 13);
this.parentNameLabel.TabIndex = 3;
this.parentNameLabel.Text = "Parent name";
//
// nameTextBox
//
this.nameTextBox.Enabled = false;
this.nameTextBox.Location = new System.Drawing.Point(138, 52);
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(28, 55);
this.nameLabel.Name = "nameLabel";
this.nameLabel.Size = new System.Drawing.Size(35, 13);
this.nameLabel.TabIndex = 1;
this.nameLabel.Text = "Name";
//
// componentNameLabel
//
this.componentNameLabel.AutoSize = true;
this.componentNameLabel.Location = new System.Drawing.Point(135, 28);
this.componentNameLabel.Name = "componentNameLabel";
this.componentNameLabel.Size = new System.Drawing.Size(83, 13);
this.componentNameLabel.TabIndex = 0;
this.componentNameLabel.Text = "ComonentName";
//
// modbusAddressLabel
//
this.modbusAddressLabel.AutoSize = true;
this.modbusAddressLabel.Location = new System.Drawing.Point(28, 135);
this.modbusAddressLabel.Name = "modbusAddressLabel";
this.modbusAddressLabel.Size = new System.Drawing.Size(38, 13);
this.modbusAddressLabel.TabIndex = 7;
this.modbusAddressLabel.Text = "TODO";
this.modbusAddressLabel.Click += new System.EventHandler(this.modbusAddressLabel_Click);
//
// modbusAddressTextBox
//
this.modbusAddressTextBox.Enabled = false;
this.modbusAddressTextBox.Location = new System.Drawing.Point(138, 132);
this.modbusAddressTextBox.Name = "modbusAddressTextBox";
this.modbusAddressTextBox.Size = new System.Drawing.Size(46, 20);
this.modbusAddressTextBox.TabIndex = 8;
this.modbusAddressTextBox.TextChanged += new System.EventHandler(this.modbusAddressTextBox_TextChanged);
//
// parentNameComboBox
//
this.parentNameComboBox.Enabled = false;
this.parentNameComboBox.FormattingEnabled = true;
this.parentNameComboBox.Location = new System.Drawing.Point(138, 78);
this.parentNameComboBox.Name = "parentNameComboBox";
this.parentNameComboBox.Size = new System.Drawing.Size(130, 21);
this.parentNameComboBox.TabIndex = 4;
//
// controlBoardComboBox
//
this.controlBoardComboBox.Enabled = false;
this.controlBoardComboBox.FormattingEnabled = true;
this.controlBoardComboBox.Location = new System.Drawing.Point(138, 105);
this.controlBoardComboBox.Name = "controlBoardComboBox";
this.controlBoardComboBox.Size = new System.Drawing.Size(130, 21);
this.controlBoardComboBox.TabIndex = 6;
//
// controlBoardLabel
//
this.controlBoardLabel.AutoSize = true;
this.controlBoardLabel.Location = new System.Drawing.Point(28, 108);
this.controlBoardLabel.Name = "controlBoardLabel";
this.controlBoardLabel.Size = new System.Drawing.Size(70, 13);
this.controlBoardLabel.TabIndex = 5;
this.controlBoardLabel.Text = "Control board";
//
// TankSelectorCfgCtrl
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.controlBoardComboBox);
this.Controls.Add(this.controlBoardLabel);
this.Controls.Add(this.parentNameComboBox);
this.Controls.Add(this.modbusAddressTextBox);
this.Controls.Add(this.modbusAddressLabel);
this.Controls.Add(this.parentNameLabel);
this.Controls.Add(this.nameTextBox);
this.Controls.Add(this.nameLabel);
this.Controls.Add(this.componentNameLabel);
this.Name = "TankSelectorCfgCtrl";
this.Size = new System.Drawing.Size(300, 200);
this.Load += new System.EventHandler(this.TankSelectorCfgCtrl_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label parentNameLabel;
private System.Windows.Forms.TextBox nameTextBox;
private System.Windows.Forms.Label nameLabel;
private System.Windows.Forms.Label componentNameLabel;
private System.Windows.Forms.Label modbusAddressLabel;
private System.Windows.Forms.TextBox modbusAddressTextBox;
private System.Windows.Forms.ComboBox parentNameComboBox;
private System.Windows.Forms.ComboBox controlBoardComboBox;
private System.Windows.Forms.Label controlBoardLabel;
}
}
@@ -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>
@@ -93,6 +93,7 @@ namespace TBF.BenchControl
Factories.Add(new ResultsPrinters.Cevak.PrinterFactory());
Factories.Add(new ResultsPrinters.Munich.PrinterFactory());
Factories.Add(new DB.SensusOracle.DatabaseFactory());
Factories.Add(new Modbus.QuidoRS.TankSelector.Factory()); /// TankSelector
Factories.Add(new Elde.TempMeter.TempMeterFactory());
Factories.Add(new Elde.TempMeterInternal.TempMeterFactory());
Factories.Add(new Elde.Valve.ValveFactory());