diff --git a/TestBenchFramework/BenchControl/Modbus/PressureMeter/Meret/Factory.cs b/TestBenchFramework/BenchControl/Modbus/PressureMeter/Meret/Factory.cs new file mode 100644 index 000000000..ed51286b3 --- /dev/null +++ b/TestBenchFramework/BenchControl/Modbus/PressureMeter/Meret/Factory.cs @@ -0,0 +1,26 @@ +/// +/// Copyright (c) 2016 Sensus Metering Systems +/// +using System.Collections.Generic; +using TBF.BenchControl.Generic; + +namespace TBF.BenchControl.Modbus.PressureMeter.Meret +{ + public class Factory : IComponentFactory + { + public string ClassName { get { return this.GetType().Namespace.Substring(17); } } + + public void ResetStaticProperties() { PressureMeter.ResetStaticProperties(); } + + public IComponent DummyComponent() { return new PressureMeter(); } + + public IComponent GetComponent(IComponentCfg cfg, IList components) { return new PressureMeter(cfg, components); } + + public IComponentCfg DefaultConfig() { return new PressureMeterCfg(this); } + + public IComponentCfg CmpntCfgFromCmpntEntity(Config.Entities.Component component) + { + return ComponentCfgBase.CreateFromDbEntity(typeof(PressureMeterCfg), component, this); + } + } +} diff --git a/TestBenchFramework/BenchControl/Modbus/PressureMeter/Meret/PressureMeter.cs b/TestBenchFramework/BenchControl/Modbus/PressureMeter/Meret/PressureMeter.cs new file mode 100644 index 000000000..773e6085e --- /dev/null +++ b/TestBenchFramework/BenchControl/Modbus/PressureMeter/Meret/PressureMeter.cs @@ -0,0 +1,96 @@ +/// +/// Copyright (c) 2016 Sensus Metering Systems +/// +using System; +using System.Collections.Generic; +using log4net; +using TBF.BenchControl.Generic; +using TBF.Boxes; + +namespace TBF.BenchControl.Modbus.PressureMeter.Meret +{ + public class PressureMeter : ComponentBase, GenericDevices.IPressureMeter, IDevice + { + private static readonly ILog log = LogManager.GetLogger(typeof(PressureMeter)); + public override string ToString() { return string.Format("PressureMeter({0})", Cfg.ToString(1)); } + + readonly PressureMeterCfg pressureMeterCfg; + readonly GenericDevices.IModbus modbus; + + private ushort currentOutputs; + + const ushort WatchdogBitMask = 0x0010; + + public PressureMeter() + { + } + + public PressureMeter(Generic.IComponentCfg cfg, IList components) + : base(cfg) + { + pressureMeterCfg = cfg as PressureMeterCfg; + + modbus = (GenericDevices.IModbus)TbfComponents.FindComponent(cfg.ParentName, components); + if (modbus == null) throw new Exception("Cannot find " + Name + " parent"); + + /// Connect to handler + //ModbusAddress.MeretRS485Address[Idx0] = ModbusAddress; + + log.Debug(this.ToString()); + } + + /// Initialize this device + public void Initialize() + { + } + + + /// + /// Returns the water pressure + /// + /// Pressure in mBar + public float ReadPressure() + { + return (float)Config.Units.ConvertFrom(Config.Unit.kPa, 1.0F); + } + + /// + /// Events: PressureDone, Error + /// + /// Reference to a variable for the pressure in Bar + /// ReadPressureOp instance reference casted to IOperaton + public IOperation ReadPressureOp(ref FloatBox pressure) + { + return new ReadPressureOp(this, ref pressure); + } + + /// + /// Events: pressureDone, Error + /// + /// Reference to a variable for the pressure in Bar + /// Event returned when measurement done + /// ReadPressureOp instance reference casted to IOperaton + public IOperation ReadPressureOp(ref FloatBox pressure, Event pressureDone) + { + return new ReadPressureOp(this, ref pressure, pressureDone); + } + + + /// Run this device + public void RunDeviceBefore() + { + } + + /// Run this device + public void RunDeviceAfter() + { + currentOutputs = (UInt16)((Int32)currentOutputs ^ (Int32)WatchdogBitMask); + //SendOutputs(currentOutputs); + } + + /// Stop this device + public void StopDevice() + { + } + } +} diff --git a/TestBenchFramework/BenchControl/Modbus/PressureMeter/Meret/PressureMeterCfg.cs b/TestBenchFramework/BenchControl/Modbus/PressureMeter/Meret/PressureMeterCfg.cs new file mode 100644 index 000000000..e6d2a921c --- /dev/null +++ b/TestBenchFramework/BenchControl/Modbus/PressureMeter/Meret/PressureMeterCfg.cs @@ -0,0 +1,43 @@ +/// +/// Copyright (c) 2016 Sensus Metering Systems +/// +using System; +using System.Collections.Generic; +using System.IO; +using System.Xml.Serialization; +using TBF.BenchControl.Generic; + +namespace TBF.BenchControl.Modbus.PressureMeter.Meret +{ + public class PressureMeterCfg : ComponentCfgBase, Generic.IChildComponentCfg + { + public IComponentCfgCtrl GetControl() { return new PressureMeterCfgCtrl(); } + + /// + /// Serialized parameters + /// + public byte ModbusAddress; /// 1..255 + + /// Private parameterless constructor invoked by all other (public) constructors + PressureMeterCfg() + { + Name = "Pr"; + ParentName = "Modbus"; + ModbusAddress = 49; + } + + public PressureMeterCfg(IComponentFactory factory) + : this() + { + this.Factory = factory; + } + + public string ToString(int i) + { + return string.Format("Name={0}, ModbusAddr={1}, Parent={2}", + Name, + ModbusAddress, + (string.IsNullOrEmpty(ParentName) ? "-" : ParentName)); + } + } +} diff --git a/TestBenchFramework/BenchControl/Modbus/PressureMeter/Meret/PressureMeterCfgCtrl.cs b/TestBenchFramework/BenchControl/Modbus/PressureMeter/Meret/PressureMeterCfgCtrl.cs new file mode 100644 index 000000000..bb627a337 --- /dev/null +++ b/TestBenchFramework/BenchControl/Modbus/PressureMeter/Meret/PressureMeterCfgCtrl.cs @@ -0,0 +1,106 @@ +/// +/// Copyright (c) 2016 Sensus Metering Systems +/// +using System; +using System.Windows.Forms; +using log4net; +using TBF.BenchControl.Generic; + +namespace TBF.BenchControl.Modbus.PressureMeter.Meret +{ + public partial class PressureMeterCfgCtrl : UserControl, IComponentCfgCtrl + { + static readonly ILog log = LogManager.GetLogger(typeof(PressureMeterCfgCtrl)); + + ComponentParametersDlg parent; + + public bool ShowMore { get { return false; } } + + PressureMeterCfg config; + public IComponentCfg Config + { + get { return config as IComponentCfg; } + set + { + config = value as PressureMeterCfg; + Redraw(); + } + } + + public PressureMeterCfgCtrl() + { + InitializeComponent(); + } + + private void PressureMeterCfgCtrl_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 Modbus.Common.Factory) + { + parentNameComboBox.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; + modbusAddressTextBox.Text = config.ModbusAddress.ToString(); + } + + public void Unlock() + { + nameTextBox.Enabled = true; + parentNameComboBox.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 (!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.ModbusAddress = (byte)int.Parse(modbusAddressTextBox.Text); + + return flags; + } + } +} diff --git a/TestBenchFramework/BenchControl/Modbus/PressureMeter/Meret/PressureMeterCfgCtrl.designer.cs b/TestBenchFramework/BenchControl/Modbus/PressureMeter/Meret/PressureMeterCfgCtrl.designer.cs new file mode 100644 index 000000000..8f443a7da --- /dev/null +++ b/TestBenchFramework/BenchControl/Modbus/PressureMeter/Meret/PressureMeterCfgCtrl.designer.cs @@ -0,0 +1,133 @@ +/// +/// Copyright (c) 2016 Sensus Metering Systems +/// +namespace TBF.BenchControl.Modbus.PressureMeter.Meret +{ + partial class PressureMeterCfgCtrl + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + 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.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(69, 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, 133); + this.modbusAddressLabel.Name = "modbusAddressLabel"; + this.modbusAddressLabel.Size = new System.Drawing.Size(86, 13); + this.modbusAddressLabel.TabIndex = 7; + this.modbusAddressLabel.Text = "Modbus Address"; + // + // modbusAddressTextBox + // + this.modbusAddressTextBox.Enabled = false; + this.modbusAddressTextBox.Location = new System.Drawing.Point(138, 130); + this.modbusAddressTextBox.Name = "modbusAddressTextBox"; + this.modbusAddressTextBox.Size = new System.Drawing.Size(46, 20); + this.modbusAddressTextBox.TabIndex = 8; + // + // 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; + // + // ComponentCfgCtrl + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + 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 = "ComponentCfgCtrl"; + this.Size = new System.Drawing.Size(300, 200); + this.Load += new System.EventHandler(this.PressureMeterCfgCtrl_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; + } +} diff --git a/TestBenchFramework/BenchControl/Modbus/PressureMeter/Meret/PressureMeterCfgCtrl.resx b/TestBenchFramework/BenchControl/Modbus/PressureMeter/Meret/PressureMeterCfgCtrl.resx new file mode 100644 index 000000000..1af7de150 --- /dev/null +++ b/TestBenchFramework/BenchControl/Modbus/PressureMeter/Meret/PressureMeterCfgCtrl.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/TestBenchFramework/BenchControl/Modbus/PressureMeter/Meret/ReadPressureOp.cs b/TestBenchFramework/BenchControl/Modbus/PressureMeter/Meret/ReadPressureOp.cs new file mode 100644 index 000000000..986bbc425 --- /dev/null +++ b/TestBenchFramework/BenchControl/Modbus/PressureMeter/Meret/ReadPressureOp.cs @@ -0,0 +1,64 @@ +/// +/// Copyright (c) 2016 Sensus Metering Systems +/// +using System; +using log4net; +using TBF.Boxes; + +namespace TBF.BenchControl.Modbus.PressureMeter.Meret +{ + public class ReadPressureOp : IOperation + { + private static readonly ILog log = LogManager.GetLogger(typeof(ReadPressureOp)); + public override string ToString() { return string.Format("ReadPressureOp(.,{0},.)", eventDone); } + + /// Set by the constructor + readonly PressureMeter pressureMeter; + readonly Event eventDone; + + /// Measured value + FloatBox pressure; + + /// + /// Events: PressureInDone, PressureOutDone or Error + /// + /// Pressure meter reference + /// Reference to the measured pressure variable, value is in bar + /// Event to be returned by Run() when completed OK + public ReadPressureOp(PressureMeter pressureMeter, ref FloatBox pressure, Event eventDone) + { + if (pressureMeter == null) throw new ArgumentNullException("pressureMeter"); + this.pressureMeter = pressureMeter; + this.pressure = pressure; + this.eventDone = eventDone; + + log.Debug(this.ToString()); + } + public ReadPressureOp(PressureMeter pressureMeter, ref FloatBox pressure) + : this(pressureMeter, ref pressure, Event.PressureDone) + { + } + + + /// Start this operation + public void Start() + { + pressure.Val = pressureMeter.ReadPressure(); + } + + /// Run this operation + /// + /// Event.PressureInDone or Event.PressureOutDone + /// + public Event Run() + { + pressure.Val = pressureMeter.ReadPressure(); + return eventDone; + } + + /// Stop this operation + public void Stop() + { + } + } +} diff --git a/TestBenchFramework/BenchControl/TbfComponents.cs b/TestBenchFramework/BenchControl/TbfComponents.cs index 03b1d1e50..eea87224a 100644 --- a/TestBenchFramework/BenchControl/TbfComponents.cs +++ b/TestBenchFramework/BenchControl/TbfComponents.cs @@ -63,6 +63,7 @@ namespace TBF.BenchControl Factories.Add(new MettlerToledo.Standard.BalanceNewFactory()); /// MettlerToledoBalanceSN Factories.Add(new MettlerToledo.Multi.BalanceFactory()); /// MettlerToledo-Multi Factories.Add(new Modbus.Common.Factory()); /// Modbus + Factories.Add(new Modbus.PressureMeter.Meret.Factory()); /// Meret pressure meter connected via modbus Factories.Add(new Output.FileWriters.Basic.FactorySingle()); /// Output.FileWriters.Basic.Single Factories.Add(new Output.FileWriters.Basic.FactoryCompound()); /// Output.FileWriters.Basic.Compound Factories.Add(new Output.FileWriters.Enhanced.FactorySingle()); /// Output.FileWriters.Basic.Single diff --git a/TestBenchFramework/Properties/AssemblyInfo.cs b/TestBenchFramework/Properties/AssemblyInfo.cs index 68860f492..5210ac8be 100644 --- a/TestBenchFramework/Properties/AssemblyInfo.cs +++ b/TestBenchFramework/Properties/AssemblyInfo.cs @@ -29,5 +29,5 @@ using System.Runtime.InteropServices; // Build Number // Revision // -[assembly: AssemblyVersion("2.10.356.1")] -[assembly: AssemblyFileVersion("2.10.356.1")] +[assembly: AssemblyVersion("2.10.357.1")] +[assembly: AssemblyFileVersion("2.10.357.1")] diff --git a/TestBenchFramework/TBF.csproj b/TestBenchFramework/TBF.csproj index bd1113b34..6219bc872 100644 --- a/TestBenchFramework/TBF.csproj +++ b/TestBenchFramework/TBF.csproj @@ -437,6 +437,16 @@ ModbusCfgCtrl.cs + + + + + UserControl + + + PressureMeterCfgCtrl.cs + + @@ -1702,6 +1712,9 @@ ModbusCfgCtrl.cs + + PressureMeterCfgCtrl.cs + QuidoRSCfgCtrl.cs