diff --git a/Common/.vs/Common/config/applicationhost.config b/Common/.vs/Common/config/applicationhost.config index c55a7f21..40cde372 100644 --- a/Common/.vs/Common/config/applicationhost.config +++ b/Common/.vs/Common/config/applicationhost.config @@ -155,7 +155,7 @@ - + diff --git a/Common/CordonelPreadjustmentUi/MeterStateControl.cs b/Common/CordonelPreadjustmentUi/MeterStateControl.cs index d157ac8d..7cb2071f 100644 --- a/Common/CordonelPreadjustmentUi/MeterStateControl.cs +++ b/Common/CordonelPreadjustmentUi/MeterStateControl.cs @@ -394,8 +394,8 @@ namespace Xylem.Common.Ui.CordonelPreadjustmentUi private void WatchTmrOnTick(Object sender, EventArgs e) { - var t = new Task(() => { RunWatchActions(); }); - t.Start(); + //var t = new Task(() => { RunWatchActions(); }); + //t.Start(); } internal void DisableTemperatureinput(bool v) diff --git a/Common/CordonelPreadjustmentUi/Processes/Actions/CompletionProcess.cs b/Common/CordonelPreadjustmentUi/Processes/Actions/CompletionProcess.cs index 26680a8c..48416605 100644 --- a/Common/CordonelPreadjustmentUi/Processes/Actions/CompletionProcess.cs +++ b/Common/CordonelPreadjustmentUi/Processes/Actions/CompletionProcess.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Reflection; +using System.Threading; using System.Threading.Tasks; using Xylem.Common.CommonCore.Configuration; using Xylem.Common.Hardware.WaterMeter.Genesis.Registers; @@ -30,6 +31,9 @@ namespace CordonelPreadjustmentUi.Processes.Actions var listOfProcessTask = new List(); pp.IsBusy = true; + + MetersToProcess.ForEach(m => m.StartTempWatch()); + foreach (var meterctl in MetersToProcess) { listOfProcessTask.Add(new Task(() => @@ -52,6 +56,8 @@ namespace CordonelPreadjustmentUi.Processes.Actions Ok = WriteRegisterSafe(meterctl.Meter, $"Store calibration", Register.Genesisflow.StoreCalibration, 1, false); if (CheckAbort(Ok, meterctl)) { return Ok; } pp.DebugMessage($"Read out", meterctl.Slot, "CC"); + Thread.Sleep(1000); + } else { @@ -130,7 +136,7 @@ namespace CordonelPreadjustmentUi.Processes.Actions meterctl.Meter.calibrationResult.AdditionalLogInfos["Amp. Test Mean value PATH 3"] = tempP.Trim(); } meterctl.Meter.calibrationResult.Succesfull = !meterctl.Failed; - + meterctl.Meter.WriteLog($"store CalibrationResults on server Succesfull: {meterctl.Meter.calibrationResult.Succesfull} "); var r = LocalWebRequest.PostRequestAsync($"{ServiceUrls.PostGenesisCalibrationResultUrl()}?PcbId={meterctl.Meter.PcbId}", ref code, ref exPost, 8000, meterctl.Meter.calibrationResult); if (!r) { diff --git a/Common/CordonelPreadjustmentUi/Processes/Actions/TemperatureCalibrationProcess.cs b/Common/CordonelPreadjustmentUi/Processes/Actions/TemperatureCalibrationProcess.cs index 941ad9d4..cabe6f8f 100644 --- a/Common/CordonelPreadjustmentUi/Processes/Actions/TemperatureCalibrationProcess.cs +++ b/Common/CordonelPreadjustmentUi/Processes/Actions/TemperatureCalibrationProcess.cs @@ -74,7 +74,26 @@ namespace CordonelPreadjustmentUi.Processes.Actions foreach (var meterctl in MetersToProcess) { meterctl.SetTemperature(avgTemp); + } + pp.RequestTemperatur(); + while (!pp.PushedTestBenchTemp.HasValue) + { + Thread.Sleep(5000); + } + + foreach (var putTempIntoMeter in MetersToProcess) + { + if (Math.Abs(Convert.ToDecimal(pp.PushedTestBenchTemp.Value) - avgTemp) > (decimal)2.0) + { + System.Windows.Forms.MessageBox.Show("Abweichung von SPS zu Flansch gößer als 2°C"); + } + putTempIntoMeter.Meter.calibrationResult.AddAdditionalLog($"SPS Temp", Convert.ToDecimal(pp.PushedTestBenchTemp.Value).ToString()); + + } + + + } } diff --git a/Common/Hardware/WaterMeter/Genesis/GenesisCore/GenesisMeter.cs b/Common/Hardware/WaterMeter/Genesis/GenesisCore/GenesisMeter.cs index 72704585..6e5a9917 100644 --- a/Common/Hardware/WaterMeter/Genesis/GenesisCore/GenesisMeter.cs +++ b/Common/Hardware/WaterMeter/Genesis/GenesisCore/GenesisMeter.cs @@ -681,7 +681,7 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore 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}"); + Logger.Debug($"Request Url: {tmpUrl}"); //ToDO: Update to service URl LocalWebRequest.GetRequest(tmpUrl, 30000); @@ -817,8 +817,8 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore } catch (Exception ex) { - var msg = $"Slot:{Slot} - {Resources.StrErrorMsgComPort} { ex.Message}"; - Logger.Fatal(msg); + var msg = $"Slot:{Slot} - {Resources.StrErrorMsgComPort} {ex.Message}"; + Logger.Fatal(msg); throw new ApplicationException(msg); } @@ -1451,7 +1451,7 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore try { var radioFrequencyRaw = ReadRegister(Register.Sensusradio.FrequencyIndicator); - if (radioFrequencyRaw != null && + if (radioFrequencyRaw != null && RegisterConverter.ByteArrayToValue(radioFrequencyRaw) != 0) { Region = "EMEA"; @@ -2306,59 +2306,69 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore /// public void Dispose() { - Logger.Trace($"Slot:{Slot} - Start to dispose"); - - - LogRawData(false); - LogManager.Flush(); - //isPart of Logout - //StopKeepSession(); - - //Cancel receive tokens - _keepSessionToken?.Cancel(); - try { - //todo only from Bench - //WriteRegister(Register.Genesisflow.SampleRate, 2, checkRegister: true); - //WriteRegister(Register.Genesisflow.LedMode, 0, checkRegister: true); - //Logout(); - } - catch (Exception) - { - // ignored - } - //Run thread again to notice CancellationToken has changed - _onSyncKeepSessionThread?.Set(); + Logger.Trace($"Slot:{Slot} - Start to dispose"); - //this timeout counter is being used for dispose only - var timeoutCounter = 100; - if (_keepSessionThread != null) - { - while (_keepSessionThread.ThreadState != ThreadState.Stopped && timeoutCounter > 0) + + LogRawData(false); + LogManager.Flush(); + //isPart of Logout + //StopKeepSession(); + + //Cancel receive tokens + _keepSessionToken?.Cancel(); + + try { - Thread.Sleep(1); - timeoutCounter -= 1; + //todo only from Bench + //WriteRegister(Register.Genesisflow.SampleRate, 2, checkRegister: true); + //WriteRegister(Register.Genesisflow.LedMode, 0, checkRegister: true); + //Logout(); + } + catch (Exception) + { + // ignored } - if (_keepSessionThread.ThreadState != ThreadState.Stopped) + + //Run thread again to notice CancellationToken has changed + _onSyncKeepSessionThread?.Set(); + + //this timeout counter is being used for dispose only + var timeoutCounter = 100; + if (_keepSessionThread != null) { - //if thread is still running try to abort - // try to avoid abort (takes age to run and is not safe) - _keepSessionThread.Abort(); + while (_keepSessionThread.ThreadState != ThreadState.Stopped && timeoutCounter > 0) + { + Thread.Sleep(1); + timeoutCounter -= 1; + } + + if (_keepSessionThread.ThreadState != ThreadState.Stopped) + { + //if thread is still running try to abort + // try to avoid abort (takes age to run and is not safe) + _keepSessionThread.Abort(); + } } + + _keepSessionThread = null; + + RequestPort?.Dispose(); + StreamingPort?.Dispose(); + + RequestProtocol?.Dispose(); + StreamingProtocol?.Dispose(); + Logger.Trace($"Slot:{Slot} - Dispose is finished"); } + catch (Exception ex) + { - _keepSessionThread = null; - - RequestPort?.Dispose(); - StreamingPort?.Dispose(); - - RequestProtocol?.Dispose(); - StreamingProtocol?.Dispose(); - Logger.Trace($"Slot:{Slot} - Dispose is finished"); + Logger.Trace($"Slot:{Slot} -dispose exception {ex.Message}"); + } } #endregion diff --git a/Common/Hardware/WaterMeter/WaterMeterCore/WaterMeterRegisters/obj/Debug/WaterMeterRegisters.csproj.CoreCompileInputs.cache b/Common/Hardware/WaterMeter/WaterMeterCore/WaterMeterRegisters/obj/Debug/WaterMeterRegisters.csproj.CoreCompileInputs.cache index 4163759b..ee62f15d 100644 --- a/Common/Hardware/WaterMeter/WaterMeterCore/WaterMeterRegisters/obj/Debug/WaterMeterRegisters.csproj.CoreCompileInputs.cache +++ b/Common/Hardware/WaterMeter/WaterMeterCore/WaterMeterRegisters/obj/Debug/WaterMeterRegisters.csproj.CoreCompileInputs.cache @@ -1 +1 @@ -8cb55c312de586b683d72cf58c13e2801d10e14b767777d98338d3e1473a1213 +e5e0833ba33456b07a9a7533c01344837e98dad9 diff --git a/Common/LaaPackages b/Common/LaaPackages index e7aa3e27..69bb5675 160000 --- a/Common/LaaPackages +++ b/Common/LaaPackages @@ -1 +1 @@ -Subproject commit e7aa3e2723a435f0a714df661dc5d86dfd45a71c +Subproject commit 69bb567543b02e71b246a70e7b0aa255f4fda529 diff --git a/Common/Service/MeterProcessState/Controllers/FinalCheckController.cs b/Common/Service/MeterProcessState/Controllers/FinalCheckController.cs index 92efca20..ddce280e 100644 --- a/Common/Service/MeterProcessState/Controllers/FinalCheckController.cs +++ b/Common/Service/MeterProcessState/Controllers/FinalCheckController.cs @@ -671,7 +671,7 @@ namespace Xylem.Common.Service.MeterProcessState.Controllers if (CheckPcbId.HasValue) { - var SkipRadioCheck = true; + var SkipRadioCheck = false; sb = new StringBuilder(); @@ -1273,7 +1273,68 @@ namespace Xylem.Common.Service.MeterProcessState.Controllers } } + [HttpGet] + [Route("CalibrationResultsFromRun/{CalibrationResultId}")] + public IHttpActionResult CalibrationResultsFromRun(int CalibrationResultId) + { + var result = SqlConnection + .CreateSqlConnection(GlobalConfig.ConnectionString.Value) + .CreateCommand($@" + SELECT TOP 1 + ID + , PcbId + , CalFactor1 + , CalFactor2 + , CalFactor3 + , ZeroOffset1 + , ZeroOffset2 + , ZeroOffset3 + , FirstHitUpdatePeriod + , FirstHitShift + , FirstHitPercent1 + , FirstHitPercent2 + , FirstHitPercent3 + , ToFTempOffset1 + , ToFTempOffset2 + , ToFTempOffset3 + , MeterSize + , date + , successful + FROM CordonelMeterCalibrationResults + WHERE successful = 1 + AND ID = @{nameof(CalibrationResultId)} + ORDER BY date DESC") + .SetParameter(nameof(CalibrationResultId), CalibrationResultId) + .FirstOrDefault(x => new CalibrationResults + { + Id = x.GetValue(0), + PcbId = x.GetValue(1), + CalFactor1 = x.GetValue(2), + CalFactor2 = x.GetValue(3), + CalFactor3 = x.GetValue(4), + ZeroOffset1 = x.GetValue(5), + ZeroOffset2 = x.GetValue(6), + ZeroOffset3 = x.GetValue(7), + FirstHitUpdatePeriod = x.GetValue(8), + FirstHitShift = x.GetValue(9), + FirstHitPercent1 = x.GetValue(10), + FirstHitPercent2 = x.GetValue(11), + FirstHitPercent3 = x.GetValue(12), + ToFTempOffset1 = x.GetValue(13), + ToFTempOffset2 = x.GetValue(14), + ToFTempOffset3 = x.GetValue(15), + MeterSize = x.GetValue(16), + Date = x.GetValue(17), + Succeeded = x.GetValue(18), + }); + if (result is null) + { + return this.NotFound(); + } + + return this.Json(result); + } [HttpGet] [Route("CalibrationResults/{pcbId}")] diff --git a/Common/Service/MeterProcessState/MeterProcessState.csproj b/Common/Service/MeterProcessState/MeterProcessState.csproj index 4d228141..08dbc41d 100644 --- a/Common/Service/MeterProcessState/MeterProcessState.csproj +++ b/Common/Service/MeterProcessState/MeterProcessState.csproj @@ -14,7 +14,7 @@ Properties Xylem.Common.Service.MeterProcessState Xylem.Common.Service.MeterProcessState - v4.8.1 + v4.8 false true @@ -39,6 +39,7 @@ bin\Xylem.Common.Service.MeterProcessState.xml IDE0003;IDE0049;CS1591; OnlyFilesToRunTheApp + false pdbonly @@ -48,6 +49,7 @@ prompt 4 7 + false @@ -497,6 +499,7 @@ prompt MinimumRecommendedRules.ruleset 7.0 + false true @@ -507,6 +510,7 @@ 7 prompt MinimumRecommendedRules.ruleset + false bin\ @@ -517,6 +521,7 @@ 7 prompt MinimumRecommendedRules.ruleset + false true @@ -527,6 +532,7 @@ 7.0 prompt MinimumRecommendedRules.ruleset + false false @@ -539,9 +545,11 @@ bin\ + false bin\ + false diff --git a/Common/Service/MeterProcessState/MeterProcessState.csproj.user b/Common/Service/MeterProcessState/MeterProcessState.csproj.user index fd13e9b2..caeb1dad 100644 --- a/Common/Service/MeterProcessState/MeterProcessState.csproj.user +++ b/Common/Service/MeterProcessState/MeterProcessState.csproj.user @@ -2,7 +2,7 @@ Debug|Any CPU - a + C:\Users\drabesch_ro\Repo\lab\la_operations\laa_production\Common\Service\MeterProcessState\Properties\PublishProfiles\a.pubxml true diff --git a/Common/Ui/GenesisToolBox/frmRegisterStore.Designer.cs b/Common/Ui/GenesisToolBox/frmRegisterStore.Designer.cs index 5c3ccd96..0e6c9124 100644 --- a/Common/Ui/GenesisToolBox/frmRegisterStore.Designer.cs +++ b/Common/Ui/GenesisToolBox/frmRegisterStore.Designer.cs @@ -44,17 +44,18 @@ this.probarBussy = new System.Windows.Forms.ProgressBar(); this.label3 = new System.Windows.Forms.Label(); this.btnReadFwVersions = new System.Windows.Forms.Button(); - this.btn_MultiReadWrite = new System.Windows.Forms.Button(); + this.btn_CalibrationRestore = new System.Windows.Forms.Button(); this.button1 = new System.Windows.Forms.Button(); this.button2 = new System.Windows.Forms.Button(); this.btnStoreAll = new System.Windows.Forms.Button(); this.button3 = new System.Windows.Forms.Button(); this.timer1 = new System.Windows.Forms.Timer(this.components); - this.button6 = new System.Windows.Forms.Button(); this.btnBatLife = new System.Windows.Forms.Button(); this.btnRadioPressure = new System.Windows.Forms.Button(); + this.nundCalResultID = new System.Windows.Forms.NumericUpDown(); ((System.ComponentModel.ISupportInitialize)(this.registerGridView)).BeginInit(); this.pnlBussy.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.nundCalResultID)).BeginInit(); this.SuspendLayout(); // // cbComSlot @@ -78,7 +79,7 @@ // // btnRead // - this.btnRead.Location = new System.Drawing.Point(205, 48); + this.btnRead.Location = new System.Drawing.Point(189, 48); this.btnRead.Name = "btnRead"; this.btnRead.Size = new System.Drawing.Size(185, 30); this.btnRead.TabIndex = 2; @@ -103,7 +104,7 @@ // // btnConnect // - this.btnConnect.Location = new System.Drawing.Point(214, 12); + this.btnConnect.Location = new System.Drawing.Point(189, 12); this.btnConnect.Name = "btnConnect"; this.btnConnect.Size = new System.Drawing.Size(85, 30); this.btnConnect.TabIndex = 4; @@ -127,9 +128,9 @@ // // btnGetPCbID // - this.btnGetPCbID.Location = new System.Drawing.Point(305, 12); + this.btnGetPCbID.Location = new System.Drawing.Point(280, 12); this.btnGetPCbID.Name = "btnGetPCbID"; - this.btnGetPCbID.Size = new System.Drawing.Size(85, 30); + this.btnGetPCbID.Size = new System.Drawing.Size(94, 30); this.btnGetPCbID.TabIndex = 11; this.btnGetPCbID.Text = "Get PCB ID"; this.btnGetPCbID.UseVisualStyleBackColor = true; @@ -196,7 +197,7 @@ // // btnReadFwVersions // - this.btnReadFwVersions.Location = new System.Drawing.Point(396, 12); + this.btnReadFwVersions.Location = new System.Drawing.Point(380, 12); this.btnReadFwVersions.Name = "btnReadFwVersions"; this.btnReadFwVersions.Size = new System.Drawing.Size(114, 30); this.btnReadFwVersions.TabIndex = 52; @@ -204,19 +205,19 @@ this.btnReadFwVersions.UseVisualStyleBackColor = true; this.btnReadFwVersions.Click += new System.EventHandler(this.btnReadFwVersions_Click); // - // btn_MultiReadWrite + // btn_CalibrationRestore // - this.btn_MultiReadWrite.Location = new System.Drawing.Point(516, 12); - this.btn_MultiReadWrite.Name = "btn_MultiReadWrite"; - this.btn_MultiReadWrite.Size = new System.Drawing.Size(110, 30); - this.btn_MultiReadWrite.TabIndex = 58; - this.btn_MultiReadWrite.Text = "MultiReadWrite"; - this.btn_MultiReadWrite.UseVisualStyleBackColor = true; - this.btn_MultiReadWrite.Click += new System.EventHandler(this.btn_MultiReadWrite_Click); + this.btn_CalibrationRestore.Location = new System.Drawing.Point(516, 12); + this.btn_CalibrationRestore.Name = "btn_CalibrationRestore"; + this.btn_CalibrationRestore.Size = new System.Drawing.Size(114, 30); + this.btn_CalibrationRestore.TabIndex = 58; + this.btn_CalibrationRestore.Text = "CalibrationRestore"; + this.btn_CalibrationRestore.UseVisualStyleBackColor = true; + this.btn_CalibrationRestore.Click += new System.EventHandler(this.btn_CalibrationRestore_Click); // // button1 // - this.button1.Location = new System.Drawing.Point(396, 48); + this.button1.Location = new System.Drawing.Point(380, 48); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(114, 30); this.button1.TabIndex = 60; @@ -226,7 +227,7 @@ // // button2 // - this.button2.Location = new System.Drawing.Point(516, 46); + this.button2.Location = new System.Drawing.Point(516, 80); this.button2.Name = "button2"; this.button2.Size = new System.Drawing.Size(114, 30); this.button2.TabIndex = 61; @@ -259,16 +260,6 @@ this.timer1.Interval = 5000; this.timer1.Tick += new System.EventHandler(this.timer1_Tick); // - // button6 - // - this.button6.Location = new System.Drawing.Point(516, 80); - this.button6.Name = "button6"; - this.button6.Size = new System.Drawing.Size(110, 30); - this.button6.TabIndex = 68; - this.button6.Text = "Seal Display Test"; - this.button6.UseVisualStyleBackColor = true; - this.button6.Click += new System.EventHandler(this.button6_Click); - // // btnBatLife // this.btnBatLife.Location = new System.Drawing.Point(516, 116); @@ -289,19 +280,31 @@ this.btnRadioPressure.UseVisualStyleBackColor = true; this.btnRadioPressure.Click += new System.EventHandler(this.btnRadioPressure_Click); // + // nundCalResultID + // + this.nundCalResultID.Location = new System.Drawing.Point(516, 47); + this.nundCalResultID.Maximum = new decimal(new int[] { + 999999, + 0, + 0, + 0}); + this.nundCalResultID.Name = "nundCalResultID"; + this.nundCalResultID.Size = new System.Drawing.Size(114, 20); + this.nundCalResultID.TabIndex = 73; + // // FrmRegisterStore // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(695, 553); + this.Controls.Add(this.nundCalResultID); this.Controls.Add(this.btnRadioPressure); this.Controls.Add(this.btnBatLife); - this.Controls.Add(this.button6); this.Controls.Add(this.button3); this.Controls.Add(this.btnStoreAll); this.Controls.Add(this.button2); this.Controls.Add(this.button1); - this.Controls.Add(this.btn_MultiReadWrite); + this.Controls.Add(this.btn_CalibrationRestore); this.Controls.Add(this.btnReadFwVersions); this.Controls.Add(this.pnlBussy); this.Controls.Add(this.btnGetPCbID); @@ -318,6 +321,7 @@ ((System.ComponentModel.ISupportInitialize)(this.registerGridView)).EndInit(); this.pnlBussy.ResumeLayout(false); this.pnlBussy.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.nundCalResultID)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -339,14 +343,14 @@ private System.Windows.Forms.ProgressBar probarBussy; private System.Windows.Forms.Label label3; private System.Windows.Forms.Button btnReadFwVersions; - private System.Windows.Forms.Button btn_MultiReadWrite; + private System.Windows.Forms.Button btn_CalibrationRestore; private System.Windows.Forms.Button button1; private System.Windows.Forms.Button button2; private System.Windows.Forms.Button btnStoreAll; private System.Windows.Forms.Button button3; private System.Windows.Forms.Timer timer1; - private System.Windows.Forms.Button button6; private System.Windows.Forms.Button btnBatLife; private System.Windows.Forms.Button btnRadioPressure; + private System.Windows.Forms.NumericUpDown nundCalResultID; } } \ No newline at end of file diff --git a/Common/Ui/GenesisToolBox/frmRegisterStore.cs b/Common/Ui/GenesisToolBox/frmRegisterStore.cs index 575d3de5..618c0e0e 100644 --- a/Common/Ui/GenesisToolBox/frmRegisterStore.cs +++ b/Common/Ui/GenesisToolBox/frmRegisterStore.cs @@ -8,6 +8,7 @@ using System.Data; using System.Drawing; using System.IO; using System.Linq; +using System.Net; using System.Reflection; using System.Text; using System.Threading; @@ -27,6 +28,7 @@ using Xylem.Common.Logic.ProductionOrderCore.TestResults; using Xylem.Common.Logic.ServiceCore; using Xylem.Common.Logic.SoftwareAccessHelper; using Xylem.Common.Utils.Logging; +using XylemCommonUiLegacyGenCtl; using static Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore.GenesisMeter; using Access = Xylem.Common.Hardware.WaterMeter.Genesis.Registers.Access; @@ -1568,12 +1570,6 @@ namespace Xylem.Common.Ui.GenesisToolBox private void btn_MultiReadWrite_Click(Object sender, EventArgs e) { - if (_currentGenesis != null && _currentGenesis.IsLoggedOn) - { - var frmDialog = new FrmMultiWrite(_currentGenesis, _currentGenesis.GetRegistersDic()); - - frmDialog.ShowDialog(); - } } @@ -1969,7 +1965,7 @@ namespace Xylem.Common.Ui.GenesisToolBox Thread.Sleep(5000); if (!_currentGenesis.Login()) { - + } } _currentGenesis.WriteRegister("SYSTEM_ExitReason", 21, true, false); @@ -2072,7 +2068,7 @@ namespace Xylem.Common.Ui.GenesisToolBox } catch (Exception ex) { - + } @@ -2142,14 +2138,14 @@ namespace Xylem.Common.Ui.GenesisToolBox //CUSTOMER_AlarmVisualMask - 00-00-1F-DC // - Meter.WriteRegister("SENSUSRADIO_MainAlarmMask", new Byte[] { 0x00 }, true); - Meter.WriteRegister("SENSUSRADIO_ExtendedAlarmMask", new Byte[] { 0x00 }, true); + Meter.WriteRegister("SENSUSRADIO_MainAlarmMask", new Byte[] { 0x00 }, true); + Meter.WriteRegister("SENSUSRADIO_ExtendedAlarmMask", new Byte[] { 0x00 }, true); Meter.WriteRegister("CUSTOMER_AlarmEnableMask", new Byte[] { 0xD3, 0x9F, 0x00, 0x00 }, true); Meter.WriteRegister("CUSTOMER_AlarmBroadcastMask", new Byte[] { 0xDC, 0x1F, 0x00, 0x00 }, true); Meter.WriteRegister("CUSTOMER_AlarmVisualMask", new Byte[] { 0xDC, 0x1F, 0x00, 0x00 }, true); - - Meter.WriteRegister("SENSUSRADIO_SystemState", 0xFF,true); + + Meter.WriteRegister("SENSUSRADIO_SystemState", 0xFF, true); Meter.Logout(); Thread.Sleep(5000); if (!Meter.Login()) @@ -2157,7 +2153,7 @@ namespace Xylem.Common.Ui.GenesisToolBox Thread.Sleep(5000); if (!Meter.Login()) { - + } } @@ -2196,5 +2192,73 @@ namespace Xylem.Common.Ui.GenesisToolBox } } + + private void btn_CalibrationRestore_Click(Object sender, EventArgs e) + { + string err; + foreach (var me in _meterBatch.ListOfMeters) + { + if (me is GenesisMeter Meter) + { + if (((GenesisMeter)me).IsLoggedOn) + { + var meterCalibrations = new CalibrationResults(); + if (!GetCalibrationResultsFromDbperRun(_currentPcbId, meterCalibrations, out err)) + { + MessageBox.Show(err); + } + else + { + Meter.WriteRegister(Register.Genesisflow.FirstHitPercent1, meterCalibrations.FirstHitPercent1, true); + Meter.WriteRegister(Register.Genesisflow.FirstHitPercent2, meterCalibrations.FirstHitPercent2, true); + Meter.WriteRegister(Register.Genesisflow.FirstHitPercent3, meterCalibrations.FirstHitPercent3, true); + Meter.WriteRegister(Register.Genesisflow.FirstHitShift, meterCalibrations.FirstHitShift, true); + Meter.WriteRegister(Register.Genesisflow.FirstHitUpdatePeriod, meterCalibrations.FirstHitUpdatePeriod, true); + Meter.WriteRegister(Register.Genesisflow.ToFTempOffset1, meterCalibrations.ToFTempOffset1, true); + Meter.WriteRegister(Register.Genesisflow.ToFTempOffset2, meterCalibrations.ToFTempOffset2, true); + Meter.WriteRegister(Register.Genesisflow.ToFTempOffset3, meterCalibrations.ToFTempOffset3, true); + Meter.WriteRegister(Register.Genesisflow.ZeroOffset1, meterCalibrations.ZeroOffset1, true); + Meter.WriteRegister(Register.Genesisflow.ZeroOffset2, meterCalibrations.ZeroOffset2, true); + Meter.WriteRegister(Register.Genesisflow.ZeroOffset3, meterCalibrations.ZeroOffset3, true); + } + } + } + } + } + + public static Boolean GetCalibrationResultsFromDbperRun(int RunId, CalibrationResults calibResults, + out String errorMsg) + { + errorMsg = ""; + if (null == calibResults || string.IsNullOrEmpty(RunId)) + { + return false; + } + + try + { + var url = "http://sla12iis01.emea.sensus.net/MeterProcessState/api/FinalCheck/CalibrationResults/"; + var requestResponse = LocalWebRequest.GetRequest(url, 30000, out var httpStatus); + if (httpStatus == HttpStatusCode.OK && !string.IsNullOrEmpty(requestResponse)) + { + var calibRes = JsonConvert.DeserializeObject(requestResponse); + // ClassAccess.CopyProperties(calibResults, calibRes); + var type = typeof(CalibrationResults); + foreach (var prop in type.GetProperties()) + { + if (prop.CanWrite) + prop.SetValue(calibResults, prop.GetValue(calibRes, null), null); + } + return true; + } + } + catch (Exception e) + { + errorMsg = e.Message; + return false; + } + + return false; + } } } \ No newline at end of file