diff --git a/Common/Hardware/WaterMeter/MagFlux/MagFluxCore/MagFluxMeter.cs b/Common/Hardware/WaterMeter/MagFlux/MagFluxCore/MagFluxMeter.cs index 11614711..e9ffd451 100644 --- a/Common/Hardware/WaterMeter/MagFlux/MagFluxCore/MagFluxMeter.cs +++ b/Common/Hardware/WaterMeter/MagFlux/MagFluxCore/MagFluxMeter.cs @@ -36,16 +36,16 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxCore { #region Variables and Properties + /// + /// Calibration points reference to DUT + /// + private List _calibPoints; + /// /// Mark the streaming catcher as active /// private Boolean _streamingCatcherIsActive; - /// - /// Streaming decoder - /// - //private StreamingDecoder _streamingDecoder; - /// /// Enable raw record logging, if set every incoming package will be logged /// @@ -81,7 +81,7 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxCore /// /// Represent meter size in mm /// - public Int32 MeterSize_mm + public Int32 MeterSizeMm { get; private set; @@ -123,14 +123,11 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxCore private String _currentActionText = ""; /// - /// Hold the current process name e.g. FlowTest, Preadjustemtn for logging + /// Hold the current process name e.g. FlowTest, Preadjustment for logging /// public String CurrentActionText { - get - { - return _currentActionText; - } + get => _currentActionText; set { _currentActionText = value; @@ -138,36 +135,38 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxCore } } - /// - /// Add on ctor a password and it will be used for login in if no other password is set - /// - private String _password; + ///// + ///// Add on ctor a password and it will be used for login in if no other password is set + ///// + //private String _password; /// /// request port assignment/info /// - public IPort RequestPort + private IPort RequestPort { - get; private set; + get; + set; } /// /// request protocol assignment/info /// - public RequestProtocol RequestProtocol; + private RequestProtocol RequestProtocol; /// /// streaming port assignment/info /// - public IPort StreamingPort + private IPort StreamingPort { - get; private set; + get; + set; } /// /// streaming protocol assignment/info /// - public StreamingProtocol StreamingProtocol; + private StreamingProtocol StreamingProtocol; /// public String SerialNumber @@ -189,12 +188,9 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxCore /// on some states other events will be invoke as well public ProcessState ProcessStatus { - get - { - return _myProcessStatus; - } + get => _myProcessStatus; - set + private set { if (_myProcessStatus == value) { @@ -242,8 +238,9 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxCore /// public ErrorState ErrorStatus { + private set; get; - } + } = ErrorState.None; /// public Int32 Slot @@ -267,7 +264,7 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxCore /// /// Transmit protocol access for underlie objects to change response timeout /// - public ITransmitProtocol TransmitProtocol; + private ITransmitProtocol TransmitProtocol; //initially do not signal event private readonly AutoResetEvent _onSyncKeepSessionThread = new AutoResetEvent(false); @@ -325,9 +322,9 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxCore /// public event EventHandler OnStreamingRecordDecoded; - /// - /// call this if session is expired and you need an re-authorization - /// + ///// + ///// call this if session is expired and you need an re-authorization + ///// //public EventHandler AuthorizationRequired; /// @@ -555,7 +552,7 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxCore Boolean ignoreCorruptedData = true, String password = "") { Slot = slot; - _password = password; + //_password = password; if (requestPort != null) { @@ -624,7 +621,7 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxCore /// /// On should one once added in runtime /// - private void LinkPortToProtocol(IPort port, IProtocol protocol) + private static void LinkPortToProtocol(IPort port, IProtocol protocol) { //for streaming mode only if (port == null) @@ -672,11 +669,9 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxCore private void RequestProtocol_AuthorizationGrant(Object sender, EventArgs e) { - _logger.Debug($"Slot:{Slot} - Authorization succeeded"); - } - /// + public void SetupFromConfigFile(Int32 slot, Boolean ignoreCorruptedData = true) { SetupFromConfigFile(slot, ignoreCorruptedData, true, true); @@ -760,9 +755,9 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxCore { FwBuildDate = fwBuildDate; } - if (RequestProtocol.GetDn_mm(out var meterSize_mm)) + if (RequestProtocol.GetMeterSizeMm(out var meterSizeMm)) { - MeterSize_mm = meterSize_mm; + MeterSizeMm = meterSizeMm; } if (RequestProtocol.GetFwGitHash(out var gitHash)) { @@ -772,7 +767,8 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxCore { UniqueId = uniqueId; } - if (RequestProtocol.GetSensorSerialNo(out var pcbId)) + // The PcbId will be named as SensorSerialNo by MJK + if (RequestProtocol.GetPcbId(out var pcbId)) { PcbId = pcbId; } @@ -948,36 +944,49 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxCore return ret.HasValue ? ret.Value : false; } - private CalibrationPoints calibPoints; + /// > + public String GetPcbId(Int32 expectedLength = 12) + { + if (!string.IsNullOrEmpty(PcbId) && !string.Equals("?", PcbId)) + { + return PcbId; + } + var pcbId = PcbId; + RequestProtocol?.GetPcbId(out pcbId); + PcbId = pcbId; + return pcbId; + } /// /// Write calibration values to MagFlux /// - public void WriteCalibration() + public void WriteCalibration(List calibPoints) { _logger.Info($"Slot:{Slot} - Write calibration values to MagFlux"); - RequestProtocol?.SetCalibrationPoints(calibPoints); + _calibPoints = calibPoints; + + RequestProtocol?.SetCalibrationPoints(_calibPoints); } /// - /// Write calibration values to MagFlux + /// Read calibration values to MagFlux /// - public void ReadCalibration() + public void ReadCalibration(out List calibPoints) { _logger.Info($"Slot:{Slot} - Read calibration values from MagFlux"); - RequestProtocol?.GetCalibrationPoints(out calibPoints); + RequestProtocol?.GetCalibrationPoints(out _calibPoints); + calibPoints = _calibPoints; } + /// public void InitCalibration() { _logger.Info($"Slot:{Slot} - Init calibration and set calibration values of all channels to default"); if (RequestProtocol == null) return; - // first read out the current calibration points - RequestProtocol.GetCalibrationPoints(out calibPoints); + // first read out the current calibration points, those are used as container for overwriting + RequestProtocol.GetCalibrationPoints(out _calibPoints); if (RequestProtocol.PrepareDeviceForCalibration()) PreMeasurement(); - RequestProtocol.GetCalibrationPoints(out calibPoints); - } /// @@ -1000,8 +1009,8 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxCore } /// - public void BuildAndCheckCalibFactorsAllChannels(Double refVolumeCm, Double? refTimeS = null, Double reqDeviationPercent = 0, - Double maxCalibFactorTolerancePercent = 0) + public void BuildAndCheckCalibFactorsAllChannels(Double refVolumeCm, Double? refTimeS = null, + Double reqDeviationPercent = 0, Double maxCalibFactorTolerancePercent = 0) { throw new NotImplementedException(); } @@ -1140,15 +1149,15 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxCore if (!string.IsNullOrEmpty(SerialNumber) && CurrentActionText.Contains("PG")) { - var pathMain = NLogHelper.GetPath(_logger); - var pathRaw = NLogHelper.GetPath(((LedSerialPort)StreamingPort).GetRawLogger()); + //var pathMain = NLogHelper.GetPath(_logger); + //var pathRaw = NLogHelper.GetPath(((LedSerialPort)StreamingPort).GetRawLogger()); - var basePath = Path.GetDirectoryName(pathMain); + //var basePath = Path.GetDirectoryName(pathMain); - var testRunString = CurrentActionText.Replace("PG", ""); - var lastChat = pathMain.LastIndexOf('\\'); - pathMain = pathMain.Substring(lastChat + 1); - pathRaw = Path.GetFileName(pathRaw); + //var testRunString = CurrentActionText.Replace("PG", ""); + //var lastChat = pathMain.LastIndexOf('\\'); + //pathMain = pathMain.Substring(lastChat + 1); + //pathRaw = Path.GetFileName(pathRaw); //var tmpUrl = $"http://10.49.40.25/MeterProcessState/api/TestBench/SetMeterLogPathInfo?SerialNumber={SerialNumber}&TestRunId={testRunString}&BasePath={basePath}&MainLogName={pathMain}&LEDName={pathRaw}"; //_logger.Debug($"Request Url: { tmpUrl}"); @@ -1159,10 +1168,10 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxCore } } + /// void IMeter.SetupFromConfigFile(Int32 slot, Boolean ignoreCorruptedData, Boolean useRequest, Boolean useStreaming) { SetupFromConfigFile(slot, ignoreCorruptedData); - } #endregion } diff --git a/Common/Hardware/WaterMeter/MagFlux/Protocols/RequestProtocol/RequestProtocol.cs b/Common/Hardware/WaterMeter/MagFlux/Protocols/RequestProtocol/RequestProtocol.cs index 546010c6..b8331e46 100644 --- a/Common/Hardware/WaterMeter/MagFlux/Protocols/RequestProtocol/RequestProtocol.cs +++ b/Common/Hardware/WaterMeter/MagFlux/Protocols/RequestProtocol/RequestProtocol.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Threading; using NLog; using Xylem.Common.Hardware.Interfaces.Ports.PortCore.EventArguments; @@ -111,19 +112,20 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.Protocols.RequestProtocol } /// - /// Wrapper to get the sensor serial number + /// Wrapper to get the PcbId which equals the sensor serial number /// - /// + /// /// /// /// - Initial /// - public Boolean GetSensorSerialNo(out String serialNumber) + public Boolean GetPcbId(out String pcbId) { - serialNumber = "?"; + pcbId = "?"; if (_magFluxRequestProtocol == null) return false; - var retVal = _magFluxRequestProtocol.GetSensorSerialNo(out serialNumber); - _logger.Debug(retVal ? $"{_ident} SensorId: {serialNumber}" : $"{_ident} SensorId request failed!"); + var retVal = _magFluxRequestProtocol.GetSensorSerialNo(out pcbId); + _logger.Debug(retVal ? $"{_ident} PcbId (SensorSerialNo): {pcbId}" : + $"{_ident} PcbId (SensorSerialNo) request failed!"); return retVal; } /// @@ -206,7 +208,7 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.Protocols.RequestProtocol /// /// - Initial /// - public Boolean GetDn_mm(out Int32 meterSize) + public Boolean GetMeterSizeMm(out Int32 meterSize) { meterSize = 0; if (_magFluxRequestProtocol == null) return false; @@ -251,28 +253,32 @@ namespace Xylem.Common.Hardware.WaterMeter.MagFlux.Protocols.RequestProtocol /// /// - Initial /// - public Boolean GetCalibrationPoints(out CalibrationPoints calibPoints) + public Boolean GetCalibrationPoints(out List calibPoints) { - calibPoints = null; + calibPoints = new List(); if (_magFluxRequestProtocol == null) return false; - var retVal = _magFluxRequestProtocol.GetCalibrationPoints(out calibPoints); + var retVal = _magFluxRequestProtocol.GetCalibrationPoints(out var calibrations); + calibPoints = calibrations?.calibrations?.ToList(); + calibPoints?.Sort(); _logger.Debug(retVal ? $"{_ident} MagFlux calibration successfully read" : $"{_ident} MagFlux calibration read failed!"); return retVal; } /// - /// Wrapper to set the calibration points from MagFlux + /// Wrapper to set the calibration points from MagFlux: + /// - Calibration points have to be sorted ascending by request from MJK /// /// /// /// /// - Initial /// - public Boolean SetCalibrationPoints(CalibrationPoints calibPoints) + public Boolean SetCalibrationPoints(List calibPoints) { if (_magFluxRequestProtocol == null) return false; - var retVal = _magFluxRequestProtocol.SetCalibrationPoints(calibPoints); + var cbs = new CalibrationPoints(calibPoints, calibPoints.Count); + var retVal = _magFluxRequestProtocol.SetCalibrationPoints(cbs); _logger.Debug(retVal ? $"{_ident} MagFlux calibration successfully set" : $"{_ident} MagFlux calibration setup failed!"); return retVal; diff --git a/Common/Hardware/WaterMeter/WaterMeterCore/IMeter.cs b/Common/Hardware/WaterMeter/WaterMeterCore/IMeter.cs index f5ccfe8a..d6fc263e 100644 --- a/Common/Hardware/WaterMeter/WaterMeterCore/IMeter.cs +++ b/Common/Hardware/WaterMeter/WaterMeterCore/IMeter.cs @@ -101,7 +101,15 @@ namespace Xylem.Common.Hardware.WaterMeter.WaterMeterCore String CurrentActionText { get; set; } #endregion - #region method + #region method + + /// + /// Read the PcbId from IMeter, if device has no readable PcbId simulate one + /// + /// + /// + String GetPcbId(Int32 expectedLength = 12); + /// /// Open Com ports, try some communication, login /// diff --git a/Common/Ui/MagFluxToolBox/FrmTest.Designer.cs b/Common/Ui/MagFluxToolBox/FrmTest.Designer.cs index 21ef3bcd..d5e85b62 100644 --- a/Common/Ui/MagFluxToolBox/FrmTest.Designer.cs +++ b/Common/Ui/MagFluxToolBox/FrmTest.Designer.cs @@ -74,12 +74,14 @@ this.btnWriteCalibration = new System.Windows.Forms.Button(); this.btnAbortCalibration = new System.Windows.Forms.Button(); this.grpCalibration = new System.Windows.Forms.GroupBox(); + this.gridViewCalib = new System.Windows.Forms.DataGridView(); this.grpSetup.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.picLogo)).BeginInit(); this.grpMeasurements.SuspendLayout(); this.grpInfo.SuspendLayout(); this.grpCalibration.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.gridViewCalib)).BeginInit(); this.SuspendLayout(); // // grpSetup @@ -166,7 +168,7 @@ // this.lblWaitingForMeterResponse.AutoSize = true; this.lblWaitingForMeterResponse.ForeColor = System.Drawing.Color.Red; - this.lblWaitingForMeterResponse.Location = new System.Drawing.Point(529, 351); + this.lblWaitingForMeterResponse.Location = new System.Drawing.Point(590, 480); this.lblWaitingForMeterResponse.Name = "lblWaitingForMeterResponse"; this.lblWaitingForMeterResponse.Size = new System.Drawing.Size(182, 13); this.lblWaitingForMeterResponse.TabIndex = 18; @@ -175,7 +177,7 @@ // lblOverall // this.lblOverall.AutoSize = true; - this.lblOverall.Location = new System.Drawing.Point(18, 388); + this.lblOverall.Location = new System.Drawing.Point(15, 517); this.lblOverall.Name = "lblOverall"; this.lblOverall.Size = new System.Drawing.Size(80, 13); this.lblOverall.TabIndex = 7; @@ -183,16 +185,16 @@ // // barSingleProgressUpdate // - this.barSingleProgressUpdate.Location = new System.Drawing.Point(9, 367); + this.barSingleProgressUpdate.Location = new System.Drawing.Point(6, 496); this.barSingleProgressUpdate.Name = "barSingleProgressUpdate"; - this.barSingleProgressUpdate.Size = new System.Drawing.Size(702, 18); + this.barSingleProgressUpdate.Size = new System.Drawing.Size(766, 18); this.barSingleProgressUpdate.TabIndex = 6; this.barSingleProgressUpdate.Visible = false; // // lblActualProcess // this.lblActualProcess.AutoSize = true; - this.lblActualProcess.Location = new System.Drawing.Point(18, 351); + this.lblActualProcess.Location = new System.Drawing.Point(15, 480); this.lblActualProcess.Name = "lblActualProcess"; this.lblActualProcess.Size = new System.Drawing.Size(76, 13); this.lblActualProcess.TabIndex = 4; @@ -200,9 +202,9 @@ // // barOverallProgressUpdate // - this.barOverallProgressUpdate.Location = new System.Drawing.Point(9, 404); + this.barOverallProgressUpdate.Location = new System.Drawing.Point(6, 533); this.barOverallProgressUpdate.Name = "barOverallProgressUpdate"; - this.barOverallProgressUpdate.Size = new System.Drawing.Size(702, 18); + this.barOverallProgressUpdate.Size = new System.Drawing.Size(766, 18); this.barOverallProgressUpdate.TabIndex = 3; this.barOverallProgressUpdate.Visible = false; // @@ -219,7 +221,7 @@ // this.lblFwUpdateInfo.AutoSize = true; this.lblFwUpdateInfo.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.lblFwUpdateInfo.Location = new System.Drawing.Point(623, 66); + this.lblFwUpdateInfo.Location = new System.Drawing.Point(678, 66); this.lblFwUpdateInfo.Name = "lblFwUpdateInfo"; this.lblFwUpdateInfo.Size = new System.Drawing.Size(72, 13); this.lblFwUpdateInfo.TabIndex = 27; @@ -232,7 +234,7 @@ // label9 // this.label9.AutoSize = true; - this.label9.Location = new System.Drawing.Point(247, 351); + this.label9.Location = new System.Drawing.Point(244, 480); this.label9.Name = "label9"; this.label9.Size = new System.Drawing.Size(101, 13); this.label9.TabIndex = 30; @@ -241,7 +243,7 @@ // lblUpdateTime // this.lblUpdateTime.AutoSize = true; - this.lblUpdateTime.Location = new System.Drawing.Point(354, 351); + this.lblUpdateTime.Location = new System.Drawing.Point(351, 480); this.lblUpdateTime.Name = "lblUpdateTime"; this.lblUpdateTime.Size = new System.Drawing.Size(28, 13); this.lblUpdateTime.TabIndex = 31; @@ -262,7 +264,7 @@ this.picLogo.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.picLogo.Image = global::Xylem.Common.Ui.MagFluxToolBox.Properties.Resources.MjK_LogoSmall; this.picLogo.InitialImage = null; - this.picLogo.Location = new System.Drawing.Point(620, 5); + this.picLogo.Location = new System.Drawing.Point(681, 5); this.picLogo.Name = "picLogo"; this.picLogo.Size = new System.Drawing.Size(91, 58); this.picLogo.TabIndex = 34; @@ -278,9 +280,9 @@ this.grpMeasurements.Controls.Add(this.tbxFlowRate); this.grpMeasurements.Controls.Add(this.label7); this.grpMeasurements.Controls.Add(this.label11); - this.grpMeasurements.Location = new System.Drawing.Point(320, -1); + this.grpMeasurements.Location = new System.Drawing.Point(9, 107); this.grpMeasurements.Name = "grpMeasurements"; - this.grpMeasurements.Size = new System.Drawing.Size(203, 157); + this.grpMeasurements.Size = new System.Drawing.Size(305, 127); this.grpMeasurements.TabIndex = 37; this.grpMeasurements.TabStop = false; this.grpMeasurements.Text = "Measurements"; @@ -300,7 +302,7 @@ this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(108, 13); this.label1.TabIndex = 34; - this.label1.Text = "Reverse Volume [m²]:"; + this.label1.Text = "Reverse Volume [m³]:"; // // tbxStatus // @@ -342,7 +344,7 @@ this.label7.Name = "label7"; this.label7.Size = new System.Drawing.Size(89, 13); this.label7.TabIndex = 27; - this.label7.Text = "Flow Rate [m²/h]:"; + this.label7.Text = "Flow Rate [m³/h]:"; // // label11 // @@ -351,7 +353,7 @@ this.label11.Name = "label11"; this.label11.Size = new System.Drawing.Size(65, 13); this.label11.TabIndex = 25; - this.label11.Text = "Volume [m²]:"; + this.label11.Text = "Volume [m³]:"; // // tbxUniqueId // @@ -384,9 +386,9 @@ this.grpInfo.Controls.Add(this.tbxUniqueId); this.grpInfo.Controls.Add(this.tbxSensorNo); this.grpInfo.Controls.Add(this.lblUniqueId); - this.grpInfo.Location = new System.Drawing.Point(9, 107); + this.grpInfo.Location = new System.Drawing.Point(320, -1); this.grpInfo.Name = "grpInfo"; - this.grpInfo.Size = new System.Drawing.Size(305, 232); + this.grpInfo.Size = new System.Drawing.Size(305, 235); this.grpInfo.TabIndex = 25; this.grpInfo.TabStop = false; this.grpInfo.Text = "Info"; @@ -470,7 +472,7 @@ // // btnPrepareCalibration // - this.btnPrepareCalibration.Location = new System.Drawing.Point(269, 56); + this.btnPrepareCalibration.Location = new System.Drawing.Point(488, 100); this.btnPrepareCalibration.Name = "btnPrepareCalibration"; this.btnPrepareCalibration.Size = new System.Drawing.Size(116, 25); this.btnPrepareCalibration.TabIndex = 38; @@ -480,7 +482,7 @@ // // btnReadCalibration // - this.btnReadCalibration.Location = new System.Drawing.Point(269, 87); + this.btnReadCalibration.Location = new System.Drawing.Point(488, 131); this.btnReadCalibration.Name = "btnReadCalibration"; this.btnReadCalibration.Size = new System.Drawing.Size(116, 25); this.btnReadCalibration.TabIndex = 39; @@ -490,7 +492,7 @@ // // btnWriteCalibration // - this.btnWriteCalibration.Location = new System.Drawing.Point(269, 118); + this.btnWriteCalibration.Location = new System.Drawing.Point(488, 162); this.btnWriteCalibration.Name = "btnWriteCalibration"; this.btnWriteCalibration.Size = new System.Drawing.Size(116, 25); this.btnWriteCalibration.TabIndex = 40; @@ -500,7 +502,7 @@ // // btnAbortCalibration // - this.btnAbortCalibration.Location = new System.Drawing.Point(269, 146); + this.btnAbortCalibration.Location = new System.Drawing.Point(488, 190); this.btnAbortCalibration.Name = "btnAbortCalibration"; this.btnAbortCalibration.Size = new System.Drawing.Size(116, 25); this.btnAbortCalibration.TabIndex = 41; @@ -510,23 +512,39 @@ // // grpCalibration // + this.grpCalibration.Controls.Add(this.gridViewCalib); this.grpCalibration.Controls.Add(this.btnAbortCalibration); this.grpCalibration.Controls.Add(this.btnPrepareCalibration); this.grpCalibration.Controls.Add(this.btnReadCalibration); this.grpCalibration.Controls.Add(this.btnWriteCalibration); - this.grpCalibration.Location = new System.Drawing.Point(320, 162); + this.grpCalibration.Location = new System.Drawing.Point(9, 240); this.grpCalibration.Name = "grpCalibration"; - this.grpCalibration.Size = new System.Drawing.Size(391, 177); + this.grpCalibration.Size = new System.Drawing.Size(616, 225); this.grpCalibration.TabIndex = 42; this.grpCalibration.TabStop = false; this.grpCalibration.Text = "Calibration"; // + // gridViewCalib + // + this.gridViewCalib.AllowUserToAddRows = false; + this.gridViewCalib.AllowUserToDeleteRows = false; + this.gridViewCalib.AllowUserToResizeRows = false; + this.gridViewCalib.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.AllCells; + this.gridViewCalib.BackgroundColor = System.Drawing.SystemColors.Control; + this.gridViewCalib.BorderStyle = System.Windows.Forms.BorderStyle.None; + this.gridViewCalib.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.gridViewCalib.Location = new System.Drawing.Point(9, 18); + this.gridViewCalib.Name = "gridViewCalib"; + this.gridViewCalib.Size = new System.Drawing.Size(455, 197); + this.gridViewCalib.TabIndex = 42; + this.gridViewCalib.CellEndEdit += new System.Windows.Forms.DataGridViewCellEventHandler(this.gridViewCalib_CellEndEdit); + // // FrmTest // this.AccessibleRole = System.Windows.Forms.AccessibleRole.Sound; this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(723, 432); + this.ClientSize = new System.Drawing.Size(784, 561); this.Controls.Add(this.grpCalibration); this.Controls.Add(this.grpInfo); this.Controls.Add(this.grpMeasurements); @@ -542,9 +560,9 @@ this.Controls.Add(this.grpSetup); this.Controls.Add(this.barOverallProgressUpdate); this.MaximizeBox = false; - this.MaximumSize = new System.Drawing.Size(739, 500); + this.MaximumSize = new System.Drawing.Size(800, 600); this.MinimizeBox = false; - this.MinimumSize = new System.Drawing.Size(739, 405); + this.MinimumSize = new System.Drawing.Size(800, 600); this.Name = "FrmTest"; this.Text = "MagFlux Test"; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.FrmTest_FormClosing); @@ -558,6 +576,7 @@ this.grpInfo.ResumeLayout(false); this.grpInfo.PerformLayout(); this.grpCalibration.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.gridViewCalib)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -610,5 +629,6 @@ private System.Windows.Forms.Button btnWriteCalibration; private System.Windows.Forms.Button btnAbortCalibration; private System.Windows.Forms.GroupBox grpCalibration; + private System.Windows.Forms.DataGridView gridViewCalib; } } \ No newline at end of file diff --git a/Common/Ui/MagFluxToolBox/FrmTest.cs b/Common/Ui/MagFluxToolBox/FrmTest.cs index 2888a4af..8d68ee12 100644 --- a/Common/Ui/MagFluxToolBox/FrmTest.cs +++ b/Common/Ui/MagFluxToolBox/FrmTest.cs @@ -1,14 +1,19 @@ using System; +using System.Collections.Generic; +using System.Data; using System.Drawing; using System.Globalization; +using System.Linq; using System.Reflection; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; +using System.Xml.Serialization; using Xylem.Common.Hardware.WaterMeter.MagFlux.DataPackages.EventArguments; using Xylem.Common.Hardware.WaterMeter.MagFlux.MagFluxCore; using Xylem.Common.Hardware.WaterMeter.WaterMeterCore; using Xylem.Common.Utils.ProcessExec.EventArguments; +using XYLEM.Device; namespace Xylem.Common.Ui.MagFluxToolBox @@ -19,6 +24,24 @@ namespace Xylem.Common.Ui.MagFluxToolBox public partial class FrmTest : Form { #region Variables + + struct Calibration + { + public Single refFlowRate; + public Single dutFlowRate; + } + + const String headerRef = @"Ref FlowRate [m³/h]"; + const String headerDut = @"DUT FlowRate [m³/h]"; + + + /// + /// List of calibration points in cubic meters per hour. + /// + private List _calibPointsCmPerH; + + private DataTable _dataTableCalibPoints; + private readonly MeterBatch _meterBatch = new MeterBatch(); private MagFluxMeter _magFluxMeter; private const String StrConnecting = "Connecting to PCB"; @@ -74,6 +97,7 @@ namespace Xylem.Common.Ui.MagFluxToolBox { ProcessViewControl(false); _magFluxMeter?.StopStreamingCatcher(); + _calibPointsCmPerH = new List(); lblSensorNo.Text = StrNotConnected; lblSensorNo.ForeColor = Color.Red; lblWaitingForMeterResponse.Visible = false; @@ -105,6 +129,8 @@ namespace Xylem.Common.Ui.MagFluxToolBox private void FrmTest_FormClosing(Object sender, FormClosingEventArgs e) { + _calibPointsCmPerH.Clear(); + _calibPointsCmPerH = null; if (_magFluxMeter != null) { _magFluxMeter.OnStreamingRecordDecoded -= StreamingCatcher_OnStreamingRecordDecoded; @@ -124,6 +150,92 @@ namespace Xylem.Common.Ui.MagFluxToolBox Init(); } #endregion + #region ------------------------------------------ Data Grid Calibration -------------------------------------- + /// + /// Edit calibrations and fill the data back to calibration data field + /// + /// + /// - Initial. + /// + private void gridViewCalib_CellEndEdit(Object sender, DataGridViewCellEventArgs e) + { + try + { + if (e.ColumnIndex < 0 || e.RowIndex < 0 || _dataTableCalibPoints == null + || _calibPointsCmPerH.Count < e.RowIndex) + { + return; + } + + + var array = _calibPointsCmPerH.ToArray(); + var index = e.RowIndex; + _calibPointsCmPerH.Clear(); + var cellContent = gridViewCalib.Rows[e.RowIndex].Cells[e.ColumnIndex].Value; + + if (gridViewCalib.Columns[e.ColumnIndex].Name == headerRef) + array[index].refFlowRate = (Single)cellContent; + + if (gridViewCalib.Columns[e.ColumnIndex].Name == headerDut) + array[index].dutFlowRate = (Single)cellContent; + + var ordered = array.OrderBy(x => x.refFlowRate); + foreach (var a in ordered) + { + _calibPointsCmPerH.Add(a); + } + + FillDataGridWithCalibInfos(); + + } + catch (Exception) + { + // ignored + } + } + /// + /// Build data grid for calibrations + /// + /// + /// - Initial. + /// + private void FillDataGridWithCalibInfos() + { + + if (_calibPointsCmPerH == null) + return; + + _dataTableCalibPoints?.Dispose(); + _dataTableCalibPoints = new DataTable(); + + _dataTableCalibPoints.Columns.Add(headerRef, typeof(Single)); + _dataTableCalibPoints.Columns.Add(headerDut, typeof(Single)); + + try + { + foreach (var cb in _calibPointsCmPerH) + { + var row = _dataTableCalibPoints.NewRow(); + row[headerRef] = cb.refFlowRate; + row[headerDut] = cb.dutFlowRate; + + _dataTableCalibPoints.Rows.Add(row); + } + + gridViewCalib.DataSource = _dataTableCalibPoints; + + foreach (DataGridViewColumn column in gridViewCalib.Columns) + { + column.SortMode = DataGridViewColumnSortMode.NotSortable; + } + } + catch (Exception) + { + //not implemented + } + } + #endregion --------------------------------------- Data Grid Calibration -------------------------------------- + #region ActivationControls private void SetControlDownloadsLocked() @@ -228,7 +340,7 @@ namespace Xylem.Common.Ui.MagFluxToolBox tbxFwVersion.Text = _magFluxMeter.FwVersion; tbxFwBuildDate.Text = _magFluxMeter.FwBuildDate; tbxFwGitHash.Text = _magFluxMeter.FwGitHash; - tbxMeterSize.Text = _magFluxMeter.MeterSize_mm.ToString(); + tbxMeterSize.Text = _magFluxMeter.MeterSizeMm.ToString(); lblSensorNo.ForeColor = Color.Green; CheckUpdateEnabled(); _magFluxMeter.StartStreamingCatcher(); @@ -331,7 +443,7 @@ namespace Xylem.Common.Ui.MagFluxToolBox //// update the display of the meter size, LUT CRC and region //tbxMeterFw.Text = _magFluxMeter.FwVersion; - //tbxMeterMeterSize.Text = _magFluxMeter.MeterSize_mm; + //tbxMeterMeterSize.Text = _magFluxMeter.MeterSizeMm; //tbxMeterLutCrc.Text = _magFluxMeter.LutCrc; //tbxRegion.Text = _magFluxMeter.Region; @@ -531,16 +643,45 @@ namespace Xylem.Common.Ui.MagFluxToolBox { _magFluxMeter?.InitCalibration(); btnAbortCalibration.Enabled = true; + btnReadCalibration_Click(this, null); } private void btnReadCalibration_Click(Object sender, EventArgs e) { - _magFluxMeter?.ReadCalibration(); + var calibPoints = new List(); + _magFluxMeter?.ReadCalibration(out calibPoints); + if (calibPoints == null) return; + var calibConverter = new Calibration(); + _calibPointsCmPerH?.Clear(); + foreach (var cp in calibPoints) + { + // convert flow rate from liters per second to cubic meters per hour + calibConverter.refFlowRate = cp.ReferenceFlowRate_lps * 3.6f; + calibConverter.dutFlowRate = cp.ReportedFlowRate_lps * 3.6f; + _calibPointsCmPerH?.Add(calibConverter); + } + + _dataTableCalibPoints?.Clear(); + FillDataGridWithCalibInfos(); } private void btnWriteCalibration_Click(Object sender, EventArgs e) { - _magFluxMeter?.WriteCalibration(); + if (_calibPointsCmPerH == null) + return; + var calibPoints = new List(); + foreach (var cp in _calibPointsCmPerH) + { + // convert flow rate to liters per second from cubic meters per hour + var calibConverter = new CalibrationPoint + { + ReferenceFlowRate_lps = cp.refFlowRate / 3.6f, + ReportedFlowRate_lps = cp.dutFlowRate / 3.6f + }; + calibPoints.Add(calibConverter); + } + + _magFluxMeter?.WriteCalibration(calibPoints); } private void btnAbortCalibration_Click(Object sender, EventArgs e) diff --git a/Common/Ui/MagFluxToolBox/FrmTest.resx b/Common/Ui/MagFluxToolBox/FrmTest.resx index 9543967f..0a9e92ed 100644 --- a/Common/Ui/MagFluxToolBox/FrmTest.resx +++ b/Common/Ui/MagFluxToolBox/FrmTest.resx @@ -126,4 +126,7 @@ 432, 17 + + 25 + \ No newline at end of file diff --git a/Common/Ui/MagFluxToolBox/MagFluxToolBox.csproj b/Common/Ui/MagFluxToolBox/MagFluxToolBox.csproj index 81a89206..f32c7638 100644 --- a/Common/Ui/MagFluxToolBox/MagFluxToolBox.csproj +++ b/Common/Ui/MagFluxToolBox/MagFluxToolBox.csproj @@ -117,6 +117,10 @@ + + {F14940F8-3C86-4BB7-A915-B021E4B3052D} + modbus_master_csharp + {1B02C79E-0B19-43E2-8F6B-71EF0C786C97} CommonCore diff --git a/Common/Ui/MagFluxToolBox/Properties/AssemblyInfo.cs b/Common/Ui/MagFluxToolBox/Properties/AssemblyInfo.cs index bc73649a..cef0cab1 100644 --- a/Common/Ui/MagFluxToolBox/Properties/AssemblyInfo.cs +++ b/Common/Ui/MagFluxToolBox/Properties/AssemblyInfo.cs @@ -31,5 +31,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.2.0.0")] -[assembly: AssemblyFileVersion("1.2.0.0")] +[assembly: AssemblyVersion("1.3.0.0")] +[assembly: AssemblyFileVersion("1.3.0.0")]