recalibrations - +0.3%

This commit is contained in:
Stoyan Zlatev
2025-06-06 16:12:39 +02:00
parent 00a873c174
commit fc0d211706
11 changed files with 386 additions and 129 deletions
+22 -9
View File
@@ -53,6 +53,7 @@
this.btnBatLife = new System.Windows.Forms.Button();
this.btnRadioPressure = new System.Windows.Forms.Button();
this.nundCalResultID = new System.Windows.Forms.NumericUpDown();
this.SetPfads2Plus03 = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.registerGridView)).BeginInit();
this.pnlBussy.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.nundCalResultID)).BeginInit();
@@ -95,9 +96,9 @@
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.registerGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.registerGridView.Location = new System.Drawing.Point(8, 184);
this.registerGridView.Location = new System.Drawing.Point(8, 171);
this.registerGridView.Name = "registerGridView";
this.registerGridView.Size = new System.Drawing.Size(670, 370);
this.registerGridView.Size = new System.Drawing.Size(679, 370);
this.registerGridView.TabIndex = 3;
this.registerGridView.CellClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.registerGridView_CellClick);
this.registerGridView.CellEndEdit += new System.Windows.Forms.DataGridViewCellEventHandler(this.registerGridView_CellEndEdit);
@@ -146,9 +147,9 @@
this.pnlBussy.Controls.Add(this.lblAction);
this.pnlBussy.Controls.Add(this.probarBussy);
this.pnlBussy.Controls.Add(this.label3);
this.pnlBussy.Location = new System.Drawing.Point(5, 156);
this.pnlBussy.Location = new System.Drawing.Point(8, 171);
this.pnlBussy.Name = "pnlBussy";
this.pnlBussy.Size = new System.Drawing.Size(695, 398);
this.pnlBussy.Size = new System.Drawing.Size(704, 398);
this.pnlBussy.TabIndex = 51;
this.pnlBussy.Visible = false;
//
@@ -180,7 +181,7 @@
| System.Windows.Forms.AnchorStyles.Right)));
this.probarBussy.Location = new System.Drawing.Point(12, 286);
this.probarBussy.Name = "probarBussy";
this.probarBussy.Size = new System.Drawing.Size(671, 23);
this.probarBussy.Size = new System.Drawing.Size(680, 23);
this.probarBussy.TabIndex = 1;
//
// label3
@@ -237,9 +238,9 @@
//
// btnStoreAll
//
this.btnStoreAll.Location = new System.Drawing.Point(636, 12);
this.btnStoreAll.Location = new System.Drawing.Point(635, 12);
this.btnStoreAll.Name = "btnStoreAll";
this.btnStoreAll.Size = new System.Drawing.Size(52, 73);
this.btnStoreAll.Size = new System.Drawing.Size(52, 55);
this.btnStoreAll.TabIndex = 62;
this.btnStoreAll.Text = "Store All";
this.btnStoreAll.UseVisualStyleBackColor = true;
@@ -264,7 +265,7 @@
//
this.btnBatLife.Location = new System.Drawing.Point(516, 116);
this.btnBatLife.Name = "btnBatLife";
this.btnBatLife.Size = new System.Drawing.Size(110, 30);
this.btnBatLife.Size = new System.Drawing.Size(114, 30);
this.btnBatLife.TabIndex = 71;
this.btnBatLife.Text = "Lifetime";
this.btnBatLife.UseVisualStyleBackColor = true;
@@ -292,11 +293,22 @@
this.nundCalResultID.Size = new System.Drawing.Size(114, 20);
this.nundCalResultID.TabIndex = 73;
//
// SetPfads2Plus03
//
this.SetPfads2Plus03.Location = new System.Drawing.Point(635, 80);
this.SetPfads2Plus03.Name = "SetPfads2Plus03";
this.SetPfads2Plus03.Size = new System.Drawing.Size(52, 66);
this.SetPfads2Plus03.TabIndex = 74;
this.SetPfads2Plus03.Text = "Finger weg!";
this.SetPfads2Plus03.UseVisualStyleBackColor = true;
this.SetPfads2Plus03.Click += new System.EventHandler(this.SetPfads2Plus03_Click);
//
// 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.ClientSize = new System.Drawing.Size(704, 553);
this.Controls.Add(this.SetPfads2Plus03);
this.Controls.Add(this.nundCalResultID);
this.Controls.Add(this.btnRadioPressure);
this.Controls.Add(this.btnBatLife);
@@ -352,5 +364,6 @@
private System.Windows.Forms.Button btnBatLife;
private System.Windows.Forms.Button btnRadioPressure;
private System.Windows.Forms.NumericUpDown nundCalResultID;
private System.Windows.Forms.Button SetPfads2Plus03;
}
}
@@ -5,10 +5,12 @@ using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Reflection;
using System.Text;
using System.Threading;
@@ -2260,5 +2262,183 @@ namespace Xylem.Common.Ui.GenesisToolBox
return false;
}
private void SetPfads2Plus03_Click(object sender, EventArgs args)
{
if (this._currentGenesis?.IsLoggedOn == false)
{
MessageBox.Show("Not connected!");
return;
}
var p1Cal = default(int);
var p2Cal = default(int);
var p3Cal = default(int);
try
{
p1Cal = RegisterConverter.ByteArrayToValue<int>(this._currentGenesis.ReadRegister(Register.Genesisflow.CalFactor1));
p2Cal = RegisterConverter.ByteArrayToValue<int>(this._currentGenesis.ReadRegister(Register.Genesisflow.CalFactor2));
p3Cal = RegisterConverter.ByteArrayToValue<int>(this._currentGenesis.ReadRegister(Register.Genesisflow.CalFactor3));
}
catch (Exception eRead)
{
MessageBox.Show($"Read exception: {eRead}");
return;
}
var httpClient = new HttpClient();
var values = new Q3Calibration();
try
{
using (var httpResponse = httpClient.GetAsync(ServiceUrls.GetQ3CalibrationsURI(this._currentPcbId)).Result)
{
var content = httpResponse.Content.ReadAsStringAsync().Result;
if (httpResponse.IsSuccessStatusCode)
{
try
{
values = JsonConvert.DeserializeObject<Q3Calibration>(content);
}
catch (Exception eParse)
{
MessageBox.Show($"Parse exception: {eParse}");
return;
}
}
else
{
MessageBox.Show($"Error: {content}");
return;
}
}
}
catch (Exception eHttp)
{
MessageBox.Show($"Http exception: {eHttp}");
return;
}
if (values.P1Off != 0.30003)
{
try
{
p1Cal = (int)Math.Round(p1Cal * (1 + 0.6 / 100), 0);
p2Cal = (int)Math.Round(p2Cal * (1 + 0.6 / 100), 0);
p2Cal = (int)Math.Round(p2Cal * (1 + 0.6 / 100), 0);
}
catch (Exception eCalc)
{
MessageBox.Show($"Calculation exception: {eCalc}");
return;
}
try
{
this._currentGenesis.WriteRegister(Register.Genesisflow.CalFactor1, p1Cal);
this._currentGenesis.WriteRegister(Register.Genesisflow.CalFactor2, p2Cal);
this._currentGenesis.WriteRegister(Register.Genesisflow.CalFactor3, p3Cal);
this._currentGenesis.WriteRegister(Register.Genesisflow.StoreCalibration, 1);
}
catch (Exception eWrite)
{
MessageBox.Show($"Write exception: {eWrite}");
return;
}
values.P1Off = 0.30003;
values.P1Cal = p1Cal;
values.P2Off = 0.30003;
values.P2Cal = p2Cal;
values.P3Off = 0.30003;
values.P3Cal = p3Cal;
var newValuesWriten = false;
try
{
var requestUri = ServiceUrls.Q3CalibrationResultURL;
var requestJson = JsonConvert.SerializeObject(values);
var requestContent = new StringContent(requestJson, Encoding.UTF8, "application/json");
using (var httpResponse = httpClient.PostAsync(requestUri, requestContent).Result)
{
var content = httpResponse.Content.ReadAsStringAsync().Result;
if (httpResponse.IsSuccessStatusCode && int.TryParse($"{content}", out var rowsAffected))
{
newValuesWriten = rowsAffected > 0;
}
else
{
MessageBox.Show($"Error: {content}");
return;
}
}
}
catch (Exception eHttp)
{
MessageBox.Show($"Http exception: {eHttp}");
return;
}
if (newValuesWriten)
{
foreach (var row in this._dataTable.Rows)
{
if (row is DataRow dataRow && dataRow["Name"] is string registerName)
{
dataRow["isChecked"] = registerName == Register.Genesisflow.CalFactor1
|| registerName == Register.Genesisflow.CalFactor2
|| registerName == Register.Genesisflow.CalFactor3;
}
}
this.btnRead_Click(sender, args);
}
else
{
MessageBox.Show($"Q3Calibration values are not saved!");
return;
}
}
else
{
MessageBox.Show($"Already recalibrated!");
return;
}
}
}
public class Q3Calibration
{
public int PcbId { get; set; }
public int P1Cal { get; set; }
public double P1Off { get; set; }
public int P2Cal { get; set; }
public double P2Off { get; set; }
public int P3Cal { get; set; }
public double P3Off { get; set; }
public DateTime Date { get; set; } = DateTime.Now;
}
}