diff --git a/TestBenchFramework/BenchControl/MettlerToledo/Multi/BalanceCfg.cs b/TestBenchFramework/BenchControl/MettlerToledo/Multi/BalanceCfg.cs new file mode 100644 index 000000000..747ab917a --- /dev/null +++ b/TestBenchFramework/BenchControl/MettlerToledo/Multi/BalanceCfg.cs @@ -0,0 +1,65 @@ +/// +/// Copyright (c) 2013-2015 Sensus Metering Systems +/// +using System.IO; +using System.Collections.Generic; +using System.IO.Ports; +using System.Xml.Serialization; +using TBF.BenchControl.Generic; + +namespace TBF.BenchControl.MettlerToledo.Multi +{ + public class BalanceCfg : ComponentCfgBase, Generic.IComponentCfg + { + public IComponent GetComponent(IList components) { return new BalanceDev(this); } + public IComponentCfgCtrl GetControl() { return new BalanceCfgCtrl(); } + + /// + /// Serialized parameters + /// + public int IdNr; /// Identification number 1..3 + public float Capacity; /// Max. water mass in 'kg' or volume in 'l' + public float Empty; /// 'Empty' water mass in 'kg' or volume in 'l' + public string Format; + public int EmptyTimeSec; /// s + + public int ComPortNr; + public int BaudRate; + public Parity Parity; + public int DataBits; + public StopBits StopBits; + public Handshake Handshake; + + /// Private parameterless constructor invoked by all other (public) constructors + BalanceCfg() + { + Name = "Balance"; + ParentName = string.Empty; + + IdNr = 1; + Capacity = 200.0f; + Empty = 20.0f; + Format = "F3"; + EmptyTimeSec = 180; + + ComPortNr = 3; + BaudRate = 2400; + Parity = System.IO.Ports.Parity.Even; + DataBits = 7; + StopBits = System.IO.Ports.StopBits.One; + Handshake = System.IO.Ports.Handshake.XOnXOff; + } + + public BalanceCfg(IComponentFactory factory) + : this() + { + this.Factory = factory; + } + + public string ToString(int i) + { + return string.Format("Name={0}, Id#={1}, {2}kg, empty={3}kg, fmt.={4}, emptyTm={5}s, Com{6}, {7}Bd, {8}-bits, parity={9}, stopBits={10}, {11}", + Name, IdNr, Capacity, Empty, Format, EmptyTimeSec, ComPortNr, BaudRate, DataBits, Parity, StopBits, Handshake); + } + } +} diff --git a/TestBenchFramework/BenchControl/MettlerToledo/Multi/BalanceCfgCtrl.Designer.cs b/TestBenchFramework/BenchControl/MettlerToledo/Multi/BalanceCfgCtrl.Designer.cs new file mode 100644 index 000000000..1073e17cc --- /dev/null +++ b/TestBenchFramework/BenchControl/MettlerToledo/Multi/BalanceCfgCtrl.Designer.cs @@ -0,0 +1,379 @@ +/// +/// Copyright (c) 2013-2015 Sensus Metering Systems +/// +namespace TBF.BenchControl.MettlerToledo.Multi +{ + partial class BalanceCfgCtrl + { + /// + /// 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.handshakeComboBox = new System.Windows.Forms.ComboBox(); + this.stopBitsComboBox = new System.Windows.Forms.ComboBox(); + this.parityComboBox = new System.Windows.Forms.ComboBox(); + this.nameTextBox = new System.Windows.Forms.TextBox(); + this.nameLabel = new System.Windows.Forms.Label(); + this.classNameLabel = new System.Windows.Forms.Label(); + this.handshakeLabel = new System.Windows.Forms.Label(); + this.stopBitsLabel = new System.Windows.Forms.Label(); + this.dataBitsTextBox = new System.Windows.Forms.TextBox(); + this.dataBitsLabel = new System.Windows.Forms.Label(); + this.partityLabel = new System.Windows.Forms.Label(); + this.baudRateTextBox = new System.Windows.Forms.TextBox(); + this.baudRateLabel = new System.Windows.Forms.Label(); + this.comPortNrTextBox = new System.Windows.Forms.TextBox(); + this.label1 = new System.Windows.Forms.Label(); + this.capacityLabel = new System.Windows.Forms.Label(); + this.capacityTextBox = new System.Windows.Forms.TextBox(); + this.label2 = new System.Windows.Forms.Label(); + this.label3 = new System.Windows.Forms.Label(); + this.emptyTextBox = new System.Windows.Forms.TextBox(); + this.emptyLabel = new System.Windows.Forms.Label(); + this.label4 = new System.Windows.Forms.Label(); + this.emptyTimeTextBox = new System.Windows.Forms.TextBox(); + this.label5 = new System.Windows.Forms.Label(); + this.formatTextBox = new System.Windows.Forms.TextBox(); + this.formatLabel = new System.Windows.Forms.Label(); + this.idNrTextBox = new System.Windows.Forms.TextBox(); + this.idNrLabel = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // handshakeComboBox + // + this.handshakeComboBox.Enabled = false; + this.handshakeComboBox.FormattingEnabled = true; + this.handshakeComboBox.Location = new System.Drawing.Point(236, 216); + this.handshakeComboBox.Name = "handshakeComboBox"; + this.handshakeComboBox.Size = new System.Drawing.Size(43, 21); + this.handshakeComboBox.TabIndex = 27; + // + // stopBitsComboBox + // + this.stopBitsComboBox.Enabled = false; + this.stopBitsComboBox.FormattingEnabled = true; + this.stopBitsComboBox.Location = new System.Drawing.Point(236, 193); + this.stopBitsComboBox.Name = "stopBitsComboBox"; + this.stopBitsComboBox.Size = new System.Drawing.Size(43, 21); + this.stopBitsComboBox.TabIndex = 25; + // + // parityComboBox + // + this.parityComboBox.Enabled = false; + this.parityComboBox.FormattingEnabled = true; + this.parityComboBox.Location = new System.Drawing.Point(100, 216); + this.parityComboBox.Name = "parityComboBox"; + this.parityComboBox.Size = new System.Drawing.Size(43, 21); + this.parityComboBox.TabIndex = 21; + // + // nameTextBox + // + this.nameTextBox.Enabled = false; + this.nameTextBox.Location = new System.Drawing.Point(136, 27); + this.nameTextBox.Name = "nameTextBox"; + this.nameTextBox.Size = new System.Drawing.Size(143, 20); + this.nameTextBox.TabIndex = 2; + // + // nameLabel + // + this.nameLabel.AutoSize = true; + this.nameLabel.Location = new System.Drawing.Point(26, 30); + 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(133, 7); + this.classNameLabel.Name = "classNameLabel"; + this.classNameLabel.Size = new System.Drawing.Size(89, 13); + this.classNameLabel.TabIndex = 0; + this.classNameLabel.Text = "ComponentName"; + // + // handshakeLabel + // + this.handshakeLabel.AutoSize = true; + this.handshakeLabel.Location = new System.Drawing.Point(162, 219); + this.handshakeLabel.Name = "handshakeLabel"; + this.handshakeLabel.Size = new System.Drawing.Size(62, 13); + this.handshakeLabel.TabIndex = 26; + this.handshakeLabel.Text = "Handshake"; + // + // stopBitsLabel + // + this.stopBitsLabel.AutoSize = true; + this.stopBitsLabel.Location = new System.Drawing.Point(162, 196); + this.stopBitsLabel.Name = "stopBitsLabel"; + this.stopBitsLabel.Size = new System.Drawing.Size(49, 13); + this.stopBitsLabel.TabIndex = 24; + this.stopBitsLabel.Text = "Stop Bits"; + // + // dataBitsTextBox + // + this.dataBitsTextBox.Enabled = false; + this.dataBitsTextBox.Location = new System.Drawing.Point(236, 170); + this.dataBitsTextBox.Name = "dataBitsTextBox"; + this.dataBitsTextBox.Size = new System.Drawing.Size(43, 20); + this.dataBitsTextBox.TabIndex = 23; + // + // dataBitsLabel + // + this.dataBitsLabel.AutoSize = true; + this.dataBitsLabel.Location = new System.Drawing.Point(162, 173); + this.dataBitsLabel.Name = "dataBitsLabel"; + this.dataBitsLabel.Size = new System.Drawing.Size(50, 13); + this.dataBitsLabel.TabIndex = 22; + this.dataBitsLabel.Text = "Data Bits"; + // + // partityLabel + // + this.partityLabel.AutoSize = true; + this.partityLabel.Location = new System.Drawing.Point(26, 221); + this.partityLabel.Name = "partityLabel"; + this.partityLabel.Size = new System.Drawing.Size(33, 13); + this.partityLabel.TabIndex = 20; + this.partityLabel.Text = "Parity"; + // + // baudRateTextBox + // + this.baudRateTextBox.Enabled = false; + this.baudRateTextBox.Location = new System.Drawing.Point(100, 193); + this.baudRateTextBox.Name = "baudRateTextBox"; + this.baudRateTextBox.Size = new System.Drawing.Size(43, 20); + this.baudRateTextBox.TabIndex = 19; + // + // baudRateLabel + // + this.baudRateLabel.AutoSize = true; + this.baudRateLabel.Location = new System.Drawing.Point(26, 196); + this.baudRateLabel.Name = "baudRateLabel"; + this.baudRateLabel.Size = new System.Drawing.Size(58, 13); + this.baudRateLabel.TabIndex = 18; + this.baudRateLabel.Text = "Baud Rate"; + // + // comPortNrTextBox + // + this.comPortNrTextBox.Enabled = false; + this.comPortNrTextBox.Location = new System.Drawing.Point(100, 170); + this.comPortNrTextBox.Name = "comPortNrTextBox"; + this.comPortNrTextBox.Size = new System.Drawing.Size(43, 20); + this.comPortNrTextBox.TabIndex = 17; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(26, 173); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(68, 13); + this.label1.TabIndex = 16; + this.label1.Text = "Serial Port #:"; + // + // capacityLabel + // + this.capacityLabel.AutoSize = true; + this.capacityLabel.Location = new System.Drawing.Point(26, 76); + this.capacityLabel.Name = "capacityLabel"; + this.capacityLabel.Size = new System.Drawing.Size(76, 13); + this.capacityLabel.TabIndex = 5; + this.capacityLabel.Text = "Tank Capacity"; + // + // capacityTextBox + // + this.capacityTextBox.Enabled = false; + this.capacityTextBox.Location = new System.Drawing.Point(137, 73); + this.capacityTextBox.Name = "capacityTextBox"; + this.capacityTextBox.Size = new System.Drawing.Size(43, 20); + this.capacityTextBox.TabIndex = 6; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(186, 76); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(19, 13); + this.label2.TabIndex = 7; + this.label2.Text = "kg"; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(186, 99); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(19, 13); + this.label3.TabIndex = 10; + this.label3.Text = "kg"; + // + // emptyTextBox + // + this.emptyTextBox.Enabled = false; + this.emptyTextBox.Location = new System.Drawing.Point(137, 96); + this.emptyTextBox.Name = "emptyTextBox"; + this.emptyTextBox.Size = new System.Drawing.Size(43, 20); + this.emptyTextBox.TabIndex = 9; + // + // emptyLabel + // + this.emptyLabel.AutoSize = true; + this.emptyLabel.Location = new System.Drawing.Point(26, 99); + this.emptyLabel.Name = "emptyLabel"; + this.emptyLabel.Size = new System.Drawing.Size(64, 13); + this.emptyLabel.TabIndex = 8; + this.emptyLabel.Text = "Tank Empty"; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(186, 145); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(24, 13); + this.label4.TabIndex = 15; + this.label4.Text = "sec"; + // + // emptyTimeTextBox + // + this.emptyTimeTextBox.Enabled = false; + this.emptyTimeTextBox.Location = new System.Drawing.Point(137, 142); + this.emptyTimeTextBox.Name = "emptyTimeTextBox"; + this.emptyTimeTextBox.Size = new System.Drawing.Size(43, 20); + this.emptyTimeTextBox.TabIndex = 14; + // + // label5 + // + this.label5.AutoSize = true; + this.label5.Location = new System.Drawing.Point(26, 145); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(90, 13); + this.label5.TabIndex = 13; + this.label5.Text = "Tank Empty Time"; + // + // formatTextBox + // + this.formatTextBox.Enabled = false; + this.formatTextBox.Location = new System.Drawing.Point(137, 119); + this.formatTextBox.Name = "formatTextBox"; + this.formatTextBox.Size = new System.Drawing.Size(43, 20); + this.formatTextBox.TabIndex = 12; + // + // formatLabel + // + this.formatLabel.AutoSize = true; + this.formatLabel.Location = new System.Drawing.Point(26, 122); + this.formatLabel.Name = "formatLabel"; + this.formatLabel.Size = new System.Drawing.Size(76, 13); + this.formatLabel.TabIndex = 11; + this.formatLabel.Text = "Decimal points"; + // + // idNrTextBox + // + this.idNrTextBox.Enabled = false; + this.idNrTextBox.Location = new System.Drawing.Point(137, 50); + this.idNrTextBox.Name = "idNrTextBox"; + this.idNrTextBox.Size = new System.Drawing.Size(43, 20); + this.idNrTextBox.TabIndex = 4; + this.idNrTextBox.TextChanged += new System.EventHandler(this.idNrTextBox_TextChanged); + // + // idNrLabel + // + this.idNrLabel.AutoSize = true; + this.idNrLabel.Location = new System.Drawing.Point(26, 53); + this.idNrLabel.Name = "idNrLabel"; + this.idNrLabel.Size = new System.Drawing.Size(85, 13); + this.idNrLabel.TabIndex = 3; + this.idNrLabel.Text = "ID Number (1..3)"; + // + // BalanceCfgCtrl + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.idNrTextBox); + this.Controls.Add(this.idNrLabel); + this.Controls.Add(this.formatTextBox); + this.Controls.Add(this.formatLabel); + this.Controls.Add(this.label4); + this.Controls.Add(this.emptyTimeTextBox); + this.Controls.Add(this.label5); + this.Controls.Add(this.label3); + this.Controls.Add(this.emptyTextBox); + this.Controls.Add(this.emptyLabel); + this.Controls.Add(this.label2); + this.Controls.Add(this.capacityTextBox); + this.Controls.Add(this.capacityLabel); + this.Controls.Add(this.handshakeComboBox); + this.Controls.Add(this.stopBitsComboBox); + this.Controls.Add(this.parityComboBox); + this.Controls.Add(this.nameTextBox); + this.Controls.Add(this.nameLabel); + this.Controls.Add(this.classNameLabel); + this.Controls.Add(this.handshakeLabel); + this.Controls.Add(this.stopBitsLabel); + this.Controls.Add(this.dataBitsTextBox); + this.Controls.Add(this.dataBitsLabel); + this.Controls.Add(this.partityLabel); + this.Controls.Add(this.baudRateTextBox); + this.Controls.Add(this.baudRateLabel); + this.Controls.Add(this.comPortNrTextBox); + this.Controls.Add(this.label1); + this.Name = "BalanceCfgCtrl"; + this.Size = new System.Drawing.Size(300, 250); + this.Load += new System.EventHandler(this.BalanceCfgCtrl_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.ComboBox handshakeComboBox; + private System.Windows.Forms.ComboBox stopBitsComboBox; + private System.Windows.Forms.ComboBox parityComboBox; + private System.Windows.Forms.TextBox nameTextBox; + private System.Windows.Forms.Label nameLabel; + private System.Windows.Forms.Label classNameLabel; + private System.Windows.Forms.Label handshakeLabel; + private System.Windows.Forms.Label stopBitsLabel; + private System.Windows.Forms.TextBox dataBitsTextBox; + private System.Windows.Forms.Label dataBitsLabel; + private System.Windows.Forms.Label partityLabel; + private System.Windows.Forms.TextBox baudRateTextBox; + private System.Windows.Forms.Label baudRateLabel; + private System.Windows.Forms.TextBox comPortNrTextBox; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label capacityLabel; + private System.Windows.Forms.TextBox capacityTextBox; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.TextBox emptyTextBox; + private System.Windows.Forms.Label emptyLabel; + private System.Windows.Forms.Label label4; + private System.Windows.Forms.TextBox emptyTimeTextBox; + private System.Windows.Forms.Label label5; + private System.Windows.Forms.TextBox formatTextBox; + private System.Windows.Forms.Label formatLabel; + private System.Windows.Forms.TextBox idNrTextBox; + private System.Windows.Forms.Label idNrLabel; + } +} diff --git a/TestBenchFramework/BenchControl/MettlerToledo/Multi/BalanceCfgCtrl.cs b/TestBenchFramework/BenchControl/MettlerToledo/Multi/BalanceCfgCtrl.cs new file mode 100644 index 000000000..55f2d9f64 --- /dev/null +++ b/TestBenchFramework/BenchControl/MettlerToledo/Multi/BalanceCfgCtrl.cs @@ -0,0 +1,242 @@ +/// +/// Copyright (c) 2013-2015 Sensus Metering Systems +/// +using System; +using System.Globalization; +using System.Windows.Forms; +using System.IO.Ports; +using log4net; +using TBF.BenchControl.Generic; + +namespace TBF.BenchControl.MettlerToledo.Multi +{ + public partial class BalanceCfgCtrl : UserControl, IComponentCfgCtrl + { + static readonly ILog log = LogManager.GetLogger(typeof(BalanceCfgCtrl)); + + public bool ShowMore { get { return false; } } + + BalanceCfg config; + public IComponentCfg Config + { + get { return config as IComponentCfg; } + set + { + config = value as BalanceCfg; + Redraw(); + } + } + + public BalanceCfgCtrl() + { + InitializeComponent(); + + parityComboBox.Items.Add(Parity.None.ToString()); + parityComboBox.Items.Add(Parity.Even.ToString()); + parityComboBox.Items.Add(Parity.Odd.ToString()); + + stopBitsComboBox.Items.Add(StopBits.None.ToString()); + stopBitsComboBox.Items.Add(StopBits.One.ToString()); + stopBitsComboBox.Items.Add(StopBits.OnePointFive.ToString()); + stopBitsComboBox.Items.Add(StopBits.Two.ToString()); + + handshakeComboBox.Items.Add(Handshake.None.ToString()); + handshakeComboBox.Items.Add(Handshake.RequestToSend.ToString()); + handshakeComboBox.Items.Add(Handshake.XOnXOff.ToString()); + } + + int GetParityIx(Parity par) + { + if (par == Parity.None) return 0; + if (par == Parity.Even) return 0; + if (par == Parity.Odd) return 0; + return -1; + } + Parity GetParity(string str) + { + 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; + return (Parity)(-1); + } + + int GetStopBitsIx(StopBits sb) + { + if (sb == StopBits.None) return 0; + if (sb == StopBits.One) return 1; + if (sb == StopBits.OnePointFive) return 2; + if (sb == StopBits.Two) return 3; + return -1; + } + StopBits GetStopBits(string str) + { + 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 (StopBits)(-1); + } + + int GetHandshakeIx(Handshake par) + { + if (par == Handshake.None) return 0; + if (par == Handshake.RequestToSend) return 0; + if (par == Handshake.XOnXOff) return 0; + return -1; + } + Handshake GetHandshake(string str) + { + 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; + return (Handshake)(-1); + } + + private void BalanceCfgCtrl_Load(object sender, EventArgs e) + { + Redraw(); + } + + public void Closing() + { + } + + void Redraw() + { + if (config == null) return; /// Control was not loaded, settings were not changed + + classNameLabel.Text = config.Factory.ClassName; + nameTextBox.Text = config.Name; + idNrTextBox.Text = config.IdNr.ToString(); + capacityTextBox.Text = config.Capacity.ToString(); + emptyTextBox.Text = config.Empty.ToString(); + formatTextBox.Text = (config.Format.Length > 1) ? config.Format.Substring(1) : config.Format; + emptyTimeTextBox.Text = config.EmptyTimeSec.ToString(); + + comPortNrTextBox.Text = config.ComPortNr.ToString(); + baudRateTextBox.Text = config.BaudRate.ToString(); + parityComboBox.Text = config.Parity.ToString(); + dataBitsTextBox.Text = config.DataBits.ToString(); + stopBitsComboBox.Text = config.StopBits.ToString(); + handshakeComboBox.Text = config.Handshake.ToString(); + } + + public void Unlock() + { + nameTextBox.Enabled = true; + + idNrTextBox.Enabled = true; + capacityTextBox.Enabled = true; + emptyTextBox.Enabled = true; + formatTextBox.Enabled = true; + emptyTimeTextBox.Enabled = true; + + comPortNrTextBox.Enabled = true; + baudRateTextBox.Enabled = true; + parityComboBox.Enabled = true; + dataBitsTextBox.Enabled = true; + stopBitsComboBox.Enabled = true; + handshakeComboBox.Enabled = true; + } + + public CfgUpdateFlags VerifyCfg(ref string message) + { + CfgUpdateFlags flags = CfgUpdateFlags.None; + + int idNr; + if (!int.TryParse(idNrTextBox.Text, out idNr) || idNr < 1 || idNr > 3) + { + flags |= CfgUpdateFlags.Error; + message += Environment.NewLine + "'Id Number' is not valid"; + } + + float mass; + if (!Utils.TryParseUFloat(capacityTextBox.Text, out mass) || mass <= 0) + { + flags |= CfgUpdateFlags.Error; + message += Environment.NewLine + "'Tank Capacity' is not valid"; + } + if (!Utils.TryParseUFloat(emptyTextBox.Text, out mass) || mass <= 0) + { + flags |= CfgUpdateFlags.Error; + message += Environment.NewLine + "'Tank Empty' is not valid"; + } + + int dummy; + if (!int.TryParse(formatTextBox.Text, out dummy) || dummy < 0 || dummy > 9) + { + flags |= CfgUpdateFlags.Error; + message += Environment.NewLine + "'Decimal points' should be between 0 and 9"; + } + if (!int.TryParse(emptyTimeTextBox.Text, out dummy) || dummy < 1 || dummy > 999) + { + flags |= CfgUpdateFlags.Error; + message += Environment.NewLine + "'Tank Empty Time' should be between 1 and 999 sec"; + } + + if (idNr == 1) + { + if (!int.TryParse(comPortNrTextBox.Text, out dummy) || dummy < 1 || dummy > 999) + { + flags |= CfgUpdateFlags.Error; + message += Environment.NewLine + "'Serial Port Number' is not valid"; + } + if (!int.TryParse(baudRateTextBox.Text, out dummy) || dummy < 150 || dummy > 115200) + { + flags |= CfgUpdateFlags.Error; + message += Environment.NewLine + "'Baud Rate' is not valid"; + } + if (!int.TryParse(dataBitsTextBox.Text, out dummy) || dummy < 7 || dummy > 8) + { + flags |= CfgUpdateFlags.Error; + message += Environment.NewLine + "'Data Bits' is not valid"; + } + } + + return flags; + } + + 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.IdNr = int.Parse(idNrTextBox.Text); + + config.Capacity = Utils.ParseUFloat(capacityTextBox.Text); + config.Empty = Utils.ParseUFloat(emptyTextBox.Text); + config.Format = "F" + formatTextBox.Text; + config.EmptyTimeSec = int.Parse(emptyTimeTextBox.Text); + + if (config.IdNr == 1) + { + config.ComPortNr = int.Parse(comPortNrTextBox.Text); + config.BaudRate = int.Parse(baudRateTextBox.Text); + config.Parity = GetParity(parityComboBox.SelectedItem.ToString()); + config.DataBits = int.Parse(dataBitsTextBox.Text); + config.StopBits = GetStopBits(stopBitsComboBox.SelectedItem.ToString()); + config.Handshake = GetHandshake(handshakeComboBox.SelectedItem.ToString()); + } + + return flags; + } + + private void idNrTextBox_TextChanged(object sender, EventArgs e) + { + int idNr; + if (int.TryParse(idNrTextBox.Text, out idNr)) + { + bool visible = (idNr == 1); + + comPortNrTextBox.Visible = visible; + baudRateTextBox.Visible = visible; + parityComboBox.Visible = visible; + dataBitsTextBox.Visible = visible; + stopBitsComboBox.Visible = visible; + handshakeComboBox.Visible = visible; + } + } + } +} diff --git a/TestBenchFramework/BenchControl/MettlerToledo/Multi/BalanceCfgCtrl.resx b/TestBenchFramework/BenchControl/MettlerToledo/Multi/BalanceCfgCtrl.resx new file mode 100644 index 000000000..1af7de150 --- /dev/null +++ b/TestBenchFramework/BenchControl/MettlerToledo/Multi/BalanceCfgCtrl.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/MettlerToledo/Multi/BalanceDev.cs b/TestBenchFramework/BenchControl/MettlerToledo/Multi/BalanceDev.cs new file mode 100644 index 000000000..1423d2b15 --- /dev/null +++ b/TestBenchFramework/BenchControl/MettlerToledo/Multi/BalanceDev.cs @@ -0,0 +1,436 @@ +/// +/// Copyright (c) 2013-2015 Sensus Metering Systems +/// +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Text; +using System.IO.Ports; +using log4net; +using TBF.BenchControl.Generic; +using TBF.Boxes; + +namespace TBF.BenchControl.MettlerToledo.Multi +{ + /// + /// Mettler Toledo ICS4_5 Weighting terminal connected via serial interface (RS232) + /// + /// + /// Implemented and tested on 15.10.2013 by Milan Hanajik + /// + public class BalanceDev : ComponentBase, IDevice, GenericDevices.IBalance + { + /// + /// Info: StartMassMeasurement() and "Balnce response = .., Mass = ..." + /// Warn: Start measurement when busy is true + /// + private static readonly ILog log = LogManager.GetLogger(typeof(BalanceDev)); + public override string ToString() { return string.Format("MettlerToledo.Balance({0})", Cfg.ToString(1)); } + + protected readonly BalanceCfg balanceCfg; + + /// + /// Enumeration of balances via static fields and methods + /// + static int nextBalanceIdx = 0; + public static new void ResetStaticProperties() + { + nextBalanceIdx = 0; + } + public static int BalancesCount { get { return nextBalanceIdx; } } + public static BalanceDev[] Balances; + public static float[] Masses; + /// + protected int balanceNr; /// 0-based balance number + + protected SerialPort serialPort; + protected StringBuilder stringBuilder; + + public int BalanceNr { get { return balanceNr; } } + public float Capacity { get { return balanceCfg.Capacity; } } + public int EmptyTimeSec { get { return balanceCfg.EmptyTimeSec; } } + + /// The state of the mass measurement + public MsrmntState MsrmntState { get { return msrmntState; } } + protected MsrmntState msrmntState; + + /// The mass after StartMassMeasurement() when MsrmntState == MsrmntState.Valid + public float Mass { get { return mass; } } + protected float mass; + + /// The time stamp after StartMassMeasurement() when MsrmntState == MsrmntState.Valid + public int MsrmntTimeStamp { get { return msrmntTimeStamp; } } + protected int msrmntTimeStamp; + + public string Format { get { return balanceCfg.Format; } } + + /// + /// Constructor + /// + /// Balance properties + /// A list of components loaded so far + public BalanceDev(BalanceCfg cfg) + : base(cfg) + { + balanceCfg = cfg; + + balanceNr = nextBalanceIdx++; + Masses = new float[nextBalanceIdx]; /// (re)initialize the static array of masses of all balances + /// + if (Balances == null || Balances.Length < nextBalanceIdx) + { + BalanceDev[] balancesSoFar = Balances; + Balances = new BalanceDev[nextBalanceIdx]; + if (balancesSoFar != null) for (int i = 0; i < balancesSoFar.Length; i++) Balances[i] = balancesSoFar[i]; + Balances[nextBalanceIdx - 1] = this; + } + + log.Debug(this.ToString()); + } + + public void Initialize() + { + msrmntState = MsrmntState.Failed; /// Data not valid yet + + if (balanceCfg.DebugLevel == Entities.DebugMode.Simulate) return; + + if (balanceCfg.IdNr == 1) + { + stringBuilder = new StringBuilder(40); + string comPortName = "COM" + balanceCfg.ComPortNr.ToString(); + serialPort = new SerialPort(comPortName, balanceCfg.BaudRate, balanceCfg.Parity, balanceCfg.DataBits, balanceCfg.StopBits); + serialPort.Handshake = balanceCfg.Handshake; + serialPort.Open(); + } + + log.FatalFormat("Successfully initialized device {0}", ToString()); + } + + public bool IsEmpty(float mass) + { + return (mass <= balanceCfg.Empty); + } + + public void ZeroWhenStable() + { + if (balanceCfg.DebugLevel == Entities.DebugMode.Simulate) return; + + if (msrmntState == MsrmntState.Busy) + { + log.Warn("ZeroWhenStable() returns without starting zeroing the scale because measurementState == MeasurementState.Busy"); + return; + } + + log.Info("ZeroWhenStable()"); + + msrmntState = MsrmntState.Busy; + stringBuilder.Clear(); + serialPort.Write("Z\r\n"); + } + + public void Taring() + { + if (balanceCfg.DebugLevel == Entities.DebugMode.Simulate) return; + + if (msrmntState == MsrmntState.Busy) + { + log.Warn("Taring() returns without starting taring the scale because measurementState == MeasurementState.Busy"); + return; + } + + log.Info("Taring()"); + + msrmntState = MsrmntState.Busy; + stringBuilder.Clear(); + serialPort.Write("T\r\n"); + } + + /// + /// Get a stable mass measurement + /// + public void GetStableMassMeasurement() + { + if (balanceCfg.DebugLevel == Entities.DebugMode.Simulate) return; + + if (msrmntState == MsrmntState.Busy) + { + log.Warn("GetStableMassMeasurement() returns without starting a measurement because measurementState == MeasurementState.Busy"); + return; + } + + log.Info("GetStableMassMeasurement()"); + + msrmntState = MsrmntState.Busy; + stringBuilder.Clear(); + serialPort.Write("S\r\n"); + } + + /// + /// Get an immediate mass measurement + /// + public void GetImmediateMassMeasurement() + { + if (balanceCfg.DebugLevel == Entities.DebugMode.Simulate) return; + + if (msrmntState == MsrmntState.Busy) + { + log.Warn("GetImmediateMassMeasurement() returns without starting a measurement because measurementState == MeasurementState.Busy"); + return; + } + + log.Info("GetImmediateMassMeasurement()"); + + msrmntState = MsrmntState.Busy; + stringBuilder.Clear(); + serialPort.Write("SI\r\n"); + } + + /// Units for SetUnits() argument + public enum Units + { + g, + kg, + t, + lb, + oz + } + + /// + /// Get the serial number + /// + /// After a successful SetUnits(kg) mass is still sent in g. MH 15.10.2013 + public void SetUnits(Units unit) + { + if (balanceCfg.DebugLevel == Entities.DebugMode.Simulate) return; + + if (msrmntState == MsrmntState.Busy) + { + log.Warn("SetUnits() returns without setting the units because measurementState == MeasurementState.Busy"); + return; + } + + log.InfoFormat("SetUnits({0})", unit); + + msrmntState = MsrmntState.Busy; + stringBuilder.Clear(); + switch (unit) + { + case Units.g: serialPort.Write("U g\r\n"); break; + case Units.kg: serialPort.Write("U kg\r\n"); break; + case Units.t: serialPort.Write("U t\r\n"); break; + case Units.lb: serialPort.Write("U lb\r\n"); break; + case Units.oz: serialPort.Write("U oz\r\n"); break; + } + } + + /// + /// Parse characters received from the serial port + /// + public virtual void RunDeviceBefore() + { + if (balanceCfg.DebugLevel == Entities.DebugMode.Simulate) + { + mass = TestBenchSim.GetSimMass(balanceNr); + Masses[balanceNr] = mass; + msrmntState = MsrmntState.Valid; + msrmntTimeStamp = StateMachine.Time; + return; + } + + if (balanceCfg.IdNr != 1) return; + + log.Debug("RunDevice()"); + + if (msrmntState != MsrmntState.Busy) return; /// No measurement in progress + + string justReceived = serialPort.ReadExisting(); + if (justReceived != null && justReceived.Length > 0) + { + log.Debug("RunDevice() received " + justReceived); + stringBuilder.Append(justReceived); + } + + string currentBuffer = stringBuilder.ToString(); + int eolPos = currentBuffer.IndexOf("\r\n"); + if (eolPos >= 0) + { + msrmntTimeStamp = StateMachine.Time; + + /// Get part of theh string before EOL + string received = currentBuffer.Substring(0, eolPos); + + /// Put the rest back to the string builder + stringBuilder.Clear(); + if (currentBuffer.Length > eolPos + 2) + { + stringBuilder.Append(currentBuffer.Substring(eolPos + 2)); + } + + while (true) + { + string tmp = received.Replace(" ", " "); + if (tmp.Length == received.Length) break; + received = tmp; + } + + string[] fields = received.Split(new char[] { ' ' }); + + if (fields.Length == 1 && fields[0].Equals("ZA")) /// Zero when stable + { + mass = 0; + Masses[balanceNr] = mass; + //msrmntState = MsrmntState.Valid; + log.InfoFormat("Balance response = \"{0}\"", received); + return; + } + else if (fields.Length < 2) + { + msrmntState = MsrmntState.Failed; + log.WarnFormat("Balance response = \"{0}\", Unexpected error !!!", received); + return; + } + + if (fields[0].Equals("Z")) /// Zero when stable + { + if (fields.Length == 2 && fields[1].Equals("A")) + { + mass = 0; + Masses[balanceNr] = mass; + //msrmntState = MsrmntState.Valid; + log.InfoFormat("Balance response = \"{0}\"", received); + return; + } + else + { + msrmntState = MsrmntState.Failed; + log.WarnFormat("Balance response = \"{0}\", error !!!", received); + } + } + else if (fields[0].Equals("S")) /// Stable mass: field[1] = field[2] = "kg" + { + if (fields.Length >= 3 && + float.TryParse(fields[1], + NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, + CultureInfo.InvariantCulture, + out mass)) + { + if (fields[2].Equals("g")) mass /= 1000.0f; + if (fields[2].Equals("t")) mass *= 1000.0f; + Masses[balanceNr] = mass; + msrmntState = MsrmntState.Valid; + log.InfoFormat("Balance response = \"{0}\", Mass = {1}", received, mass); + } + else if (fields.Length == 2 && fields[1].Equals("-")) + { + mass = 0; + Masses[balanceNr] = mass; + msrmntState = MsrmntState.Valid; + log.InfoFormat("Balance response = \"{0}\", Mass = {1}", received, mass); + } + else + { + msrmntState = MsrmntState.Failed; + log.WarnFormat("Balance response = \"{0}\", Overload or and unexpected error !!!", received); + bool b = float.TryParse(fields[1], NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture, out mass); + + } + } + else if (fields[0].Equals("SD")) /// Dynamic mass: field[1] = field[2] = "kg" + { + if (fields.Length >= 3 && + float.TryParse(fields[1], + NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, + CultureInfo.InvariantCulture, + out mass)) + { + if (fields[2].Equals("g")) mass /= 1000.0f; + if (fields[2].Equals("t")) mass *= 1000.0f; + Masses[balanceNr] = mass; + msrmntState = MsrmntState.Valid; + log.InfoFormat("Balance response = \"{0}\", Mass = {1}", received, mass); + } + else if (fields.Length == 2 && fields[1].Equals("-")) + { + mass = 0; + Masses[balanceNr] = mass; + msrmntState = MsrmntState.Valid; + log.InfoFormat("Balance response = \"{0}\", Mass = {1}", received, mass); + } + else + { + msrmntState = MsrmntState.Failed; + log.WarnFormat("Balance response = \"{0}\", Overload or and unexpected error !!!", received); + bool b = float.TryParse(fields[1], NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture, out mass); + + } + } + else if (fields[0].Equals("TB")) /// Taring + { + if (fields.Length >= 3 && + float.TryParse(fields[1], + NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, + CultureInfo.InvariantCulture, + out mass)) + { + if (fields[2].Equals("g")) mass /= 1000.0f; + if (fields[2].Equals("t")) mass *= 1000.0f; + msrmntState = MsrmntState.Valid; + log.InfoFormat("Balance response = \"{0}\", Tara = {1}", received, mass); + } + else + { + msrmntState = MsrmntState.Failed; + log.WarnFormat("Balance response = \"{0}\", Overload or and unexpected error !!!", received); + } + } + else + { + msrmntState = MsrmntState.Failed; + log.WarnFormat("Balance response = \"{0}\", Unexpected error !!!", received); + } + } + } + + /// Run this device + public void RunDeviceAfter() + { + } + + /// Stop this device + public void StopDevice() + { + if (balanceCfg.IdNr == 1 && serialPort != null) serialPort.Close(); + } + + /// + /// Events: BalanceDone, Error + /// + /// Reference to a variable for 'tara' in kg + /// TaringOp instance reference casted to IOperaton + public IOperation TaringOp(ref FloatBox tara) + { + return new TaringOp(this, ref tara); + } + + /// + /// Events: BalanceDone, Error + /// + /// Reference to a variable for the measured mass in kg + /// ReadMassOp instance reference casted to IOperaton + public IOperation ReadMassOp(ref FloatBox mass) + { + return new ReadMassOp(this, ref mass); + } + + /// + /// Events: BalanceDone, Error + /// + /// Reference to a variable for the measured mass in kg + /// Required mass readings count (>= 3) + /// ReadMassAverageOp instance reference casted to IOperaton + public IOperation ReadStableMassOp(ref FloatBox mass, int readingsCount) + { + return new ReadStableMassOp(this, ref mass, readingsCount); + } + } +} diff --git a/TestBenchFramework/BenchControl/MettlerToledo/Multi/BalanceFactory.cs b/TestBenchFramework/BenchControl/MettlerToledo/Multi/BalanceFactory.cs new file mode 100644 index 000000000..6d2b3662d --- /dev/null +++ b/TestBenchFramework/BenchControl/MettlerToledo/Multi/BalanceFactory.cs @@ -0,0 +1,38 @@ +/// +/// Copyright (c) 2013-2015 Sensus Metering Systems +/// +using System.Collections.Generic; +using TBF.BenchControl.Generic; + +namespace TBF.BenchControl.MettlerToledo.Multi +{ + public class BalanceFactory : IComponentFactory + { + public string ClassName { get { return "MettlerToledo-Multi"; } } + + /// Max. number of components of this class in the system + public int MaxCount { get { return 5; } } + + public IComponentCfg DefaultConfig() + { + return new BalanceCfg(this); + } + + public IComponentCfgCtrl CreateCfgCtrl() + { + return new BalanceCfgCtrl(); + } + + public IComponent ComponentFromCmpntCfg(IComponentCfg config, IList components) + { + return new BalanceDev((BalanceCfg)config); + } + + public IComponentCfg CmpntCfgFromCmpntEntity(Entities.Component component) + { + return ComponentCfgBase.CreateFromDbEntity(typeof(BalanceCfg), component, this); + } + + public void ResetStaticProperties() { BalanceDev.ResetStaticProperties(); } + } +} diff --git a/TestBenchFramework/BenchControl/MettlerToledo/Multi/ReadMassOp.cs b/TestBenchFramework/BenchControl/MettlerToledo/Multi/ReadMassOp.cs new file mode 100644 index 000000000..d4a8d7e22 --- /dev/null +++ b/TestBenchFramework/BenchControl/MettlerToledo/Multi/ReadMassOp.cs @@ -0,0 +1,75 @@ +/// +/// Copyright (c) 2013-2015 Sensus Metering Systems +/// +using System; +using log4net; +using TBF.Boxes; + +namespace TBF.BenchControl.MettlerToledo.Multi +{ + public class ReadMassOp : IOperation + { + private static readonly ILog log = LogManager.GetLogger(typeof(ReadMassOp)); + public override string ToString() { return string.Format("ReadMassOp(.,.)"); } + + bool done; + + /// Set by the constructor + BalanceDev balanceDev; + FloatBox result; + + /// + /// Events: BalanceDone, Error + /// + /// Balance device instance + /// Required mass readings count (>= 3) + /// Reference to the measured mass in kg + public ReadMassOp(BalanceDev balanceDev, ref FloatBox result) + { + if (balanceDev == null) throw new ArgumentNullException("balanceDev"); + this.balanceDev = balanceDev; + + this.result = result; + + log.Debug(this.ToString()); + } + + /// Start this operation + public void Start() + { + done = false; + balanceDev.GetImmediateMassMeasurement(); + } + + /// Run this operation + /// + /// Event.None + /// Event.BalanceDone + /// Event.Error . . . . . Current.Tick == null + /// + public Event Run() + { + if (balanceDev.MsrmntState == MsrmntState.Valid) + { + result.Val = balanceDev.Mass; + done = true; + log.InfoFormat("ReadMassOp.Run() ... mass={0} ... returning Event.BalanceDone", balanceDev.Mass); + balanceDev.GetImmediateMassMeasurement(); /// Start another measurement + return Event.BalanceDone; /// Mass read OK + } + else if (done) + { + return Event.BalanceDone; /// Mass has already been read (at least once) + } + else + { + return Event.None; + } + } + + /// Stop this operation + public void Stop() + { + } + } +} diff --git a/TestBenchFramework/BenchControl/MettlerToledo/Multi/ReadMassesOp.cs b/TestBenchFramework/BenchControl/MettlerToledo/Multi/ReadMassesOp.cs new file mode 100644 index 000000000..31d69f794 --- /dev/null +++ b/TestBenchFramework/BenchControl/MettlerToledo/Multi/ReadMassesOp.cs @@ -0,0 +1,63 @@ +/// +/// Copyright (c) 2013-2015 Sensus Metering Systems +/// +using System; +using log4net; + +namespace TBF.BenchControl.MettlerToledo.Multi +{ + public class ReadMassesOp : IOperation + { + private static readonly ILog log = LogManager.GetLogger(typeof(ReadMassesOp)); + public override string ToString() { return string.Format("ReadMassesOp()"); } + + bool done; + + /// + /// Events: BalanceDone, Error + /// + /// Balance device instance + /// Required mass readings count (>= 3) + /// Reference to the measured mass in kg + public ReadMassesOp() + { + log.Debug(this.ToString()); + } + + /// Start this operation + public void Start() + { + done = false; + for (int i = 0; i < BalanceDev.BalancesCount; i++) + { + BalanceDev.Balances[i].GetImmediateMassMeasurement(); + } + } + + /// Run this operation + /// + /// Event.None + /// Event.BalanceDone + /// Event.Error . . . . . Current.Tick == null + /// + public Event Run() + { + if (done) return Event.BalanceDone; /// Mass has already been read + + for (int i = 0; i < BalanceDev.BalancesCount; i++) + { + if (BalanceDev.Balances[i].MsrmntState == MsrmntState.Busy) + { + return Event.None; + } + } + done = true; + return Event.BalanceDone; + } + + /// Stop this operation + public void Stop() + { + } + } +} diff --git a/TestBenchFramework/BenchControl/MettlerToledo/Multi/ReadStableMassOp.cs b/TestBenchFramework/BenchControl/MettlerToledo/Multi/ReadStableMassOp.cs new file mode 100644 index 000000000..98a54b19e --- /dev/null +++ b/TestBenchFramework/BenchControl/MettlerToledo/Multi/ReadStableMassOp.cs @@ -0,0 +1,94 @@ +/// +/// Copyright (c) 2013-2015 Sensus Metering Systems +/// +using System; +using log4net; +using TBF.Boxes; + +namespace TBF.BenchControl.MettlerToledo.Multi +{ + /// + /// Operation to read more mass values and average them to obtain a more accurate result. + /// + public class ReadStableMassOp : IOperation + { + private static readonly ILog log = LogManager.GetLogger(typeof(ReadStableMassOp)); + public override string ToString() { return string.Format("ReadStableMassOp(.,{0},.)", totalReadingsCount); } + + /// Operation specific + float[] massReadings; + int currentReadingsCount; + + /// Set by the constructor + BalanceDev balanceDev; + int totalReadingsCount; + FloatBox result; + + /// + /// Events: BalanceDone, Error + /// + /// Balance device instance + /// Reference to the measured mass in kg + /// Required mass readings count (>= 3) + public ReadStableMassOp(BalanceDev balanceDev, ref FloatBox result, int readingsCount) + { + if (balanceDev == null) throw new ArgumentNullException("balanceDev"); + this.balanceDev = balanceDev; + + if (readingsCount < 3) throw new ArgumentOutOfRangeException("requiredReadingsCount"); + this.totalReadingsCount = readingsCount; + + this.result = result; + + log.Debug(this.ToString()); + } + + /// Start this operation + public void Start() + { + currentReadingsCount = 0; + massReadings = new float[totalReadingsCount]; + balanceDev.GetStableMassMeasurement(); + } + + /// Run this operation + /// + /// Event.None + /// Event.BalanceDone + /// Event.Error . . . . . Current.Tick == null + /// + public Event Run() + { + if (currentReadingsCount >= totalReadingsCount) return Event.BalanceDone; /// Mass has already been calculated + + if (balanceDev.MsrmntState == MsrmntState.Busy) return Event.None; + + if (balanceDev.MsrmntState == MsrmntState.Valid) + { + massReadings[currentReadingsCount++] = balanceDev.Mass; + + if (currentReadingsCount == totalReadingsCount) + { + /// calculate the average + float calcMass = 0; + Array.Sort(massReadings); + for (int i = 1; i < totalReadingsCount - 1; i++) calcMass += massReadings[i]; + calcMass = (calcMass / (totalReadingsCount - 2)); + + log.InfoFormat("ReadStableMassOp.Run() ... valid mass={0} ... returning Event.BalanceDone", calcMass); + + result.Val = calcMass; + return Event.BalanceDone; /// Mass has just been calculated + } + } + + balanceDev.GetStableMassMeasurement(); + return Event.None; + } + + /// Stop this operation + public void Stop() + { + } + } +} diff --git a/TestBenchFramework/BenchControl/MettlerToledo/Multi/SetUnitsOp.cs b/TestBenchFramework/BenchControl/MettlerToledo/Multi/SetUnitsOp.cs new file mode 100644 index 000000000..513693522 --- /dev/null +++ b/TestBenchFramework/BenchControl/MettlerToledo/Multi/SetUnitsOp.cs @@ -0,0 +1,61 @@ +/// +/// Copyright (c) 2013-2015 Sensus Metering Systems +/// +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using log4net; + +namespace TBF.BenchControl.MettlerToledo.Multi +{ + public class SetUnitsOp : IOperation + { + private static readonly ILog log = LogManager.GetLogger(typeof(SetUnitsOp)); + public override string ToString() { return string.Format("SetUnitsOp({0})", units); } + + /// Set by the constructor + BalanceDev balanceDev; + BalanceDev.Units units; + + /// + /// Events: BalanceDone, Error + /// + /// Balance device instance + /// Reference to the serialNumber + public SetUnitsOp(BalanceDev balanceDev, BalanceDev.Units units) + { + if (balanceDev == null) throw new ArgumentNullException("balanceDev"); + this.balanceDev = balanceDev; + + this.units = units; + + log.Debug(this.ToString()); + } + + /// Start this operation + public void Start() + { + log.Debug("Start()"); + balanceDev.SetUnits(units); + } + + /// Run this operation + /// + /// Event.None + /// Event.BalanceDone + /// + public Event Run() + { + if (balanceDev.MsrmntState == MsrmntState.Valid) return Event.BalanceDone; /// Units set + if (balanceDev.MsrmntState == MsrmntState.Failed) return Event.Error; /// Failed + return Event.None; /// No result yet + } + + /// Stop this operation + public void Stop() + { + log.Debug("Stop()"); + } + } +} diff --git a/TestBenchFramework/BenchControl/MettlerToledo/Multi/TaringOp.cs b/TestBenchFramework/BenchControl/MettlerToledo/Multi/TaringOp.cs new file mode 100644 index 000000000..2106b019c --- /dev/null +++ b/TestBenchFramework/BenchControl/MettlerToledo/Multi/TaringOp.cs @@ -0,0 +1,78 @@ +/// +/// Copyright (c) 2013-2015 Sensus Metering Systems +/// +using System; +using log4net; +using TBF.Boxes; + +namespace TBF.BenchControl.MettlerToledo.Multi +{ + public class TaringOp : IOperation + { + private static readonly ILog log = LogManager.GetLogger(typeof(TaringOp)); + public override string ToString() { return string.Format("TaringOp(.,.)"); } + + bool done; + + /// Set by the constructor + BalanceDev balanceDev; + FloatBox tara; + + /// + /// Events: BalanceDone, Error + /// + /// Balance device instance + /// Reference to variable for 'tara' in kg + public TaringOp(BalanceDev balanceDev, ref FloatBox tara) + { + if (balanceDev == null) throw new ArgumentNullException("balanceDev"); + this.balanceDev = balanceDev; + + this.tara = tara; + + log.Debug(this.ToString()); + } + + /// Start this operation + public void Start() + { + done = false; + balanceDev.Taring(); + } + + /// Run this operation + /// + /// Event.None + /// Event.BalanceDone + /// Event.Error . . . . . Current.Tick == null + /// + public Event Run() + { + if (done) return Event.BalanceDone; /// Taring has been done already + + if (balanceDev.MsrmntState == MsrmntState.Busy) return Event.Busy; + + if (balanceDev.MsrmntState == MsrmntState.Overload) + { + tara.Val = balanceDev.Capacity; + done = true; + return Event.BalanceOverload; + } + + if (balanceDev.MsrmntState == MsrmntState.Valid) + { + tara.Val = balanceDev.Mass; + done = true; + return Event.BalanceDone; /// Taring completed + } + + balanceDev.Taring(); /// Failed -> repeat taring + return Event.Busy; + } + + /// Stop this operation + public void Stop() + { + } + } +} diff --git a/TestBenchFramework/BenchControl/TbfComponents.cs b/TestBenchFramework/BenchControl/TbfComponents.cs index 8c98a06af..7a8b31335 100644 --- a/TestBenchFramework/BenchControl/TbfComponents.cs +++ b/TestBenchFramework/BenchControl/TbfComponents.cs @@ -40,6 +40,7 @@ namespace TBF.BenchControl Factories.Add(new TestMethods.LeakTest.TestMethodFactory()); Factories.Add(new MettlerToledo.Standard.BalanceFactory()); Factories.Add(new MettlerToledo.Standard.BalanceNewFactory()); + Factories.Add(new MettlerToledo.Multi.BalanceFactory()); Factories.Add(new TestMethods.PMaxTest.TestMethodFactory()); Factories.Add(new Elde.PressureMeter.PressureMeterFactory()); Factories.Add(new Elde.Pump.PumpFactory()); diff --git a/TestBenchFramework/TBF.csproj b/TestBenchFramework/TBF.csproj index 65dffac22..90c24978c 100644 --- a/TestBenchFramework/TBF.csproj +++ b/TestBenchFramework/TBF.csproj @@ -157,6 +157,20 @@ TestStartEndForm.cs + + + UserControl + + + BalanceCfgCtrl.cs + + + + + + + + UserControl @@ -1215,6 +1229,9 @@ ValveCfgCtrl.cs + + BalanceCfgCtrl.cs + BalanceCfgCtrl.cs