diff --git a/Config/Units.cs b/Config/Units.cs index 0ae42b165..2c5e82018 100644 --- a/Config/Units.cs +++ b/Config/Units.cs @@ -1,5 +1,5 @@ /// -/// Copyright (c) 2016-2020 Sensus Slovensko a.s. +/// Copyright (c) 2016-2021 Sensus Slovensko a.s. /// using System; using System.Reflection; @@ -34,6 +34,7 @@ namespace Config [Description("cf/s")] cfs, /// 1 cubic foot per second = 101.9406477312 m3/h [Description("g")] g, /// 0.001 kg + [Description("oz")] oz, /// 0.0283495231 kg [Description("lb")] lb, /// 0.45359237 kg [Description("kg")] kg, /// * 1 kilogram [Description("t")] t, /// 1000 kg @@ -276,6 +277,7 @@ namespace Config return Quantity.Flow; case Unit.g: + case Unit.oz: case Unit.lb: case Unit.kg: case Unit.t: @@ -391,6 +393,7 @@ namespace Config /// Mass: internal representation in kg case Unit.g: return 1000 * v; /// 1 g = 0.001 kg + case Unit.oz: return 35.273962 * v; /// 1 oz = 0.0283495231 kg case Unit.lb: return 2.2046226 * v; /// 1 lb = 0.45359237 kg case Unit.t: return 0.001 * v; /// 1 t = 1000 kg @@ -468,6 +471,7 @@ namespace Config /// Mass: internal representation in kg case Unit.g: return 0.001 * v; /// 1 g = 0.001 kg + case Unit.oz: return 0.0283495231 * v; /// 1 oz = 0.0283495231 kg case Unit.lb: return 0.45359237 * v; /// 1 lb = 0.45359237 kg case Unit.t: return 1000 * v; /// 1 t = 1000 kg diff --git a/TBF/BenchControl/MettlerToledo/Standard/BalanceCfg.cs b/TBF/BenchControl/MettlerToledo/Standard/BalanceCfg.cs index 6e4804dd5..5a29cdbd0 100644 --- a/TBF/BenchControl/MettlerToledo/Standard/BalanceCfg.cs +++ b/TBF/BenchControl/MettlerToledo/Standard/BalanceCfg.cs @@ -1,5 +1,5 @@ /// -/// Copyright (c) 2013-2020 Sensus Slovensko a.s. +/// Copyright (c) 2013-2021 Sensus Slovensko a.s. /// using System; using System.IO; @@ -11,6 +11,14 @@ using TBF.BenchControl.Generic; namespace TBF.BenchControl.MettlerToledo.Standard { + public enum ActionA1D + { + Zero, + Tara, + None, + Count + } + public class BalanceCfg : ComponentCfgBase, GenericDevices.IScaleCfg, GenericDevices.ITankDrainingCfg, IDrawingItemWithMeasuredVal { public static XmlSerializer Serializer = XmlSerializer.FromTypes(new[] { typeof(BalanceCfg) })[0]; @@ -28,12 +36,13 @@ namespace TBF.BenchControl.MettlerToledo.Standard public StopBits StopBits; public Handshake Handshake; - public float Capacity { get; set; } /// Max. water mass in 'kg' or volume in 'l' - public float Empty { get; set; } /// Mass threshold for 'Tank is empty' in 'kg' (or volume in 'l') - public float EmptyUp { get; set; } /// Mass threshold for 'Tank is empty' in 'kg' (or volume in 'l') when the drain valve is not open + public float Capacity { get; set; } /// Max. water mass in 'kg' or volume in 'l' + public float Empty { get; set; } /// Mass threshold for 'Tank is empty' in 'kg' (or volume in 'l') + public float EmptyUp { get; set; } /// Mass threshold for 'Tank is empty' in 'kg' (or volume in 'l') when the drain valve is not open + public string Evaporation { get; set; } public string DrainValve { get; set; } public int DrainTimeSec { get; set; } - public string Evaporation { get; set; } + public ActionA1D ActionAfter1stDraining { get; set; } /// Buoyancy related serialized parameters displayed in Metrology tab page public float BuoyancyTemp { get; set; } diff --git a/TBF/BenchControl/MettlerToledo/Standard/BalanceCfgCtrl.Designer.cs b/TBF/BenchControl/MettlerToledo/Standard/BalanceCfgCtrl.Designer.cs index 05ef6afa6..dd531c50a 100644 --- a/TBF/BenchControl/MettlerToledo/Standard/BalanceCfgCtrl.Designer.cs +++ b/TBF/BenchControl/MettlerToledo/Standard/BalanceCfgCtrl.Designer.cs @@ -66,13 +66,15 @@ namespace TBF.BenchControl.MettlerToledo.Standard this.unitsLabel = new System.Windows.Forms.Label(); this.formatTextBox = new System.Windows.Forms.TextBox(); this.formatLabel = new System.Windows.Forms.Label(); + this.afterFirstDrainingComboBox = new System.Windows.Forms.ComboBox(); + this.afterFirstDrainingLabel = new System.Windows.Forms.Label(); this.SuspendLayout(); // // handshakeComboBox // this.handshakeComboBox.Enabled = false; this.handshakeComboBox.FormattingEnabled = true; - this.handshakeComboBox.Location = new System.Drawing.Point(236, 252); + this.handshakeComboBox.Location = new System.Drawing.Point(236, 254); this.handshakeComboBox.Name = "handshakeComboBox"; this.handshakeComboBox.Size = new System.Drawing.Size(43, 21); this.handshakeComboBox.TabIndex = 31; @@ -81,7 +83,7 @@ namespace TBF.BenchControl.MettlerToledo.Standard // this.stopBitsComboBox.Enabled = false; this.stopBitsComboBox.FormattingEnabled = true; - this.stopBitsComboBox.Location = new System.Drawing.Point(236, 229); + this.stopBitsComboBox.Location = new System.Drawing.Point(236, 231); this.stopBitsComboBox.Name = "stopBitsComboBox"; this.stopBitsComboBox.Size = new System.Drawing.Size(43, 21); this.stopBitsComboBox.TabIndex = 29; @@ -90,7 +92,7 @@ namespace TBF.BenchControl.MettlerToledo.Standard // this.parityComboBox.Enabled = false; this.parityComboBox.FormattingEnabled = true; - this.parityComboBox.Location = new System.Drawing.Point(100, 252); + this.parityComboBox.Location = new System.Drawing.Point(100, 254); this.parityComboBox.Name = "parityComboBox"; this.parityComboBox.Size = new System.Drawing.Size(43, 21); this.parityComboBox.TabIndex = 25; @@ -124,7 +126,7 @@ namespace TBF.BenchControl.MettlerToledo.Standard // handshakeLabel // this.handshakeLabel.AutoSize = true; - this.handshakeLabel.Location = new System.Drawing.Point(162, 255); + this.handshakeLabel.Location = new System.Drawing.Point(162, 257); this.handshakeLabel.Name = "handshakeLabel"; this.handshakeLabel.Size = new System.Drawing.Size(62, 13); this.handshakeLabel.TabIndex = 30; @@ -133,7 +135,7 @@ namespace TBF.BenchControl.MettlerToledo.Standard // stopBitsLabel // this.stopBitsLabel.AutoSize = true; - this.stopBitsLabel.Location = new System.Drawing.Point(162, 232); + this.stopBitsLabel.Location = new System.Drawing.Point(162, 234); this.stopBitsLabel.Name = "stopBitsLabel"; this.stopBitsLabel.Size = new System.Drawing.Size(49, 13); this.stopBitsLabel.TabIndex = 28; @@ -142,7 +144,7 @@ namespace TBF.BenchControl.MettlerToledo.Standard // dataBitsTextBox // this.dataBitsTextBox.Enabled = false; - this.dataBitsTextBox.Location = new System.Drawing.Point(236, 206); + this.dataBitsTextBox.Location = new System.Drawing.Point(236, 208); this.dataBitsTextBox.Name = "dataBitsTextBox"; this.dataBitsTextBox.Size = new System.Drawing.Size(43, 20); this.dataBitsTextBox.TabIndex = 27; @@ -150,7 +152,7 @@ namespace TBF.BenchControl.MettlerToledo.Standard // dataBitsLabel // this.dataBitsLabel.AutoSize = true; - this.dataBitsLabel.Location = new System.Drawing.Point(162, 209); + this.dataBitsLabel.Location = new System.Drawing.Point(162, 211); this.dataBitsLabel.Name = "dataBitsLabel"; this.dataBitsLabel.Size = new System.Drawing.Size(50, 13); this.dataBitsLabel.TabIndex = 26; @@ -159,7 +161,7 @@ namespace TBF.BenchControl.MettlerToledo.Standard // partityLabel // this.partityLabel.AutoSize = true; - this.partityLabel.Location = new System.Drawing.Point(26, 255); + this.partityLabel.Location = new System.Drawing.Point(26, 257); this.partityLabel.Name = "partityLabel"; this.partityLabel.Size = new System.Drawing.Size(33, 13); this.partityLabel.TabIndex = 24; @@ -168,7 +170,7 @@ namespace TBF.BenchControl.MettlerToledo.Standard // baudRateTextBox // this.baudRateTextBox.Enabled = false; - this.baudRateTextBox.Location = new System.Drawing.Point(100, 229); + this.baudRateTextBox.Location = new System.Drawing.Point(100, 231); this.baudRateTextBox.Name = "baudRateTextBox"; this.baudRateTextBox.Size = new System.Drawing.Size(43, 20); this.baudRateTextBox.TabIndex = 23; @@ -176,7 +178,7 @@ namespace TBF.BenchControl.MettlerToledo.Standard // baudRateLabel // this.baudRateLabel.AutoSize = true; - this.baudRateLabel.Location = new System.Drawing.Point(26, 232); + this.baudRateLabel.Location = new System.Drawing.Point(26, 234); this.baudRateLabel.Name = "baudRateLabel"; this.baudRateLabel.Size = new System.Drawing.Size(53, 13); this.baudRateLabel.TabIndex = 22; @@ -185,7 +187,7 @@ namespace TBF.BenchControl.MettlerToledo.Standard // comPortNrTextBox // this.comPortNrTextBox.Enabled = false; - this.comPortNrTextBox.Location = new System.Drawing.Point(100, 206); + this.comPortNrTextBox.Location = new System.Drawing.Point(100, 208); this.comPortNrTextBox.Name = "comPortNrTextBox"; this.comPortNrTextBox.Size = new System.Drawing.Size(43, 20); this.comPortNrTextBox.TabIndex = 21; @@ -193,7 +195,7 @@ namespace TBF.BenchControl.MettlerToledo.Standard // label1 // this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(26, 209); + this.label1.Location = new System.Drawing.Point(26, 211); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(67, 13); this.label1.TabIndex = 20; @@ -202,7 +204,7 @@ namespace TBF.BenchControl.MettlerToledo.Standard // capacityLabel // this.capacityLabel.AutoSize = true; - this.capacityLabel.Location = new System.Drawing.Point(26, 76); + this.capacityLabel.Location = new System.Drawing.Point(26, 63); this.capacityLabel.Name = "capacityLabel"; this.capacityLabel.Size = new System.Drawing.Size(75, 13); this.capacityLabel.TabIndex = 5; @@ -211,7 +213,7 @@ namespace TBF.BenchControl.MettlerToledo.Standard // capacityTextBox // this.capacityTextBox.Enabled = false; - this.capacityTextBox.Location = new System.Drawing.Point(137, 73); + this.capacityTextBox.Location = new System.Drawing.Point(137, 60); this.capacityTextBox.Name = "capacityTextBox"; this.capacityTextBox.Size = new System.Drawing.Size(43, 20); this.capacityTextBox.TabIndex = 6; @@ -219,7 +221,7 @@ namespace TBF.BenchControl.MettlerToledo.Standard // label2 // this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(186, 76); + this.label2.Location = new System.Drawing.Point(186, 63); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(19, 13); this.label2.TabIndex = 7; @@ -228,7 +230,7 @@ namespace TBF.BenchControl.MettlerToledo.Standard // label3 // this.label3.AutoSize = true; - this.label3.Location = new System.Drawing.Point(186, 99); + this.label3.Location = new System.Drawing.Point(186, 86); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(19, 13); this.label3.TabIndex = 10; @@ -237,7 +239,7 @@ namespace TBF.BenchControl.MettlerToledo.Standard // emptyTextBox // this.emptyTextBox.Enabled = false; - this.emptyTextBox.Location = new System.Drawing.Point(137, 96); + this.emptyTextBox.Location = new System.Drawing.Point(137, 83); this.emptyTextBox.Name = "emptyTextBox"; this.emptyTextBox.Size = new System.Drawing.Size(43, 20); this.emptyTextBox.TabIndex = 9; @@ -245,7 +247,7 @@ namespace TBF.BenchControl.MettlerToledo.Standard // emptyLabel // this.emptyLabel.AutoSize = true; - this.emptyLabel.Location = new System.Drawing.Point(26, 99); + this.emptyLabel.Location = new System.Drawing.Point(26, 86); this.emptyLabel.Name = "emptyLabel"; this.emptyLabel.Size = new System.Drawing.Size(109, 13); this.emptyLabel.TabIndex = 8; @@ -254,7 +256,7 @@ namespace TBF.BenchControl.MettlerToledo.Standard // label4 // this.label4.AutoSize = true; - this.label4.Location = new System.Drawing.Point(186, 170); + this.label4.Location = new System.Drawing.Point(186, 157); this.label4.Name = "label4"; this.label4.Size = new System.Drawing.Size(24, 13); this.label4.TabIndex = 19; @@ -263,7 +265,7 @@ namespace TBF.BenchControl.MettlerToledo.Standard // drainTimeTextBox // this.drainTimeTextBox.Enabled = false; - this.drainTimeTextBox.Location = new System.Drawing.Point(137, 167); + this.drainTimeTextBox.Location = new System.Drawing.Point(137, 154); this.drainTimeTextBox.Name = "drainTimeTextBox"; this.drainTimeTextBox.Size = new System.Drawing.Size(43, 20); this.drainTimeTextBox.TabIndex = 18; @@ -271,7 +273,7 @@ namespace TBF.BenchControl.MettlerToledo.Standard // label5 // this.label5.AutoSize = true; - this.label5.Location = new System.Drawing.Point(26, 170); + this.label5.Location = new System.Drawing.Point(26, 157); this.label5.Name = "label5"; this.label5.Size = new System.Drawing.Size(54, 13); this.label5.TabIndex = 17; @@ -281,7 +283,7 @@ namespace TBF.BenchControl.MettlerToledo.Standard // this.drainValveComboBox.Enabled = false; this.drainValveComboBox.FormattingEnabled = true; - this.drainValveComboBox.Location = new System.Drawing.Point(137, 143); + this.drainValveComboBox.Location = new System.Drawing.Point(137, 130); this.drainValveComboBox.Name = "drainValveComboBox"; this.drainValveComboBox.Size = new System.Drawing.Size(143, 21); this.drainValveComboBox.TabIndex = 16; @@ -289,7 +291,7 @@ namespace TBF.BenchControl.MettlerToledo.Standard // drainingValveLabel // this.drainingValveLabel.AutoSize = true; - this.drainingValveLabel.Location = new System.Drawing.Point(26, 146); + this.drainingValveLabel.Location = new System.Drawing.Point(26, 133); this.drainingValveLabel.Name = "drainingValveLabel"; this.drainingValveLabel.Size = new System.Drawing.Size(61, 13); this.drainingValveLabel.TabIndex = 15; @@ -298,7 +300,7 @@ namespace TBF.BenchControl.MettlerToledo.Standard // label6 // this.label6.AutoSize = true; - this.label6.Location = new System.Drawing.Point(285, 99); + this.label6.Location = new System.Drawing.Point(285, 86); this.label6.Name = "label6"; this.label6.Size = new System.Drawing.Size(19, 13); this.label6.TabIndex = 12; @@ -307,7 +309,7 @@ namespace TBF.BenchControl.MettlerToledo.Standard // emptyUpTextBox // this.emptyUpTextBox.Enabled = false; - this.emptyUpTextBox.Location = new System.Drawing.Point(236, 96); + this.emptyUpTextBox.Location = new System.Drawing.Point(236, 83); this.emptyUpTextBox.Name = "emptyUpTextBox"; this.emptyUpTextBox.Size = new System.Drawing.Size(43, 20); this.emptyUpTextBox.TabIndex = 11; @@ -315,7 +317,7 @@ namespace TBF.BenchControl.MettlerToledo.Standard // label7 // this.label7.AutoSize = true; - this.label7.Location = new System.Drawing.Point(225, 81); + this.label7.Location = new System.Drawing.Point(225, 68); this.label7.Name = "label7"; this.label7.Size = new System.Drawing.Size(83, 13); this.label7.TabIndex = 30; @@ -325,7 +327,7 @@ namespace TBF.BenchControl.MettlerToledo.Standard // this.evaporationComboBox.Enabled = false; this.evaporationComboBox.FormattingEnabled = true; - this.evaporationComboBox.Location = new System.Drawing.Point(137, 119); + this.evaporationComboBox.Location = new System.Drawing.Point(137, 106); this.evaporationComboBox.Name = "evaporationComboBox"; this.evaporationComboBox.Size = new System.Drawing.Size(143, 21); this.evaporationComboBox.TabIndex = 14; @@ -333,7 +335,7 @@ namespace TBF.BenchControl.MettlerToledo.Standard // evaporationLabel // this.evaporationLabel.AutoSize = true; - this.evaporationLabel.Location = new System.Drawing.Point(26, 122); + this.evaporationLabel.Location = new System.Drawing.Point(26, 109); this.evaporationLabel.Name = "evaporationLabel"; this.evaporationLabel.Size = new System.Drawing.Size(64, 13); this.evaporationLabel.TabIndex = 13; @@ -374,10 +376,30 @@ namespace TBF.BenchControl.MettlerToledo.Standard this.formatLabel.TabIndex = 32; this.formatLabel.Text = "Output format"; // + // afterFirstDrainingComboBox + // + this.afterFirstDrainingComboBox.Enabled = false; + this.afterFirstDrainingComboBox.FormattingEnabled = true; + this.afterFirstDrainingComboBox.Location = new System.Drawing.Point(137, 177); + this.afterFirstDrainingComboBox.Name = "afterFirstDrainingComboBox"; + this.afterFirstDrainingComboBox.Size = new System.Drawing.Size(143, 21); + this.afterFirstDrainingComboBox.TabIndex = 37; + // + // afterFirstDrainingLabel + // + this.afterFirstDrainingLabel.AutoSize = true; + this.afterFirstDrainingLabel.Location = new System.Drawing.Point(26, 180); + this.afterFirstDrainingLabel.Name = "afterFirstDrainingLabel"; + this.afterFirstDrainingLabel.Size = new System.Drawing.Size(86, 13); + this.afterFirstDrainingLabel.TabIndex = 36; + this.afterFirstDrainingLabel.Text = "After 1st draining"; + // // BalanceCfgCtrl // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.afterFirstDrainingComboBox); + this.Controls.Add(this.afterFirstDrainingLabel); this.Controls.Add(this.unitsComboBox); this.Controls.Add(this.unitsLabel); this.Controls.Add(this.formatTextBox); @@ -458,5 +480,7 @@ namespace TBF.BenchControl.MettlerToledo.Standard private System.Windows.Forms.Label unitsLabel; private System.Windows.Forms.TextBox formatTextBox; private System.Windows.Forms.Label formatLabel; + private System.Windows.Forms.ComboBox afterFirstDrainingComboBox; + private System.Windows.Forms.Label afterFirstDrainingLabel; } } diff --git a/TBF/BenchControl/MettlerToledo/Standard/BalanceCfgCtrl.cs b/TBF/BenchControl/MettlerToledo/Standard/BalanceCfgCtrl.cs index 4f90568e3..e8411e0f0 100644 --- a/TBF/BenchControl/MettlerToledo/Standard/BalanceCfgCtrl.cs +++ b/TBF/BenchControl/MettlerToledo/Standard/BalanceCfgCtrl.cs @@ -1,5 +1,5 @@ /// -/// Copyright (c) 2013-2019 Sensus Slovensko a.s. +/// Copyright (c) 2013-2021 Sensus Slovensko a.s. /// using System; using System.Windows.Forms; @@ -80,6 +80,11 @@ namespace TBF.BenchControl.MettlerToledo.Standard { InitializeComponent(); + for (ActionA1D a = 0; a < ActionA1D.Count; a++) + { + afterFirstDrainingComboBox.Items.Add(a.ToString()); + } + parityComboBox.Items.Add(Parity.None.ToString()); parityComboBox.Items.Add(Parity.Even.ToString()); parityComboBox.Items.Add(Parity.Odd.ToString()); @@ -143,6 +148,7 @@ namespace TBF.BenchControl.MettlerToledo.Standard evaporationComboBox.Text = string.IsNullOrEmpty(config.Evaporation) ? "---" : config.Evaporation; drainValveComboBox.Text = string.IsNullOrEmpty(config.DrainValve) ? "---" : config.DrainValve; drainTimeTextBox.Text = config.DrainTimeSec.ToString(); + afterFirstDrainingComboBox.Text = config.ActionAfter1stDraining.ToString(); comPortNrTextBox.Text = config.ComPortNr.ToString(); baudRateTextBox.Text = config.BaudRate.ToString(); @@ -165,6 +171,7 @@ namespace TBF.BenchControl.MettlerToledo.Standard evaporationComboBox.Enabled = true; drainValveComboBox.Enabled = true; drainTimeTextBox.Enabled = true; + afterFirstDrainingComboBox.Enabled = true; comPortNrTextBox.Enabled = true; baudRateTextBox.Enabled = true; @@ -228,6 +235,11 @@ namespace TBF.BenchControl.MettlerToledo.Standard flags |= CfgUpdateFlags.Error; message += Environment.NewLine + "'Tank drain time' should be between 1 and 999 sec"; } + if (!afterFirstDrainingComboBox.Items.Contains(afterFirstDrainingComboBox.Text)) + { + flags |= CfgUpdateFlags.Error; + message += Environment.NewLine + "Invalid 'Avter 1st draining'"; + } if (!unitsComboBox.Items.Contains(unitsComboBox.Text)) { flags |= CfgUpdateFlags.Error; @@ -250,6 +262,14 @@ namespace TBF.BenchControl.MettlerToledo.Standard config.Evaporation = evaporationComboBox.Text.Equals("---") ? string.Empty : evaporationComboBox.Text; config.DrainTimeSec = int.Parse(drainTimeTextBox.Text); config.DrainValve = drainValveComboBox.Text.Equals("---") ? string.Empty : drainValveComboBox.Text; + for (ActionA1D a = 0; a < ActionA1D.Count; a++) + { + if (afterFirstDrainingComboBox.Text == a.ToString()) + { + config.ActionAfter1stDraining = a; + break; + } + } config.ComPortNr = int.Parse(comPortNrTextBox.Text); config.BaudRate = int.Parse(baudRateTextBox.Text); diff --git a/TBF/BenchControl/MettlerToledo/Standard/BalanceDev.cs b/TBF/BenchControl/MettlerToledo/Standard/BalanceDev.cs index 1386327fb..3f1c53da2 100644 --- a/TBF/BenchControl/MettlerToledo/Standard/BalanceDev.cs +++ b/TBF/BenchControl/MettlerToledo/Standard/BalanceDev.cs @@ -1,5 +1,5 @@ /// -/// Copyright (c) 2013-2018 Sensus Slovensko a.s. +/// Copyright (c) 2013-2021 Sensus Slovensko a.s. /// using System; using System.Collections.Generic; @@ -265,21 +265,11 @@ namespace TBF.BenchControl.MettlerToledo.Standard 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 SendSetUnitsCmd(Units unit) + public void SendSetUnitsCmd(Config.Unit unit) { if (balanceCfg.DebugLevel == DebugMode.Simulate) return; @@ -293,27 +283,28 @@ namespace TBF.BenchControl.MettlerToledo.Standard stringBuilder.Clear(); switch (unit) { - case Units.g: + case Config.Unit.g: log.InfoFormat("{0} - SetUnits({1}) - \"U g\\r\\n\"", Name, unit); serialPort.Write("U g\r\n"); break; - case Units.kg: - log.InfoFormat("{0} - SetUnits({1}) - \"U kg\\r\\n\"", Name, unit); - serialPort.Write("U kg\r\n"); - break; - case Units.t: + case Config.Unit.t: log.InfoFormat("{0} - SetUnits({1}) - \"U t\\r\\n\"", Name, unit); serialPort.Write("U t\r\n"); break; - case Units.lb: + case Config.Unit.lb: log.InfoFormat("{0} - SetUnits({1}) - \"U lb\\r\\n\"", Name, unit); serialPort.Write("U lb\r\n"); break; - case Units.oz: + case Config.Unit.oz: log.InfoFormat("{0} - SetUnits({1}) - \"U oz\\r\\n\"", Name, unit); serialPort.Write("U oz\r\n"); break; - } + case Config.Unit.kg: + default: + log.InfoFormat("{0} - SetUnits({1}) - \"U kg\\r\\n\"", Name, unit); + serialPort.Write("U kg\r\n"); + break; + } } /// @@ -376,9 +367,9 @@ namespace TBF.BenchControl.MettlerToledo.Standard received = tmp; } - string[] fields = received.Split(new char[] { ' ' }); + string[] field = received.Split(new char[] { ' ' }); - if (fields.Length == 1 && fields[0].Equals("ZA")) /// Zero when stable + if (field.Length == 1 && field[0] == "ZA") /// Zero when stable { mass = 0; Masses[balanceNr] = mass; @@ -386,16 +377,16 @@ namespace TBF.BenchControl.MettlerToledo.Standard log.InfoFormat("{0} - Balance response = \"{1}\"", Name, received); return; } - else if (fields.Length < 2) + else if (field.Length < 2) { msrmntState = MsrmntState.Failed; log.WarnFormat("{0} - Balance response = \"{1}\", Unexpected error !!!", Name, received); return; } - if (fields[0].Equals("Z")) /// Zero when stable + if (field[0] == "Z") /// Zero when stable { - if (fields.Length == 2 && fields[1].Equals("A")) + if (field.Length == 2 && field[1] == "A") { mass = 0; Masses[balanceNr] = mass; @@ -409,33 +400,31 @@ namespace TBF.BenchControl.MettlerToledo.Standard log.WarnFormat("{0} - Balance response = \"{1}\", error !!!", Name, received); } } - else if (fields[0].Equals("S")) /// Stable mass: field[1] = field[2] = "kg" + else if (field[0] == "S") /// Stable mass: field[1] = field[2] = "kg" { - if (fields.Length == 3 && - double.TryParse(fields[1], + if (field.Length == 3 && + double.TryParse(field[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; + mass = Config.Units.ConvertFrom(ParseUnit(field[2]), mass); Masses[balanceNr] = mass; msrmntState = MsrmntState.Valid; log.InfoFormat("{0} - Balance response = \"{1}\", Mass = {2}", Name, received, mass); } - else if (fields.Length == 4 && (fields[1].Equals("S") || fields[1].Equals("D")) && - double.TryParse(fields[2], + else if (field.Length == 4 && (field[1] == "S" || field[1] == "D") && + double.TryParse(field[2], NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture, out mass)) { - if (fields[3].Equals("g")) mass /= 1000.0f; - if (fields[3].Equals("t")) mass *= 1000.0f; + mass = Config.Units.ConvertFrom(ParseUnit(field[3]), mass); Masses[balanceNr] = mass; msrmntState = MsrmntState.Valid; log.InfoFormat("{0} - Balance response = \"{1}\", Mass = {2}", Name, received, mass); } - else if (fields.Length == 2 && fields[1].Equals("-")) + else if (field.Length == 2 && field[1] == "-") { mass = 0; Masses[balanceNr] = mass; @@ -446,25 +435,24 @@ namespace TBF.BenchControl.MettlerToledo.Standard { msrmntState = MsrmntState.Failed; log.WarnFormat("{0} Balance response = \"{1}\", Overload or and unexpected error !!!", Name, received); - bool b = double.TryParse(fields[1], NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture, out mass); + bool b = double.TryParse(field[1], NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture, out mass); } } - else if (fields[0].Equals("SD")) /// Dynamic mass: field[1] = field[2] = "kg" + else if (field[0] == "SD") /// Dynamic mass: field[1] = field[2] = "kg" { - if (fields.Length >= 3 && - double.TryParse(fields[1], + if (field.Length >= 3 && + double.TryParse(field[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; + mass = Config.Units.ConvertFrom(ParseUnit(field[2]), mass); Masses[balanceNr] = mass; msrmntState = MsrmntState.Valid; log.InfoFormat("{0} - Balance response = \"{1}\", Mass = {2}", Name, received, mass); } - else if (fields.Length == 2 && fields[1].Equals("-")) + else if (field.Length == 2 && field[1] == "-") { mass = 0; Masses[balanceNr] = mass; @@ -475,21 +463,20 @@ namespace TBF.BenchControl.MettlerToledo.Standard { msrmntState = MsrmntState.Failed; log.WarnFormat("{0} - Balance response = \"{1}\", Overload or and unexpected error !!!", Name, received); - bool b = double.TryParse(fields[1], NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture, out mass); + bool b = double.TryParse(field[1], NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture, out mass); } } - else if (fields[0].Equals("TB")) /// Taring + else if (field[0] == "TB") /// Taring { - if (fields.Length >= 3 && - double.TryParse(fields[1], + if (field.Length >= 3 && + double.TryParse(field[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; + mass = Config.Units.ConvertFrom(ParseUnit(field[2]), mass); + msrmntState = MsrmntState.Valid; log.InfoFormat("{0} - Balance response = \"{1}\", Tara = {2}", Name, received, mass); } else @@ -498,16 +485,15 @@ namespace TBF.BenchControl.MettlerToledo.Standard log.WarnFormat("{0} - Balance response = \"{1}\", Overload or and unexpected error !!!", Name, received); } } - else if (fields[0].Equals("T")) /// Taring + else if (field[0] == "T") /// Taring { - if (fields.Length >= 4 && fields[1].Equals("S") && - double.TryParse(fields[2], + if (field.Length >= 4 && field[1] == "S" && + double.TryParse(field[2], NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture, out mass)) { - if (fields[3].Equals("g")) mass /= 1000.0f; - if (fields[3].Equals("t")) mass *= 1000.0f; + mass = Config.Units.ConvertFrom(ParseUnit(field[3]), mass); msrmntState = MsrmntState.Valid; log.InfoFormat("{0} - Balance response = \"{1}\", Tara = {2}", Name, received, mass); } @@ -554,7 +540,16 @@ namespace TBF.BenchControl.MettlerToledo.Standard /// ZeroOp reference public IOperation ZeroOp() { - return new ZeroOp(this); + switch (balanceCfg.ActionAfter1stDraining) + { + case ActionA1D.Zero: + return new ZeroOp(this); + case ActionA1D.Tara: + DoubleBox dummy = new DoubleBox(); + return new TaringOp(this, ref dummy); + default: + return null; + } } /// @@ -599,5 +594,20 @@ namespace TBF.BenchControl.MettlerToledo.Standard { return null; } + + /// + /// Parse a string representing mass units. + /// Defaults to 'kg'in case unitStr not recognized. + /// + /// String: "kg", "g", "t", "lb" or "oz" expected + /// + protected Config.Unit ParseUnit(string unitStr) + { + if (unitStr == "g") return Config.Unit.g; + if (unitStr == "t") return Config.Unit.t; + if (unitStr == "lb") return Config.Unit.lb; + if (unitStr == "oz") return Config.Unit.oz; + return Config.Unit.kg; + } } } diff --git a/TBF/BenchControl/MettlerToledo/Standard/BalanceNewDev.cs b/TBF/BenchControl/MettlerToledo/Standard/BalanceNewDev.cs index 12575378a..8636587ca 100644 --- a/TBF/BenchControl/MettlerToledo/Standard/BalanceNewDev.cs +++ b/TBF/BenchControl/MettlerToledo/Standard/BalanceNewDev.cs @@ -1,5 +1,5 @@ /// -/// Copyright (c) 2013-2020 Sensus Slovensko a.s. +/// Copyright (c) 2013-2021 Sensus Slovensko a.s. /// using System; using System.Globalization; @@ -110,8 +110,8 @@ namespace TBF.BenchControl.MettlerToledo.Standard received = tmp; } - string[] fields = received.Substring(0, received.Length - 2).Split(new char[] { ' ' }); - if (fields.Length < 2) + string[] field = received.Substring(0, received.Length - 2).Split(new char[] { ' ' }); + if (field.Length < 2) { msrmntState = MsrmntState.Failed; log.WarnFormat("{0} - Balance response = {1}, Unexpected error !!!", Name, @@ -119,11 +119,11 @@ namespace TBF.BenchControl.MettlerToledo.Standard return; } - if (fields[0].Equals("I4")) /// Serial number + if (field[0] == "I4" || field[0] == "IA") /// Serial number { - if (fields.Length == 3 && fields[1].Equals("A") && fields[2].Length >= 3) + if (field.Length == 3 && field[1] == "A" && field[2].Length >= 3) { - serialNumber = fields[2].Substring(1, fields[2].Length - 2); + serialNumber = field[2].Substring(1, field[2].Length - 2); msrmntState = MsrmntState.Valid; log.WarnFormat("{0} - Balance response = {1}, s/n = {2}", Name, received.Replace("\r", "").Replace("\n", ""), serialNumber); @@ -135,9 +135,9 @@ namespace TBF.BenchControl.MettlerToledo.Standard received.Replace("\r", "").Replace("\n", "")); } } - else if (fields[0].Equals("Z")) /// Zero when stable + else if (field[0] == "Z") /// Zero when stable { - if (fields.Length == 2 && fields[1].Equals("A")) + if (field.Length == 2 && field[1] == "A") { mass = 0; Masses[balanceNr] = mass; @@ -152,20 +152,19 @@ namespace TBF.BenchControl.MettlerToledo.Standard received.Replace("\r", "").Replace("\n", "")); } } - else if (fields[0].Equals("S")) /// Stable (field[1] == "S") or dynamic (field[1] == "D") mass measurement + else if (field[0] == "S") /// Stable (field[1] == "S") or dynamic (field[1] == "D") mass measurement { - if (fields.Length == 4 && (fields[1].Equals("S") || fields[1].Equals("D")) && - double.TryParse(fields[2], NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign | NumberStyles.AllowLeadingWhite, + if (field.Length == 4 && (field[1] == "S" || field[1] == "D") && + double.TryParse(field[2], NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign | NumberStyles.AllowLeadingWhite, CultureInfo.InvariantCulture, out mass)) { - if (fields[3].Equals("g")) mass /= 1000.0f; - if (fields[3].Equals("t")) mass *= 1000.0f; + mass = Config.Units.ConvertFrom(ParseUnit(field[3]), mass); Masses[balanceNr] = mass; msrmntState = MsrmntState.Valid; log.InfoFormat("{0} - Balance response = {1}, Mass = {2}", Name, received.Replace("\r", "").Replace("\n", ""), mass); } - else if (fields.Length == 2 && fields[1].Equals("-")) + else if (field.Length == 2 && field[1] == "-") { //mass = 0; //Masses[balanceNr] = mass; @@ -173,7 +172,7 @@ namespace TBF.BenchControl.MettlerToledo.Standard log.InfoFormat("{0} - Balance response = {1}, Mass = {2}", Name, received.Replace("\r", "").Replace("\n", ""), mass); } - else if (fields.Length == 2 && fields[1].Equals("+")) + else if (field.Length == 2 && field[1] == "+") { //mass = Capacity; //Masses[balanceNr] = mass; @@ -181,7 +180,7 @@ namespace TBF.BenchControl.MettlerToledo.Standard log.InfoFormat("{0} - Balance response = {1}, Overload", Name, received.Replace("\r", "").Replace("\n", "")); } - else if (fields.Length >= 2 && fields[1].Equals("I")) + else if (field.Length >= 2 && field[1] == "I") { //mass = balanceCfg.Capacity; //Masses[balanceNr] = mass; @@ -196,19 +195,18 @@ namespace TBF.BenchControl.MettlerToledo.Standard received.Replace("\r", "").Replace("\n", "")); } } - else if (fields[0].Equals("T")) /// Taring + else if (field[0] == "T") /// Taring { - if (fields.Length == 4 && fields[1].Equals("S") && - double.TryParse(fields[2], NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign | NumberStyles.AllowLeadingWhite, + if (field.Length == 4 && field[1] == "S" && + double.TryParse(field[2], NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign | NumberStyles.AllowLeadingWhite, CultureInfo.InvariantCulture, out mass)) { - if (fields[3].Equals("g")) mass /= 1000.0f; - if (fields[3].Equals("t")) mass *= 1000.0f; + mass = Config.Units.ConvertFrom(ParseUnit(field[3]), mass); msrmntState = MsrmntState.Valid; log.WarnFormat("{0} - Balance response = {1}, Mass = {2}", Name, received.Replace("\r", "").Replace("\n", ""), mass); } - else if (fields.Length >= 2 && fields[1].Equals("I")) + else if (field.Length >= 2 && field[1] == "I") { mass = mass = balanceCfg.Capacity; msrmntState = MsrmntState.Overload; @@ -222,9 +220,9 @@ namespace TBF.BenchControl.MettlerToledo.Standard received.Replace("\r", "").Replace("\n", "")); } } - else if (fields[0].Equals("U")) + else if (field[0] == "U") { - if (fields.Length == 2 && fields[1].Equals("A")) + if (field.Length == 2 && field[1] == "A") { msrmntState = MsrmntState.Valid; log.InfoFormat("{0} - Balance response = \"{1}\"", Name, @@ -237,9 +235,9 @@ namespace TBF.BenchControl.MettlerToledo.Standard received.Replace("\r", "").Replace("\n", "")); } } - else if (fields[0].Equals("SI")) /// "SI I" received in case of overload -> empty the tank + else if (field[0] == "SI") /// "SI I" received in case of overload -> empty the tank { - if (fields.Length >= 2 && fields[1].Equals("I")) + if (field.Length >= 2 && field[1] == "I") { mass = balanceCfg.Capacity; Masses[balanceNr] = mass; @@ -268,7 +266,7 @@ namespace TBF.BenchControl.MettlerToledo.Standard /// /// /// SetUnitsOp instance reference casted to IOperaton - public IOperation SetUnitsOp(Units units) + public IOperation SetUnitsOp(Config.Unit units) { return new SetUnitsOp(this, units); } diff --git a/TBF/BenchControl/MettlerToledo/Standard/BalanceOld.cs b/TBF/BenchControl/MettlerToledo/Standard/BalanceOld.cs index d8d8765d3..bf223c6e0 100644 --- a/TBF/BenchControl/MettlerToledo/Standard/BalanceOld.cs +++ b/TBF/BenchControl/MettlerToledo/Standard/BalanceOld.cs @@ -1,5 +1,5 @@ /// -/// Copyright (c) 2016-2020 Sensus Slovensko a.s. +/// Copyright (c) 2016-2021 Sensus Slovensko a.s. /// using System; using System.Collections.Generic; @@ -92,17 +92,17 @@ namespace TBF.BenchControl.MettlerToledo.Standard received = tmp; } - string[] fields = received.Substring(0, received.Length - 2).Split(new char[] { ' ' }); - if (fields.Length < 2) + string[] field = received.Substring(0, received.Length - 2).Split(new char[] { ' ' }); + if (field.Length < 2) { msrmntState = MsrmntState.Failed; log.WarnFormat("{0} - Balance response = {1}, Unexpected error !!!", Name, received.Replace("\r", "").Replace("\n", "")); return; } - else if (fields[0].Equals("Z")) /// Zero when stable + else if (field[0] == "Z") /// Zero when stable { - if (fields.Length == 2 && fields[1].Equals("A")) + if (field.Length == 2 && field[1] == "A") { mass = 0; Masses[balanceNr] = mass; @@ -117,31 +117,29 @@ namespace TBF.BenchControl.MettlerToledo.Standard received.Replace("\r", "").Replace("\n", "")); } } - else if (fields[0].Equals("S")) /// Stable (field[1] == "S") or dynamic (field[1] == "D") mass measurement + else if (field[0] == "S") /// Stable (field[1] == "S") or dynamic (field[1] == "D") mass measurement { - if (fields.Length == 4 && fields[1].Equals("S") && - double.TryParse(fields[2], NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign | NumberStyles.AllowLeadingWhite, + if (field.Length == 4 && field[1] == "S" && + double.TryParse(field[2], NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign | NumberStyles.AllowLeadingWhite, CultureInfo.InvariantCulture, out mass)) { - if (fields[3].Equals("g")) mass /= 1000.0f; - if (fields[3].Equals("t")) mass *= 1000.0f; + mass = Config.Units.ConvertFrom(ParseUnit(field[3]), mass); Masses[balanceNr] = mass; msrmntState = MsrmntState.Valid; log.InfoFormat("{0} - Balance response = {1}, Mass = {2}", Name, received.Replace("\r", "").Replace("\n", ""), mass); } - else if (fields.Length == 4 && fields[1].Equals("D") && - double.TryParse(fields[2], NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign | NumberStyles.AllowLeadingWhite, + else if (field.Length == 4 && field[1] == "D" && + double.TryParse(field[2], NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign | NumberStyles.AllowLeadingWhite, CultureInfo.InvariantCulture, out mass)) { - if (fields[3].Equals("g")) mass /= 1000.0f; - if (fields[3].Equals("t")) mass *= 1000.0f; + mass = Config.Units.ConvertFrom(ParseUnit(field[3]), mass); Masses[balanceNr] = mass; msrmntState = MsrmntState.Valid; log.InfoFormat("{0} - Balance response = {1}, Mass = {2}", Name, received.Replace("\r", "").Replace("\n", ""), mass); } - else if (fields.Length == 2 && fields[1].Equals("-")) + else if (field.Length == 2 && field[1] == "-") { mass = 0; Masses[balanceNr] = mass; @@ -149,7 +147,7 @@ namespace TBF.BenchControl.MettlerToledo.Standard log.InfoFormat("{0} - Balance response = {1}, Mass = {2}", Name, received.Replace("\r", "").Replace("\n", ""), mass); } - else if (fields.Length == 2 && fields[1].Equals("+")) + else if (field.Length == 2 && field[1] == "+") { mass = Capacity; Masses[balanceNr] = mass; @@ -157,7 +155,7 @@ namespace TBF.BenchControl.MettlerToledo.Standard log.InfoFormat("{0} - Balance response = {1}, Overload", Name, received.Replace("\r", "").Replace("\n", "")); } - else if (fields.Length >= 2 && fields[1].Equals("I")) + else if (field.Length >= 2 && field[1] == "I") { mass = balanceCfg.Capacity; Masses[balanceNr] = mass; @@ -172,19 +170,18 @@ namespace TBF.BenchControl.MettlerToledo.Standard received.Replace("\r", "").Replace("\n", "")); } } - else if (fields[0].Equals("T")) /// Taring + else if (field[0] == "T") /// Taring { - if (fields.Length == 4 && fields[1].Equals("S") && - double.TryParse(fields[2], NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign | NumberStyles.AllowLeadingWhite, + if (field.Length == 4 && field[1] == "S" && + double.TryParse(field[2], NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign | NumberStyles.AllowLeadingWhite, CultureInfo.InvariantCulture, out mass)) { - if (fields[3].Equals("g")) mass /= 1000.0f; - if (fields[3].Equals("t")) mass *= 1000.0f; + mass = Config.Units.ConvertFrom(ParseUnit(field[3]), mass); msrmntState = MsrmntState.Valid; log.InfoFormat("{0} - Balance response = {1}, Mass = {2}", Name, received.Replace("\r", "").Replace("\n", ""), mass); } - else if (fields.Length >= 2 && fields[1].Equals("I")) + else if (field.Length >= 2 && field[1] == "I") { mass = mass = balanceCfg.Capacity; msrmntState = MsrmntState.Overload; @@ -198,9 +195,9 @@ namespace TBF.BenchControl.MettlerToledo.Standard received.Replace("\r", "").Replace("\n", "")); } } - else if (fields[0].Equals("U")) + else if (field[0] == "U") { - if (fields.Length == 2 && fields[1].Equals("A")) + if (field.Length == 2 && field[1] == "A") { msrmntState = MsrmntState.Valid; log.InfoFormat("{0} - Balance response = \"{1}\"", Name, @@ -213,9 +210,9 @@ namespace TBF.BenchControl.MettlerToledo.Standard received.Replace("\r", "").Replace("\n", "")); } } - else if (fields[0].Equals("SI")) /// "SI I" received in case of overload -> empty the tank + else if (field[0] == "SI") /// "SI I" received in case of overload -> empty the tank { - if (fields.Length >= 2 && fields[1].Equals("I")) + if (field.Length >= 2 && field[1] == "I") { mass = balanceCfg.Capacity; Masses[balanceNr] = mass; @@ -234,7 +231,7 @@ namespace TBF.BenchControl.MettlerToledo.Standard /// /// /// SetUnitsOp instance reference casted to IOperaton - public IOperation SetUnitsOp(Units units) + public IOperation SetUnitsOp(Config.Unit units) { return new SetUnitsOp(this, units); } diff --git a/TBF/BenchControl/MettlerToledo/Standard/SetUnitsOp.cs b/TBF/BenchControl/MettlerToledo/Standard/SetUnitsOp.cs index dca688038..06a7d4d4e 100644 --- a/TBF/BenchControl/MettlerToledo/Standard/SetUnitsOp.cs +++ b/TBF/BenchControl/MettlerToledo/Standard/SetUnitsOp.cs @@ -1,5 +1,5 @@ /// -/// Copyright (c) 2013-2020 Sensus Slovensko a.s. +/// Copyright (c) 2013-2021 Sensus Slovensko a.s. /// using System; using System.Collections.Generic; @@ -16,7 +16,7 @@ namespace TBF.BenchControl.MettlerToledo.Standard /// Set by the constructor BalanceDev scale; - BalanceDev.Units units; + Config.Unit units; bool activityStarted; /// @@ -24,7 +24,7 @@ namespace TBF.BenchControl.MettlerToledo.Standard /// /// Balance device instance /// Reference to the serialNumber - public SetUnitsOp(BalanceDev scale, BalanceDev.Units units) + public SetUnitsOp(BalanceDev scale, Config.Unit units) { if (scale == null) throw new ArgumentNullException("balanceDev"); this.scale = scale;