diff --git a/Common/Hardware/WaterMeter/MechanicalMeter/FM2014/FM2014Config/FM2014Config.cs b/Common/Hardware/WaterMeter/MechanicalMeter/FM2014/FM2014Config/FM2014Config.cs index b9e667f2..692ea4e7 100644 --- a/Common/Hardware/WaterMeter/MechanicalMeter/FM2014/FM2014Config/FM2014Config.cs +++ b/Common/Hardware/WaterMeter/MechanicalMeter/FM2014/FM2014Config/FM2014Config.cs @@ -69,7 +69,9 @@ namespace Sensus.Common.Hardware.WaterMeter.MechanicalMeter.FM2014.FM2014Config configFile = Path.Combine(ProgramConfig.FM2014ConfigFileName); if (!File.Exists(configFile)) { - FM2014ComPort = null; + SerialPort = null; + Address = null; + TolerancePercent = null; return false; } } @@ -77,7 +79,9 @@ namespace Sensus.Common.Hardware.WaterMeter.MechanicalMeter.FM2014.FM2014Config using (var tr = new StreamReader(configFile)) { var fm2014Setup = JsonConvert.DeserializeObject(tr.ReadToEnd()); - FM2014ComPort = fm2014Setup.FM2014ComPort; + SerialPort = fm2014Setup.SerialPort; + Address = fm2014Setup.Address; + TolerancePercent = fm2014Setup.TolerancePercent; } return true; @@ -104,9 +108,19 @@ namespace Sensus.Common.Hardware.WaterMeter.MechanicalMeter.FM2014.FM2014Config } /// - /// Comport for SIRT interface with 433MHz radio frequency + /// Comport for the FM2014 /// - public String FM2014ComPort { get; set; } + public String SerialPort { get; set; } + + /// + /// Address of the FM2014 + /// + public Int32? Address { get; set; } + + /// + /// Address of the FM2014 + /// + public Int32? TolerancePercent { get; set; } } } diff --git a/Common/Hardware/WaterMeter/MechanicalMeter/FM2014/FM2014Core/FM2014.cs b/Common/Hardware/WaterMeter/MechanicalMeter/FM2014/FM2014Core/FM2014.cs index 4ed6bb62..48aadb16 100644 --- a/Common/Hardware/WaterMeter/MechanicalMeter/FM2014/FM2014Core/FM2014.cs +++ b/Common/Hardware/WaterMeter/MechanicalMeter/FM2014/FM2014Core/FM2014.cs @@ -49,13 +49,6 @@ namespace Sensus.Common.Hardware.WaterMeter.MechanicalMeter.FM2014.FM2014Core { #region properties - /// - public SerialPort SerialPort - { - get; - internal set; - } - /// /// Logger for raw data output /// @@ -71,6 +64,13 @@ namespace Sensus.Common.Hardware.WaterMeter.MechanicalMeter.FM2014.FM2014Core internal set; } + /// + public SerialPort SerialPort + { + get; + private set; + } + /// public String FullId { @@ -79,12 +79,54 @@ namespace Sensus.Common.Hardware.WaterMeter.MechanicalMeter.FM2014.FM2014Core } /// - public Int32 Address + public Int32? Address { get; set; } + /// + public Int32? TolerancePercent + { + get; + set; + } + + /// + public Boolean UseDampedTolerance + { + get; + private set; + } + + /// + public UInt16 RefPulsePerCm + { + get; + private set; + } + + /// + public UInt16 DutPulsePerCm + { + get; + private set; + } + + /// + public Single RefToDutScaleNorm + { + get; + private set; + } + + /// + public Byte Attenuation + { + get; + private set; + } + /// public Boolean IsLoggedOn { @@ -96,7 +138,7 @@ namespace Sensus.Common.Hardware.WaterMeter.MechanicalMeter.FM2014.FM2014Core public String FwVersion { get; - internal set; + private set; } #endregion @@ -135,9 +177,9 @@ namespace Sensus.Common.Hardware.WaterMeter.MechanicalMeter.FM2014.FM2014Core } SerialPort.Open(); - SerialPort.WriteLine($"**{Address}@\n"); - //Thread.Sleep(2000); - //FullId = SerialPort.ReadLine(); + SerialPort.WriteLine($"**{Address}@\r"); + Thread.Sleep(2000); + FullId = SerialPort.ReadLine(); if (!string.IsNullOrEmpty(FullId)) { var fields = FullId.Split('.'); diff --git a/Common/Hardware/WaterMeter/MechanicalMeter/FM2014/FM2014Core/IFM2014.cs b/Common/Hardware/WaterMeter/MechanicalMeter/FM2014/FM2014Core/IFM2014.cs index 3bca90fc..0483deea 100644 --- a/Common/Hardware/WaterMeter/MechanicalMeter/FM2014/FM2014Core/IFM2014.cs +++ b/Common/Hardware/WaterMeter/MechanicalMeter/FM2014/FM2014Core/IFM2014.cs @@ -77,10 +77,59 @@ namespace Sensus.Common.Hardware.WaterMeter.MechanicalMeter.FM2014.FM2014Core /// /// FM2014 address string /// - Int32 Address + Int32? Address + { + get; + } + + /// + /// Tolerance output of current loop in percent: + /// - hardware dependent 3% or 5% + /// + Int32? TolerancePercent + { + get; + } + + /// + /// Use the damped tolerance output from the FM2014 to stabilize this value + /// + Boolean UseDampedTolerance + { + get; + } + + /// + /// Reference pulses per cubic-meter + /// + UInt16 RefPulsePerCm + { + get; + } + + /// + /// Device under test pulses per cubic-meter + /// + UInt16 DutPulsePerCm + { + get; + } + + /// + /// Normalized scale REF to DUT pulses + /// + Single RefToDutScaleNorm + { + get; + } + + /// + /// Filter value to attenuate the velocity of + /// the current output on the tolerance display + /// + Byte Attenuation { get; - set; } /// diff --git a/MiniPrf/Ui/FrmMainMiniPrf.Designer.cs b/MiniPrf/Ui/FrmMainMiniPrf.Designer.cs index d2d82884..3494ac7b 100644 --- a/MiniPrf/Ui/FrmMainMiniPrf.Designer.cs +++ b/MiniPrf/Ui/FrmMainMiniPrf.Designer.cs @@ -31,12 +31,21 @@ this.components = new System.ComponentModel.Container(); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FrmMainMiniPrf)); this.gbxFM2014Setup = new System.Windows.Forms.GroupBox(); + this.lblSerialNumber = new System.Windows.Forms.Label(); + this.cbxFM2014TolerancePercent = new System.Windows.Forms.ComboBox(); + this.tbxFM2014SerialNumber = new System.Windows.Forms.TextBox(); + this.lblFM2014Tolerance = new System.Windows.Forms.Label(); + this.cbxFM2014Address = new System.Windows.Forms.ComboBox(); + this.lblFM2014Address = new System.Windows.Forms.Label(); + this.lblFwVersion = new System.Windows.Forms.Label(); this.btnConnect = new System.Windows.Forms.Button(); this.cbxFM2014ComPort = new System.Windows.Forms.ComboBox(); this.lblSerialPort = new System.Windows.Forms.Label(); this.lblConnectFM2014 = new System.Windows.Forms.Label(); this.tbxFullId = new System.Windows.Forms.TextBox(); + this.tbxApplicationFwVersion = new System.Windows.Forms.TextBox(); this.gbxRegulationSetup = new System.Windows.Forms.GroupBox(); + this.cbxAttenuation = new System.Windows.Forms.ComboBox(); this.lblRefPulsePerVolume = new System.Windows.Forms.Label(); this.lblDutPulsePerVolume = new System.Windows.Forms.Label(); this.lblAttenuation = new System.Windows.Forms.Label(); @@ -46,36 +55,27 @@ this.tbxScaleRefToDut = new System.Windows.Forms.TextBox(); this.lblUpdateTime = new System.Windows.Forms.Label(); this.tmrProgressUpdate = new System.Windows.Forms.Timer(this.components); - this.lblFwVersion = new System.Windows.Forms.Label(); - this.lblSerialNumber = new System.Windows.Forms.Label(); - this.tbxFM2014SerialNumber = new System.Windows.Forms.TextBox(); - this.tbxFwVersion = new System.Windows.Forms.TextBox(); this.label9 = new System.Windows.Forms.Label(); this.lblWaitingForMeterResponse = new System.Windows.Forms.Label(); this.pictureBox1 = new System.Windows.Forms.PictureBox(); this.lblFwUpdateInfo = new System.Windows.Forms.Label(); this.barSingleProgressUpdate = new System.Windows.Forms.ProgressBar(); this.lblActualProcess = new System.Windows.Forms.Label(); - this.cbxFM2014Address = new System.Windows.Forms.ComboBox(); - this.lblFM2014Address = new System.Windows.Forms.Label(); - this.cbxFM2014Tolerance = new System.Windows.Forms.ComboBox(); - this.lblFM2014Tolerance = new System.Windows.Forms.Label(); - this.cbxAttenuation = new System.Windows.Forms.ComboBox(); this.btnRegulation = new System.Windows.Forms.Button(); this.grpRefCalibration = new System.Windows.Forms.GroupBox(); - this.gbxRegulation = new System.Windows.Forms.GroupBox(); - this.btnCalibration = new System.Windows.Forms.Button(); - this.lblMeasuredRefPulses = new System.Windows.Forms.Label(); - this.tbxMeasuredRefPulses = new System.Windows.Forms.TextBox(); - this.lblWeightScaleMass = new System.Windows.Forms.Label(); - this.tbxWeightScaleMass = new System.Windows.Forms.TextBox(); this.lblPulseVolumeCmRelation = new System.Windows.Forms.Label(); this.tbxPulseVolumeCmRelation = new System.Windows.Forms.TextBox(); - this.lblActualFlowRateCmPerHour = new System.Windows.Forms.Label(); - this.tbxActualFlowRateCmPerHour = new System.Windows.Forms.TextBox(); + this.lblWeightScaleMass = new System.Windows.Forms.Label(); + this.tbxWeightScaleMass = new System.Windows.Forms.TextBox(); + this.lblMeasuredRefPulses = new System.Windows.Forms.Label(); + this.tbxMeasuredRefPulses = new System.Windows.Forms.TextBox(); + this.btnCalibration = new System.Windows.Forms.Button(); + this.gbxRegulation = new System.Windows.Forms.GroupBox(); + this.ckbxUseDampedTolerance = new System.Windows.Forms.CheckBox(); this.lblTolerance = new System.Windows.Forms.Label(); this.tbxTolerance = new System.Windows.Forms.TextBox(); - this.ckbxUseDampedTolerance = new System.Windows.Forms.CheckBox(); + this.lblActualFlowRateCmPerHour = new System.Windows.Forms.Label(); + this.tbxActualFlowRateCmPerHour = new System.Windows.Forms.TextBox(); this.gbxFM2014Setup.SuspendLayout(); this.gbxRegulationSetup.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); @@ -86,7 +86,7 @@ // gbxFM2014Setup // this.gbxFM2014Setup.Controls.Add(this.lblSerialNumber); - this.gbxFM2014Setup.Controls.Add(this.cbxFM2014Tolerance); + this.gbxFM2014Setup.Controls.Add(this.cbxFM2014TolerancePercent); this.gbxFM2014Setup.Controls.Add(this.tbxFM2014SerialNumber); this.gbxFM2014Setup.Controls.Add(this.lblFM2014Tolerance); this.gbxFM2014Setup.Controls.Add(this.cbxFM2014Address); @@ -97,7 +97,7 @@ this.gbxFM2014Setup.Controls.Add(this.lblSerialPort); this.gbxFM2014Setup.Controls.Add(this.lblConnectFM2014); this.gbxFM2014Setup.Controls.Add(this.tbxFullId); - this.gbxFM2014Setup.Controls.Add(this.tbxFwVersion); + this.gbxFM2014Setup.Controls.Add(this.tbxApplicationFwVersion); this.gbxFM2014Setup.Location = new System.Drawing.Point(8, 6); this.gbxFM2014Setup.Name = "gbxFM2014Setup"; this.gbxFM2014Setup.Size = new System.Drawing.Size(275, 210); @@ -105,6 +105,92 @@ this.gbxFM2014Setup.TabStop = false; this.gbxFM2014Setup.Text = "FM2014"; // + // lblSerialNumber + // + this.lblSerialNumber.AutoSize = true; + this.lblSerialNumber.Location = new System.Drawing.Point(10, 78); + this.lblSerialNumber.Name = "lblSerialNumber"; + this.lblSerialNumber.Size = new System.Drawing.Size(76, 13); + this.lblSerialNumber.TabIndex = 27; + this.lblSerialNumber.Text = "Serial Number:"; + // + // cbxFM2014TolerancePercent + // + this.cbxFM2014TolerancePercent.FormattingEnabled = true; + this.cbxFM2014TolerancePercent.Items.AddRange(new object[] { + "3", + "5"}); + this.cbxFM2014TolerancePercent.Location = new System.Drawing.Point(140, 150); + this.cbxFM2014TolerancePercent.Name = "cbxFM2014TolerancePercent"; + this.cbxFM2014TolerancePercent.Size = new System.Drawing.Size(60, 21); + this.cbxFM2014TolerancePercent.TabIndex = 35; + this.cbxFM2014TolerancePercent.Text = "3"; + this.cbxFM2014TolerancePercent.SelectedValueChanged += new System.EventHandler(this.cbxFM2014ComPort_SelectedValueChanged); + // + // tbxFM2014SerialNumber + // + this.tbxFM2014SerialNumber.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.tbxFM2014SerialNumber.Location = new System.Drawing.Point(140, 75); + this.tbxFM2014SerialNumber.Name = "tbxFM2014SerialNumber"; + this.tbxFM2014SerialNumber.ReadOnly = true; + this.tbxFM2014SerialNumber.Size = new System.Drawing.Size(120, 20); + this.tbxFM2014SerialNumber.TabIndex = 29; + // + // lblFM2014Tolerance + // + this.lblFM2014Tolerance.AutoSize = true; + this.lblFM2014Tolerance.Location = new System.Drawing.Point(10, 153); + this.lblFM2014Tolerance.Name = "lblFM2014Tolerance"; + this.lblFM2014Tolerance.Size = new System.Drawing.Size(75, 13); + this.lblFM2014Tolerance.TabIndex = 36; + this.lblFM2014Tolerance.Text = "Tolerance [%]:"; + // + // cbxFM2014Address + // + this.cbxFM2014Address.FormattingEnabled = true; + this.cbxFM2014Address.Items.AddRange(new object[] { + "1", + "2", + "3", + "4", + "5", + "6", + "7", + "8", + "9", + "10", + "11", + "12", + "13", + "14", + "15", + "16", + "22"}); + this.cbxFM2014Address.Location = new System.Drawing.Point(140, 125); + this.cbxFM2014Address.Name = "cbxFM2014Address"; + this.cbxFM2014Address.Size = new System.Drawing.Size(60, 21); + this.cbxFM2014Address.TabIndex = 33; + this.cbxFM2014Address.Text = "1"; + this.cbxFM2014Address.SelectedValueChanged += new System.EventHandler(this.cbxFM2014ComPort_SelectedValueChanged); + // + // lblFM2014Address + // + this.lblFM2014Address.AutoSize = true; + this.lblFM2014Address.Location = new System.Drawing.Point(10, 128); + this.lblFM2014Address.Name = "lblFM2014Address"; + this.lblFM2014Address.Size = new System.Drawing.Size(48, 13); + this.lblFM2014Address.TabIndex = 34; + this.lblFM2014Address.Text = "Address:"; + // + // lblFwVersion + // + this.lblFwVersion.AutoSize = true; + this.lblFwVersion.Location = new System.Drawing.Point(10, 52); + this.lblFwVersion.Name = "lblFwVersion"; + this.lblFwVersion.Size = new System.Drawing.Size(107, 13); + this.lblFwVersion.TabIndex = 25; + this.lblFwVersion.Text = "Application Firmware:"; + // // btnConnect // this.btnConnect.Location = new System.Drawing.Point(140, 175); @@ -123,7 +209,7 @@ this.cbxFM2014ComPort.Size = new System.Drawing.Size(60, 21); this.cbxFM2014ComPort.TabIndex = 5; this.cbxFM2014ComPort.Text = "NA"; - this.cbxFM2014ComPort.SelectedIndexChanged += new System.EventHandler(this.cbxFM2014ComPort_SelectedIndexChanged); + this.cbxFM2014ComPort.SelectedValueChanged += new System.EventHandler(this.cbxFM2014ComPort_SelectedValueChanged); // // lblSerialPort // @@ -152,6 +238,15 @@ this.tbxFullId.Size = new System.Drawing.Size(120, 20); this.tbxFullId.TabIndex = 32; // + // tbxApplicationFwVersion + // + this.tbxApplicationFwVersion.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.tbxApplicationFwVersion.Location = new System.Drawing.Point(140, 50); + this.tbxApplicationFwVersion.Name = "tbxApplicationFwVersion"; + this.tbxApplicationFwVersion.ReadOnly = true; + this.tbxApplicationFwVersion.Size = new System.Drawing.Size(120, 20); + this.tbxApplicationFwVersion.TabIndex = 31; + // // gbxRegulationSetup // this.gbxRegulationSetup.Controls.Add(this.cbxAttenuation); @@ -169,6 +264,25 @@ this.gbxRegulationSetup.TabStop = false; this.gbxRegulationSetup.Text = "Regulation Setup"; // + // cbxAttenuation + // + this.cbxAttenuation.FormattingEnabled = true; + this.cbxAttenuation.Items.AddRange(new object[] { + "1", + "2", + "3", + "4", + "5", + "6", + "7", + "8", + "9"}); + this.cbxAttenuation.Location = new System.Drawing.Point(140, 100); + this.cbxAttenuation.Name = "cbxAttenuation"; + this.cbxAttenuation.Size = new System.Drawing.Size(60, 21); + this.cbxAttenuation.TabIndex = 69; + this.cbxAttenuation.Text = "3"; + // // lblRefPulsePerVolume // this.lblRefPulsePerVolume.AutoSize = true; @@ -246,42 +360,6 @@ this.tmrProgressUpdate.Interval = 200; this.tmrProgressUpdate.Tick += new System.EventHandler(this.tmrProgressUpdate_Tick); // - // lblFwVersion - // - this.lblFwVersion.AutoSize = true; - this.lblFwVersion.Location = new System.Drawing.Point(10, 52); - this.lblFwVersion.Name = "lblFwVersion"; - this.lblFwVersion.Size = new System.Drawing.Size(107, 13); - this.lblFwVersion.TabIndex = 25; - this.lblFwVersion.Text = "Application Firmware:"; - // - // lblSerialNumber - // - this.lblSerialNumber.AutoSize = true; - this.lblSerialNumber.Location = new System.Drawing.Point(10, 78); - this.lblSerialNumber.Name = "lblSerialNumber"; - this.lblSerialNumber.Size = new System.Drawing.Size(76, 13); - this.lblSerialNumber.TabIndex = 27; - this.lblSerialNumber.Text = "Serial Number:"; - // - // tbxFM2014SerialNumber - // - this.tbxFM2014SerialNumber.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.tbxFM2014SerialNumber.Location = new System.Drawing.Point(140, 75); - this.tbxFM2014SerialNumber.Name = "tbxFM2014SerialNumber"; - this.tbxFM2014SerialNumber.ReadOnly = true; - this.tbxFM2014SerialNumber.Size = new System.Drawing.Size(120, 20); - this.tbxFM2014SerialNumber.TabIndex = 29; - // - // tbxFwVersion - // - this.tbxFwVersion.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.tbxFwVersion.Location = new System.Drawing.Point(140, 50); - this.tbxFwVersion.Name = "tbxFwVersion"; - this.tbxFwVersion.ReadOnly = true; - this.tbxFwVersion.Size = new System.Drawing.Size(120, 20); - this.tbxFwVersion.TabIndex = 31; - // // label9 // this.label9.AutoSize = true; @@ -337,82 +415,6 @@ this.lblActualProcess.TabIndex = 74; this.lblActualProcess.Text = "Process status"; // - // cbxFM2014Address - // - this.cbxFM2014Address.FormattingEnabled = true; - this.cbxFM2014Address.Items.AddRange(new object[] { - "1", - "2", - "3", - "4", - "5", - "6", - "7", - "8", - "9", - "10", - "11", - "12", - "13", - "14", - "15", - "16", - "22"}); - this.cbxFM2014Address.Location = new System.Drawing.Point(140, 125); - this.cbxFM2014Address.Name = "cbxFM2014Address"; - this.cbxFM2014Address.Size = new System.Drawing.Size(60, 21); - this.cbxFM2014Address.TabIndex = 33; - this.cbxFM2014Address.Text = "1"; - // - // lblFM2014Address - // - this.lblFM2014Address.AutoSize = true; - this.lblFM2014Address.Location = new System.Drawing.Point(10, 128); - this.lblFM2014Address.Name = "lblFM2014Address"; - this.lblFM2014Address.Size = new System.Drawing.Size(48, 13); - this.lblFM2014Address.TabIndex = 34; - this.lblFM2014Address.Text = "Address:"; - // - // cbxFM2014Tolerance - // - this.cbxFM2014Tolerance.FormattingEnabled = true; - this.cbxFM2014Tolerance.Items.AddRange(new object[] { - "3%", - "5%"}); - this.cbxFM2014Tolerance.Location = new System.Drawing.Point(140, 150); - this.cbxFM2014Tolerance.Name = "cbxFM2014Tolerance"; - this.cbxFM2014Tolerance.Size = new System.Drawing.Size(60, 21); - this.cbxFM2014Tolerance.TabIndex = 35; - this.cbxFM2014Tolerance.Text = "3%"; - // - // lblFM2014Tolerance - // - this.lblFM2014Tolerance.AutoSize = true; - this.lblFM2014Tolerance.Location = new System.Drawing.Point(10, 153); - this.lblFM2014Tolerance.Name = "lblFM2014Tolerance"; - this.lblFM2014Tolerance.Size = new System.Drawing.Size(58, 13); - this.lblFM2014Tolerance.TabIndex = 36; - this.lblFM2014Tolerance.Text = "Tolerance:"; - // - // cbxAttenuation - // - this.cbxAttenuation.FormattingEnabled = true; - this.cbxAttenuation.Items.AddRange(new object[] { - "1", - "2", - "3", - "4", - "5", - "6", - "7", - "8", - "9"}); - this.cbxAttenuation.Location = new System.Drawing.Point(140, 100); - this.cbxAttenuation.Name = "cbxAttenuation"; - this.cbxAttenuation.Size = new System.Drawing.Size(60, 21); - this.cbxAttenuation.TabIndex = 69; - this.cbxAttenuation.Text = "3"; - // // btnRegulation // this.btnRegulation.Location = new System.Drawing.Point(140, 126); @@ -438,47 +440,23 @@ this.grpRefCalibration.TabStop = false; this.grpRefCalibration.Text = "Manual REF Calibration"; // - // gbxRegulation + // lblPulseVolumeCmRelation // - this.gbxRegulation.Controls.Add(this.ckbxUseDampedTolerance); - this.gbxRegulation.Controls.Add(this.lblTolerance); - this.gbxRegulation.Controls.Add(this.tbxTolerance); - this.gbxRegulation.Controls.Add(this.lblActualFlowRateCmPerHour); - this.gbxRegulation.Controls.Add(this.tbxActualFlowRateCmPerHour); - this.gbxRegulation.Controls.Add(this.btnRegulation); - this.gbxRegulation.Location = new System.Drawing.Point(290, 222); - this.gbxRegulation.Name = "gbxRegulation"; - this.gbxRegulation.Size = new System.Drawing.Size(275, 161); - this.gbxRegulation.TabIndex = 84; - this.gbxRegulation.TabStop = false; - this.gbxRegulation.Text = "DUT to REF Regulation"; + this.lblPulseVolumeCmRelation.AutoSize = true; + this.lblPulseVolumeCmRelation.Location = new System.Drawing.Point(10, 78); + this.lblPulseVolumeCmRelation.Name = "lblPulseVolumeCmRelation"; + this.lblPulseVolumeCmRelation.Size = new System.Drawing.Size(86, 13); + this.lblPulseVolumeCmRelation.TabIndex = 72; + this.lblPulseVolumeCmRelation.Text = "REF [pulses/m³]:"; // - // btnCalibration + // tbxPulseVolumeCmRelation // - this.btnCalibration.Location = new System.Drawing.Point(138, 115); - this.btnCalibration.Name = "btnCalibration"; - this.btnCalibration.Size = new System.Drawing.Size(120, 25); - this.btnCalibration.TabIndex = 38; - this.btnCalibration.Text = "Start Calibration"; - this.btnCalibration.UseVisualStyleBackColor = true; - // - // lblMeasuredRefPulses - // - this.lblMeasuredRefPulses.AutoSize = true; - this.lblMeasuredRefPulses.Location = new System.Drawing.Point(10, 28); - this.lblMeasuredRefPulses.Name = "lblMeasuredRefPulses"; - this.lblMeasuredRefPulses.Size = new System.Drawing.Size(121, 13); - this.lblMeasuredRefPulses.TabIndex = 68; - this.lblMeasuredRefPulses.Text = "Measured REF [Pulses]:"; - // - // tbxMeasuredRefPulses - // - this.tbxMeasuredRefPulses.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.tbxMeasuredRefPulses.Location = new System.Drawing.Point(140, 25); - this.tbxMeasuredRefPulses.Name = "tbxMeasuredRefPulses"; - this.tbxMeasuredRefPulses.ReadOnly = true; - this.tbxMeasuredRefPulses.Size = new System.Drawing.Size(120, 20); - this.tbxMeasuredRefPulses.TabIndex = 69; + this.tbxPulseVolumeCmRelation.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.tbxPulseVolumeCmRelation.Location = new System.Drawing.Point(140, 75); + this.tbxPulseVolumeCmRelation.Name = "tbxPulseVolumeCmRelation"; + this.tbxPulseVolumeCmRelation.ReadOnly = true; + this.tbxPulseVolumeCmRelation.Size = new System.Drawing.Size(120, 20); + this.tbxPulseVolumeCmRelation.TabIndex = 73; // // lblWeightScaleMass // @@ -498,41 +476,58 @@ this.tbxWeightScaleMass.Size = new System.Drawing.Size(120, 20); this.tbxWeightScaleMass.TabIndex = 71; // - // lblPulseVolumeCmRelation + // lblMeasuredRefPulses // - this.lblPulseVolumeCmRelation.AutoSize = true; - this.lblPulseVolumeCmRelation.Location = new System.Drawing.Point(10, 78); - this.lblPulseVolumeCmRelation.Name = "lblPulseVolumeCmRelation"; - this.lblPulseVolumeCmRelation.Size = new System.Drawing.Size(86, 13); - this.lblPulseVolumeCmRelation.TabIndex = 72; - this.lblPulseVolumeCmRelation.Text = "REF [pulses/m³]:"; + this.lblMeasuredRefPulses.AutoSize = true; + this.lblMeasuredRefPulses.Location = new System.Drawing.Point(10, 28); + this.lblMeasuredRefPulses.Name = "lblMeasuredRefPulses"; + this.lblMeasuredRefPulses.Size = new System.Drawing.Size(121, 13); + this.lblMeasuredRefPulses.TabIndex = 68; + this.lblMeasuredRefPulses.Text = "Measured REF [Pulses]:"; // - // tbxPulseVolumeCmRelation + // tbxMeasuredRefPulses // - this.tbxPulseVolumeCmRelation.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.tbxPulseVolumeCmRelation.Location = new System.Drawing.Point(140, 75); - this.tbxPulseVolumeCmRelation.Name = "tbxPulseVolumeCmRelation"; - this.tbxPulseVolumeCmRelation.ReadOnly = true; - this.tbxPulseVolumeCmRelation.Size = new System.Drawing.Size(120, 20); - this.tbxPulseVolumeCmRelation.TabIndex = 73; + this.tbxMeasuredRefPulses.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.tbxMeasuredRefPulses.Location = new System.Drawing.Point(140, 25); + this.tbxMeasuredRefPulses.Name = "tbxMeasuredRefPulses"; + this.tbxMeasuredRefPulses.ReadOnly = true; + this.tbxMeasuredRefPulses.Size = new System.Drawing.Size(120, 20); + this.tbxMeasuredRefPulses.TabIndex = 69; // - // lblActualFlowRateCmPerHour + // btnCalibration // - this.lblActualFlowRateCmPerHour.AutoSize = true; - this.lblActualFlowRateCmPerHour.Location = new System.Drawing.Point(10, 28); - this.lblActualFlowRateCmPerHour.Name = "lblActualFlowRateCmPerHour"; - this.lblActualFlowRateCmPerHour.Size = new System.Drawing.Size(89, 13); - this.lblActualFlowRateCmPerHour.TabIndex = 74; - this.lblActualFlowRateCmPerHour.Text = "Flow Rate [m³/h]:"; + this.btnCalibration.Location = new System.Drawing.Point(138, 115); + this.btnCalibration.Name = "btnCalibration"; + this.btnCalibration.Size = new System.Drawing.Size(120, 25); + this.btnCalibration.TabIndex = 38; + this.btnCalibration.Text = "Start Calibration"; + this.btnCalibration.UseVisualStyleBackColor = true; // - // tbxActualFlowRateCmPerHour + // gbxRegulation // - this.tbxActualFlowRateCmPerHour.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.tbxActualFlowRateCmPerHour.Location = new System.Drawing.Point(140, 25); - this.tbxActualFlowRateCmPerHour.Name = "tbxActualFlowRateCmPerHour"; - this.tbxActualFlowRateCmPerHour.ReadOnly = true; - this.tbxActualFlowRateCmPerHour.Size = new System.Drawing.Size(120, 20); - this.tbxActualFlowRateCmPerHour.TabIndex = 75; + this.gbxRegulation.Controls.Add(this.ckbxUseDampedTolerance); + this.gbxRegulation.Controls.Add(this.lblTolerance); + this.gbxRegulation.Controls.Add(this.tbxTolerance); + this.gbxRegulation.Controls.Add(this.lblActualFlowRateCmPerHour); + this.gbxRegulation.Controls.Add(this.tbxActualFlowRateCmPerHour); + this.gbxRegulation.Controls.Add(this.btnRegulation); + this.gbxRegulation.Location = new System.Drawing.Point(290, 222); + this.gbxRegulation.Name = "gbxRegulation"; + this.gbxRegulation.Size = new System.Drawing.Size(275, 161); + this.gbxRegulation.TabIndex = 84; + this.gbxRegulation.TabStop = false; + this.gbxRegulation.Text = "DUT to REF Regulation"; + // + // ckbxUseDampedTolerance + // + this.ckbxUseDampedTolerance.AutoSize = true; + this.ckbxUseDampedTolerance.Location = new System.Drawing.Point(13, 78); + this.ckbxUseDampedTolerance.Name = "ckbxUseDampedTolerance"; + this.ckbxUseDampedTolerance.RightToLeft = System.Windows.Forms.RightToLeft.Yes; + this.ckbxUseDampedTolerance.Size = new System.Drawing.Size(117, 17); + this.ckbxUseDampedTolerance.TabIndex = 78; + this.ckbxUseDampedTolerance.Text = "Damped Tolerance"; + this.ckbxUseDampedTolerance.UseVisualStyleBackColor = true; // // lblTolerance // @@ -552,16 +547,23 @@ this.tbxTolerance.Size = new System.Drawing.Size(120, 20); this.tbxTolerance.TabIndex = 77; // - // ckbxUseDampedTolerance + // lblActualFlowRateCmPerHour // - this.ckbxUseDampedTolerance.AutoSize = true; - this.ckbxUseDampedTolerance.Location = new System.Drawing.Point(13, 78); - this.ckbxUseDampedTolerance.Name = "ckbxUseDampedTolerance"; - this.ckbxUseDampedTolerance.RightToLeft = System.Windows.Forms.RightToLeft.Yes; - this.ckbxUseDampedTolerance.Size = new System.Drawing.Size(117, 17); - this.ckbxUseDampedTolerance.TabIndex = 78; - this.ckbxUseDampedTolerance.Text = "Damped Tolerance"; - this.ckbxUseDampedTolerance.UseVisualStyleBackColor = true; + this.lblActualFlowRateCmPerHour.AutoSize = true; + this.lblActualFlowRateCmPerHour.Location = new System.Drawing.Point(10, 28); + this.lblActualFlowRateCmPerHour.Name = "lblActualFlowRateCmPerHour"; + this.lblActualFlowRateCmPerHour.Size = new System.Drawing.Size(89, 13); + this.lblActualFlowRateCmPerHour.TabIndex = 74; + this.lblActualFlowRateCmPerHour.Text = "Flow Rate [m³/h]:"; + // + // tbxActualFlowRateCmPerHour + // + this.tbxActualFlowRateCmPerHour.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.tbxActualFlowRateCmPerHour.Location = new System.Drawing.Point(140, 25); + this.tbxActualFlowRateCmPerHour.Name = "tbxActualFlowRateCmPerHour"; + this.tbxActualFlowRateCmPerHour.ReadOnly = true; + this.tbxActualFlowRateCmPerHour.Size = new System.Drawing.Size(120, 20); + this.tbxActualFlowRateCmPerHour.TabIndex = 75; // // FrmMainMiniPrf // @@ -619,14 +621,14 @@ private System.Windows.Forms.Label lblFwVersion; private System.Windows.Forms.Label lblSerialNumber; private System.Windows.Forms.TextBox tbxFM2014SerialNumber; - private System.Windows.Forms.TextBox tbxFwVersion; + private System.Windows.Forms.TextBox tbxApplicationFwVersion; private System.Windows.Forms.Label label9; private System.Windows.Forms.Label lblWaitingForMeterResponse; private System.Windows.Forms.PictureBox pictureBox1; private System.Windows.Forms.Label lblFwUpdateInfo; private System.Windows.Forms.ProgressBar barSingleProgressUpdate; private System.Windows.Forms.Label lblActualProcess; - private System.Windows.Forms.ComboBox cbxFM2014Tolerance; + private System.Windows.Forms.ComboBox cbxFM2014TolerancePercent; private System.Windows.Forms.Label lblFM2014Tolerance; private System.Windows.Forms.ComboBox cbxFM2014Address; private System.Windows.Forms.Label lblFM2014Address; diff --git a/MiniPrf/Ui/FrmMainMiniPrf.cs b/MiniPrf/Ui/FrmMainMiniPrf.cs index 01a44f30..11bb3896 100644 --- a/MiniPrf/Ui/FrmMainMiniPrf.cs +++ b/MiniPrf/Ui/FrmMainMiniPrf.cs @@ -91,6 +91,10 @@ namespace Sensus.MiniPrf.Ui //private readonly ILogger _logger = NLogHelper.CreateOrGetLogger("FM2014"); private readonly FM2014Config _fm2014Config = new FM2014Config(); + // internal reminders of changed items to avoid write access on startup if items are preloaded + private Int32 _comPortIdx; + private Int32 _addressIdx; + private Int32 _toleranceIdx; #endregion Properties #region FormControls @@ -107,20 +111,6 @@ namespace Sensus.MiniPrf.Ui Thread.CurrentThread.CurrentUICulture = cultureInfo; Thread.CurrentThread.CurrentCulture = cultureInfo; _version = Assembly.GetExecutingAssembly().GetName().Version; - - // Load the configuration - _fm2014Config.ReadFM2014Config(); - - // display actual com-port, if not assigned use the 'NA' - cbxFM2014ComPort.Items.Add(_fm2014Config.FM2014ComPort ?? "NA"); - - // collect all com-ports from device manager - var comPorts = SerialPort.GetPortNames().ToList(); - foreach (var comPort in comPorts.Where(comPort => !cbxFM2014ComPort.Items.Contains(comPort))) - { - cbxFM2014ComPort.Items.Add(comPort); - } - cbxFM2014ComPort.Text = cbxFM2014ComPort.Items[0].ToString(); } /// @@ -133,20 +123,50 @@ namespace Sensus.MiniPrf.Ui lblConnectFM2014.ForeColor = Color.Red; lblWaitingForMeterResponse.Visible = false; - tbxFwVersion.Text = ""; + // FM2014 + tbxFullId.Text = ""; + tbxApplicationFwVersion.Text = ""; tbxFM2014SerialNumber.Text = ""; - tbxMeterSize.Text = ""; - tbxRegion.Text = ""; - tbxDateTime.Text = ""; - tbxRadio.Text = ""; - tbxExpiredLifeTime.Text = ""; - tbxDrainedLoad_uAs.Text = ""; - tbxBatteries.Text = ""; - tbxInitialBatteryLoad.Text = ""; + // Load the configuration from the local file stored in AppData\FM2014 + _fm2014Config.ReadFM2014Config(); + + // Display actual com-port, if not assigned use the 'NA'. This will be placed on Items[0] + cbxFM2014ComPort.Items.Add(_fm2014Config.SerialPort ?? "NA"); + + // Collect and add all com-ports from device manager to items + var comPorts = SerialPort.GetPortNames().ToList(); + foreach (var comPort in comPorts.Where(comPort => !cbxFM2014ComPort.Items.Contains(comPort))) + { + cbxFM2014ComPort.Items.Add(comPort); + } + _comPortIdx = 0; + cbxFM2014ComPort.Text = cbxFM2014ComPort.Items[0].ToString(); + + var itemContent = _fm2014Config.Address ?? 1; + for (var idx = 0; idx < cbxFM2014Address.MaxDropDownItems; idx++) + { + if (!cbxFM2014Address.Items[idx].ToString().Equals(itemContent.ToString())) continue; + + _addressIdx = idx; + cbxFM2014Address.SelectedItem = cbxFM2014Address.Items[idx]; + break; + } + + itemContent = _fm2014Config.TolerancePercent ?? 3; + for (var idx = 0; idx < cbxFM2014TolerancePercent.MaxDropDownItems; idx++) + { + if (!cbxFM2014TolerancePercent.Items[idx].ToString().Equals(itemContent.ToString())) continue; + + _toleranceIdx = idx; + cbxFM2014TolerancePercent.SelectedItem = cbxFM2014TolerancePercent.Items[idx]; + break; + } + + // Regulation Setup tbxRefPulsePerVolume.Text = ""; tbxDutPulsePerVolume.Text = ""; tbxScaleRefToDut.Text = ""; - tbxStorageMonths.Text = ""; + tbxActualFlowRateCmPerHour.Text = ""; SetFM2014AccessLocked(); tbxFullId.Visible = false; @@ -163,16 +183,15 @@ namespace Sensus.MiniPrf.Ui /// private void StoreFM2014Settings() { - _fm2014Config.FM2014ComPort = cbxFM2014ComPort.Text; + _fm2014Config.SerialPort = cbxFM2014ComPort.Text; + if (int.TryParse(cbxFM2014Address.SelectedItem.ToString(), out var address)) + _fm2014Config.Address = address; + if (int.TryParse(cbxFM2014TolerancePercent.SelectedItem.ToString(), out var tolerancePercent) + && (tolerancePercent == 3 || tolerancePercent == 5)) + _fm2014Config.TolerancePercent = tolerancePercent; _fm2014Config.Update(); } - private void cbxFM2014ComPort_SelectedIndexChanged(Object sender, EventArgs e) - { - StoreFM2014Settings(); - } - - private void FrmMainMiniPrf_Load(Object sender, EventArgs e) { var version = Assembly.GetExecutingAssembly().GetName().Version; @@ -308,6 +327,8 @@ namespace Sensus.MiniPrf.Ui return; } + StoreFM2014Settings(); + LowLevelActionControl(true); _fm2014?.Dispose(); @@ -316,7 +337,26 @@ namespace Sensus.MiniPrf.Ui //assign new meter _fm2014 = new FM2014(); - _fm2014.Address = 1; + if (int.TryParse(cbxFM2014Address.SelectedItem.ToString(), out var address)) + { + _fm2014.Address = address; + } + else + { + LowLevelActionControl(false); + LogErrorText("ERROR: FM2014 Address is invalid!"); + } + if (int.TryParse(cbxFM2014TolerancePercent.SelectedItem.ToString(), out var tolerancePercent) + && (tolerancePercent == 3 || tolerancePercent == 5)) + { + _fm2014.TolerancePercent = tolerancePercent; + } + else + { + LowLevelActionControl(false); + LogErrorText("ERROR: FM2014 Tolerance is invalid!"); + } + lblActualProcess.Text = @"Connecting to FM2014..."; _fm2014.Connect(cbxFM2014ComPort.SelectedItem.ToString()); @@ -339,7 +379,7 @@ namespace Sensus.MiniPrf.Ui lblConnectFM2014.Text = StrPartPcbConnected; tbxFullId.Text = _fm2014.FullId; tbxFullId.Visible = true; - tbxFwVersion.Text = _fm2014.FwVersion; + tbxApplicationFwVersion.Text = _fm2014.FwVersion; LogText("FM2014 Full ID:\t" + _fm2014.FullId); LogText("FM2014 FW Version:\t" + _fm2014.FwVersion); LogText("FM2014 Serial Number:\t" + _fm2014.SerialNumber); @@ -440,7 +480,7 @@ namespace Sensus.MiniPrf.Ui else { lblActualProcess.Visible = false; - barSingleProgressUpdate.Visible = false; + barSingleProgressUpdate.Visible = false; tmrProgressUpdate.Enabled = false; lblWaitingForMeterResponse.Visible = false; lblActualProcess.Text = ""; @@ -576,6 +616,19 @@ namespace Sensus.MiniPrf.Ui Connect(); } - #endregion Tools + private void cbxFM2014ComPort_SelectedValueChanged(Object sender, EventArgs e) + { + if (_toleranceIdx != cbxFM2014TolerancePercent.SelectedIndex || + _addressIdx != cbxFM2014Address.SelectedIndex || + _comPortIdx != cbxFM2014ComPort.SelectedIndex) + { + _toleranceIdx = cbxFM2014TolerancePercent.SelectedIndex; + _addressIdx = cbxFM2014Address.SelectedIndex; + _comPortIdx = cbxFM2014ComPort.SelectedIndex; + StoreFM2014Settings(); + } + } + #endregion Buttons and Controls + } }