TempCalibration: auf mehrere flanschen
This commit is contained in:
+1
-1
@@ -1 +1 @@
|
|||||||
8fbe991b217e7692af4817ad205b768685aa5a72
|
89102b0142e574de38a9f47d370f3334e5e6c268
|
||||||
|
|||||||
+1
-1
@@ -1 +1 @@
|
|||||||
1babc7d629fd8c486aff20f4990c117c2e58a68f
|
338bdd8d71c148c9df0972f903098eb23eacf0c9
|
||||||
|
|||||||
+48
-47
@@ -33,11 +33,12 @@ namespace Xylem.Common.Ui.GenesisToolBox
|
|||||||
this.components = new System.ComponentModel.Container();
|
this.components = new System.ComponentModel.Container();
|
||||||
this.timer1 = new System.Windows.Forms.Timer(this.components);
|
this.timer1 = new System.Windows.Forms.Timer(this.components);
|
||||||
this.timer2 = new System.Windows.Forms.Timer(this.components);
|
this.timer2 = new System.Windows.Forms.Timer(this.components);
|
||||||
this.automaticCalibrationTabControl = new System.Windows.Forms.TabControl();
|
this.multiflancshCalibration = new System.Windows.Forms.TabControl();
|
||||||
this.tabPage1 = new System.Windows.Forms.TabPage();
|
this.tabPage1 = new System.Windows.Forms.TabPage();
|
||||||
this.btnRefreshLut = new System.Windows.Forms.Button();
|
this.btnRefreshLut = new System.Windows.Forms.Button();
|
||||||
this.txtLuts = new System.Windows.Forms.TextBox();
|
this.txtLuts = new System.Windows.Forms.TextBox();
|
||||||
this.tabPage2 = new System.Windows.Forms.TabPage();
|
this.tabPage2 = new System.Windows.Forms.TabPage();
|
||||||
|
this.txtComport = new System.Windows.Forms.TextBox();
|
||||||
this.lblCheck = new System.Windows.Forms.Label();
|
this.lblCheck = new System.Windows.Forms.Label();
|
||||||
this.label9 = new System.Windows.Forms.Label();
|
this.label9 = new System.Windows.Forms.Label();
|
||||||
this.btnCheck = new System.Windows.Forms.Button();
|
this.btnCheck = new System.Windows.Forms.Button();
|
||||||
@@ -58,6 +59,7 @@ namespace Xylem.Common.Ui.GenesisToolBox
|
|||||||
this.automaticContentBox = new System.Windows.Forms.RichTextBox();
|
this.automaticContentBox = new System.Windows.Forms.RichTextBox();
|
||||||
this.autometicControlsSplitter = new System.Windows.Forms.Splitter();
|
this.autometicControlsSplitter = new System.Windows.Forms.Splitter();
|
||||||
this.automaticControlsPanel = new System.Windows.Forms.Panel();
|
this.automaticControlsPanel = new System.Windows.Forms.Panel();
|
||||||
|
this.connectedMeters = new System.Windows.Forms.ListView();
|
||||||
this.saveSettingsBtn = new System.Windows.Forms.Button();
|
this.saveSettingsBtn = new System.Windows.Forms.Button();
|
||||||
this.messurementDauerMS = new System.Windows.Forms.TextBox();
|
this.messurementDauerMS = new System.Windows.Forms.TextBox();
|
||||||
this.label3 = new System.Windows.Forms.Label();
|
this.label3 = new System.Windows.Forms.Label();
|
||||||
@@ -67,11 +69,9 @@ namespace Xylem.Common.Ui.GenesisToolBox
|
|||||||
this.label2 = new System.Windows.Forms.Label();
|
this.label2 = new System.Windows.Forms.Label();
|
||||||
this.GMHPort = new System.Windows.Forms.TextBox();
|
this.GMHPort = new System.Windows.Forms.TextBox();
|
||||||
this.label1 = new System.Windows.Forms.Label();
|
this.label1 = new System.Windows.Forms.Label();
|
||||||
this.tabPage4 = new System.Windows.Forms.TabPage();
|
|
||||||
this.timer3 = new System.Windows.Forms.Timer(this.components);
|
this.timer3 = new System.Windows.Forms.Timer(this.components);
|
||||||
this.mainMenuStrip = new System.Windows.Forms.MenuStrip();
|
this.mainMenuStrip = new System.Windows.Forms.MenuStrip();
|
||||||
this.txtComport = new System.Windows.Forms.TextBox();
|
this.multiflancshCalibration.SuspendLayout();
|
||||||
this.automaticCalibrationTabControl.SuspendLayout();
|
|
||||||
this.tabPage1.SuspendLayout();
|
this.tabPage1.SuspendLayout();
|
||||||
this.tabPage2.SuspendLayout();
|
this.tabPage2.SuspendLayout();
|
||||||
this.tabPage3.SuspendLayout();
|
this.tabPage3.SuspendLayout();
|
||||||
@@ -89,23 +89,22 @@ namespace Xylem.Common.Ui.GenesisToolBox
|
|||||||
//
|
//
|
||||||
this.timer2.Tick += new System.EventHandler(this.timer2_Tick);
|
this.timer2.Tick += new System.EventHandler(this.timer2_Tick);
|
||||||
//
|
//
|
||||||
// automaticCalibrationTabControl
|
// multiflancshCalibration
|
||||||
//
|
//
|
||||||
this.automaticCalibrationTabControl.Controls.Add(this.tabPage1);
|
this.multiflancshCalibration.Controls.Add(this.tabPage1);
|
||||||
this.automaticCalibrationTabControl.Controls.Add(this.tabPage2);
|
this.multiflancshCalibration.Controls.Add(this.tabPage2);
|
||||||
this.automaticCalibrationTabControl.Controls.Add(this.tabPage3);
|
this.multiflancshCalibration.Controls.Add(this.tabPage3);
|
||||||
this.automaticCalibrationTabControl.Controls.Add(this.AutomaticCalibrationTab);
|
this.multiflancshCalibration.Controls.Add(this.AutomaticCalibrationTab);
|
||||||
this.automaticCalibrationTabControl.Controls.Add(this.tabPage4);
|
this.multiflancshCalibration.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||||
this.automaticCalibrationTabControl.Dock = System.Windows.Forms.DockStyle.Fill;
|
this.multiflancshCalibration.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||||
this.automaticCalibrationTabControl.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
this.multiflancshCalibration.Location = new System.Drawing.Point(0, 24);
|
||||||
this.automaticCalibrationTabControl.Location = new System.Drawing.Point(0, 24);
|
this.multiflancshCalibration.Margin = new System.Windows.Forms.Padding(0);
|
||||||
this.automaticCalibrationTabControl.Margin = new System.Windows.Forms.Padding(0);
|
this.multiflancshCalibration.Name = "multiflancshCalibration";
|
||||||
this.automaticCalibrationTabControl.Name = "automaticCalibrationTabControl";
|
this.multiflancshCalibration.Padding = new System.Drawing.Point(0, 0);
|
||||||
this.automaticCalibrationTabControl.Padding = new System.Drawing.Point(0, 0);
|
this.multiflancshCalibration.SelectedIndex = 0;
|
||||||
this.automaticCalibrationTabControl.SelectedIndex = 0;
|
this.multiflancshCalibration.Size = new System.Drawing.Size(1225, 676);
|
||||||
this.automaticCalibrationTabControl.Size = new System.Drawing.Size(1225, 676);
|
this.multiflancshCalibration.TabIndex = 55;
|
||||||
this.automaticCalibrationTabControl.TabIndex = 55;
|
this.multiflancshCalibration.Tag = "";
|
||||||
this.automaticCalibrationTabControl.Tag = "";
|
|
||||||
//
|
//
|
||||||
// tabPage1
|
// tabPage1
|
||||||
//
|
//
|
||||||
@@ -151,6 +150,19 @@ namespace Xylem.Common.Ui.GenesisToolBox
|
|||||||
this.tabPage2.Text = "Manual check temp";
|
this.tabPage2.Text = "Manual check temp";
|
||||||
this.tabPage2.UseVisualStyleBackColor = true;
|
this.tabPage2.UseVisualStyleBackColor = true;
|
||||||
//
|
//
|
||||||
|
// txtComport
|
||||||
|
//
|
||||||
|
this.txtComport.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
|
||||||
|
| System.Windows.Forms.AnchorStyles.Right)));
|
||||||
|
this.txtComport.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||||
|
this.txtComport.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||||
|
this.txtComport.Location = new System.Drawing.Point(77, 24);
|
||||||
|
this.txtComport.Margin = new System.Windows.Forms.Padding(0);
|
||||||
|
this.txtComport.MinimumSize = new System.Drawing.Size(2, 25);
|
||||||
|
this.txtComport.Name = "txtComport";
|
||||||
|
this.txtComport.Size = new System.Drawing.Size(318, 24);
|
||||||
|
this.txtComport.TabIndex = 55;
|
||||||
|
//
|
||||||
// lblCheck
|
// lblCheck
|
||||||
//
|
//
|
||||||
this.lblCheck.AutoSize = true;
|
this.lblCheck.AutoSize = true;
|
||||||
@@ -363,6 +375,7 @@ namespace Xylem.Common.Ui.GenesisToolBox
|
|||||||
// automaticControlsPanel
|
// automaticControlsPanel
|
||||||
//
|
//
|
||||||
this.automaticControlsPanel.BackColor = System.Drawing.SystemColors.Menu;
|
this.automaticControlsPanel.BackColor = System.Drawing.SystemColors.Menu;
|
||||||
|
this.automaticControlsPanel.Controls.Add(this.connectedMeters);
|
||||||
this.automaticControlsPanel.Controls.Add(this.saveSettingsBtn);
|
this.automaticControlsPanel.Controls.Add(this.saveSettingsBtn);
|
||||||
this.automaticControlsPanel.Controls.Add(this.messurementDauerMS);
|
this.automaticControlsPanel.Controls.Add(this.messurementDauerMS);
|
||||||
this.automaticControlsPanel.Controls.Add(this.label3);
|
this.automaticControlsPanel.Controls.Add(this.label3);
|
||||||
@@ -379,6 +392,17 @@ namespace Xylem.Common.Ui.GenesisToolBox
|
|||||||
this.automaticControlsPanel.Size = new System.Drawing.Size(328, 647);
|
this.automaticControlsPanel.Size = new System.Drawing.Size(328, 647);
|
||||||
this.automaticControlsPanel.TabIndex = 0;
|
this.automaticControlsPanel.TabIndex = 0;
|
||||||
//
|
//
|
||||||
|
// connectedMeters
|
||||||
|
//
|
||||||
|
this.connectedMeters.HideSelection = false;
|
||||||
|
this.connectedMeters.Location = new System.Drawing.Point(5, 285);
|
||||||
|
this.connectedMeters.MultiSelect = false;
|
||||||
|
this.connectedMeters.Name = "connectedMeters";
|
||||||
|
this.connectedMeters.Size = new System.Drawing.Size(318, 356);
|
||||||
|
this.connectedMeters.TabIndex = 17;
|
||||||
|
this.connectedMeters.UseCompatibleStateImageBehavior = false;
|
||||||
|
this.connectedMeters.ItemSelectionChanged += new System.Windows.Forms.ListViewItemSelectionChangedEventHandler(this.MeterSelected);
|
||||||
|
//
|
||||||
// saveSettingsBtn
|
// saveSettingsBtn
|
||||||
//
|
//
|
||||||
this.saveSettingsBtn.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
|
this.saveSettingsBtn.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
|
||||||
@@ -500,16 +524,6 @@ namespace Xylem.Common.Ui.GenesisToolBox
|
|||||||
this.label1.Text = "Messgerät (COM port)";
|
this.label1.Text = "Messgerät (COM port)";
|
||||||
this.label1.TextAlign = System.Drawing.ContentAlignment.BottomLeft;
|
this.label1.TextAlign = System.Drawing.ContentAlignment.BottomLeft;
|
||||||
//
|
//
|
||||||
// tabPage4
|
|
||||||
//
|
|
||||||
this.tabPage4.Location = new System.Drawing.Point(4, 25);
|
|
||||||
this.tabPage4.Name = "tabPage4";
|
|
||||||
this.tabPage4.Padding = new System.Windows.Forms.Padding(3);
|
|
||||||
this.tabPage4.Size = new System.Drawing.Size(1217, 647);
|
|
||||||
this.tabPage4.TabIndex = 4;
|
|
||||||
this.tabPage4.Text = "tabPage4";
|
|
||||||
this.tabPage4.UseVisualStyleBackColor = true;
|
|
||||||
//
|
|
||||||
// timer3
|
// timer3
|
||||||
//
|
//
|
||||||
this.timer3.Interval = 10000;
|
this.timer3.Interval = 10000;
|
||||||
@@ -524,30 +538,17 @@ namespace Xylem.Common.Ui.GenesisToolBox
|
|||||||
this.mainMenuStrip.TabIndex = 57;
|
this.mainMenuStrip.TabIndex = 57;
|
||||||
this.mainMenuStrip.Text = "menuStrip1";
|
this.mainMenuStrip.Text = "menuStrip1";
|
||||||
//
|
//
|
||||||
// txtComport
|
|
||||||
//
|
|
||||||
this.txtComport.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
|
|
||||||
| System.Windows.Forms.AnchorStyles.Right)));
|
|
||||||
this.txtComport.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
|
||||||
this.txtComport.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
|
||||||
this.txtComport.Location = new System.Drawing.Point(77, 24);
|
|
||||||
this.txtComport.Margin = new System.Windows.Forms.Padding(0);
|
|
||||||
this.txtComport.MinimumSize = new System.Drawing.Size(2, 25);
|
|
||||||
this.txtComport.Name = "txtComport";
|
|
||||||
this.txtComport.Size = new System.Drawing.Size(318, 25);
|
|
||||||
this.txtComport.TabIndex = 55;
|
|
||||||
//
|
|
||||||
// FrmTempMeter
|
// FrmTempMeter
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
this.ClientSize = new System.Drawing.Size(1225, 700);
|
this.ClientSize = new System.Drawing.Size(1225, 700);
|
||||||
this.Controls.Add(this.automaticCalibrationTabControl);
|
this.Controls.Add(this.multiflancshCalibration);
|
||||||
this.Controls.Add(this.mainMenuStrip);
|
this.Controls.Add(this.mainMenuStrip);
|
||||||
this.MainMenuStrip = this.mainMenuStrip;
|
this.MainMenuStrip = this.mainMenuStrip;
|
||||||
this.Name = "FrmTempMeter";
|
this.Name = "FrmTempMeter";
|
||||||
this.Text = "FrmTempMeter";
|
this.Text = "FrmTempMeter";
|
||||||
this.automaticCalibrationTabControl.ResumeLayout(false);
|
this.multiflancshCalibration.ResumeLayout(false);
|
||||||
this.tabPage1.ResumeLayout(false);
|
this.tabPage1.ResumeLayout(false);
|
||||||
this.tabPage1.PerformLayout();
|
this.tabPage1.PerformLayout();
|
||||||
this.tabPage2.ResumeLayout(false);
|
this.tabPage2.ResumeLayout(false);
|
||||||
@@ -566,7 +567,7 @@ namespace Xylem.Common.Ui.GenesisToolBox
|
|||||||
#endregion
|
#endregion
|
||||||
private System.Windows.Forms.Timer timer1;
|
private System.Windows.Forms.Timer timer1;
|
||||||
private System.Windows.Forms.Timer timer2;
|
private System.Windows.Forms.Timer timer2;
|
||||||
private System.Windows.Forms.TabControl automaticCalibrationTabControl;
|
private System.Windows.Forms.TabControl multiflancshCalibration;
|
||||||
private System.Windows.Forms.TabPage tabPage1;
|
private System.Windows.Forms.TabPage tabPage1;
|
||||||
private System.Windows.Forms.Button btnRefreshLut;
|
private System.Windows.Forms.Button btnRefreshLut;
|
||||||
private System.Windows.Forms.TextBox txtLuts;
|
private System.Windows.Forms.TextBox txtLuts;
|
||||||
@@ -602,7 +603,7 @@ namespace Xylem.Common.Ui.GenesisToolBox
|
|||||||
private System.Windows.Forms.TextBox messurementDauerMS;
|
private System.Windows.Forms.TextBox messurementDauerMS;
|
||||||
private System.Windows.Forms.Label label3;
|
private System.Windows.Forms.Label label3;
|
||||||
private System.Windows.Forms.Button saveSettingsBtn;
|
private System.Windows.Forms.Button saveSettingsBtn;
|
||||||
private System.Windows.Forms.TabPage tabPage4;
|
|
||||||
private System.Windows.Forms.TextBox txtComport;
|
private System.Windows.Forms.TextBox txtComport;
|
||||||
|
private System.Windows.Forms.ListView connectedMeters;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -47,6 +47,7 @@
|
|||||||
this.InitializeComponent();
|
this.InitializeComponent();
|
||||||
this.InitializeContent();
|
this.InitializeContent();
|
||||||
|
|
||||||
|
this.meterBatch = new MeterBatch();
|
||||||
this.reftempRangeReq = new List<RefTempRange>()
|
this.reftempRangeReq = new List<RefTempRange>()
|
||||||
{
|
{
|
||||||
new RefTempRange() { Min = 7, Max= 9 },
|
new RefTempRange() { Min = 7, Max= 9 },
|
||||||
@@ -61,70 +62,64 @@
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private void BtnConnect_Click(Object sender, EventArgs e)
|
private void BtnConnect_Click(Object sender, EventArgs e)
|
||||||
{
|
=> this.Connect();
|
||||||
this.Connect();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Connect()
|
private void Connect()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (!int.TryParse($"{this.slotsList.SelectedItem}", out var slotNr))
|
if (int.TryParse($"{this.slotsList.SelectedItem}", out var slotNr))
|
||||||
{
|
{
|
||||||
return;
|
var meter = new ZeroFlowGenesisMeter(slotNr, 3, false);
|
||||||
|
this.meterBatch.AddMeter(meter);
|
||||||
|
|
||||||
|
Task.Factory.StartNew(() =>
|
||||||
|
{
|
||||||
|
meter.Login();
|
||||||
|
|
||||||
|
if (!meter.IsLoggedOn)
|
||||||
|
{
|
||||||
|
Thread.Sleep(2000);
|
||||||
|
meter.Login();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!meter.IsLoggedOn)
|
||||||
|
{
|
||||||
|
SetEnabled(ProgrammState.Start);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.currentGenesis = meter;
|
||||||
|
|
||||||
|
meter.InitMeasurement();
|
||||||
|
|
||||||
|
meter.WriteRegister(Register.Genesisflow.SampleRate, (byte)10, checkRegister: true);
|
||||||
|
meter.WriteRegister("GENESISFLOW_MaxValidDeltaToF", 4294967295, checkRegister: true);
|
||||||
|
meter.WriteRegister("GENESISFLOW_MaxValidToF", 4294967295, checkRegister: true);
|
||||||
|
meter.WriteRegister("GENESISFLOW_MinValidToF", (uint)0, checkRegister: true);
|
||||||
|
|
||||||
|
meter.StartMeasurement();
|
||||||
|
|
||||||
|
InvokeOnUIThread(new Action(() =>
|
||||||
|
{
|
||||||
|
txtLuts.Text = GetLutsText(meter.PcbId);
|
||||||
|
|
||||||
|
if (lutIsMissing)
|
||||||
|
{
|
||||||
|
txtLuts.BackColor = Color.IndianRed;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
txtLuts.BackColor = Color.LightGreen;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.pcbidTextBox.Text = meter.PcbId;
|
||||||
|
this.SetEnabled(ProgrammState.Connected);
|
||||||
|
this.UpdateConnectedMetersList();
|
||||||
|
}));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
//var drive = 1;
|
|
||||||
currentGenesis?.DisposeMeter();
|
|
||||||
//dispose old meter
|
|
||||||
meterBatch = new MeterBatch();
|
|
||||||
currentGenesis = null;
|
|
||||||
Thread.Sleep(200);
|
|
||||||
|
|
||||||
//assign new meter and assign meter to FW update file if this exists
|
|
||||||
currentGenesis = new ZeroFlowGenesisMeter(slotNr, 3, false);
|
|
||||||
|
|
||||||
//_currentGenesis.SetupFromConfigFile(slotNr);
|
|
||||||
meterBatch.AddMeter(currentGenesis);
|
|
||||||
|
|
||||||
Task.Factory.StartNew(() =>
|
|
||||||
{
|
|
||||||
meterBatch.MetersLogin();
|
|
||||||
|
|
||||||
if (!currentGenesis.IsLoggedOn)
|
|
||||||
{
|
|
||||||
Thread.Sleep(2000);
|
|
||||||
meterBatch.MetersLogin();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!currentGenesis.IsLoggedOn)
|
|
||||||
{
|
|
||||||
SetEnabled(ProgrammState.Start);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
var a = GetLutsText(currentGenesis.PcbId);
|
|
||||||
currentGenesis.InitMeasurement();
|
|
||||||
InvokeOnUIThread(new Action(() =>
|
|
||||||
{
|
|
||||||
|
|
||||||
txtLuts.Text = a;
|
|
||||||
if (lutIsMissing)
|
|
||||||
{
|
|
||||||
txtLuts.BackColor = Color.IndianRed;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
txtLuts.BackColor = Color.LightGreen;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.pcbidTextBox.Text = currentGenesis.PcbId;
|
|
||||||
this.SetEnabled(ProgrammState.Connected);
|
|
||||||
|
|
||||||
}));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -134,6 +129,30 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void UpdateConnectedMetersList()
|
||||||
|
{
|
||||||
|
this.InvokeOnUIThread(() =>
|
||||||
|
{
|
||||||
|
this.connectedMeters.Clear();
|
||||||
|
|
||||||
|
foreach (var meter in this.meterBatch.ListOfMeters)
|
||||||
|
{
|
||||||
|
if (meter is ZeroFlowGenesisMeter gns)
|
||||||
|
{
|
||||||
|
var pcbId = gns.PcbId;
|
||||||
|
var connected = !string.IsNullOrWhiteSpace(pcbId);
|
||||||
|
var item = new ListViewItem
|
||||||
|
{
|
||||||
|
BackColor = connected ? Color.LightGreen : Color.IndianRed,
|
||||||
|
Text = pcbId,
|
||||||
|
};
|
||||||
|
|
||||||
|
this.connectedMeters.Items.Add(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private void btnRefreshLut_Click(Object sender, EventArgs e)
|
private void btnRefreshLut_Click(Object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(currentGenesis?.PcbId))
|
if (!string.IsNullOrEmpty(currentGenesis?.PcbId))
|
||||||
@@ -242,10 +261,7 @@
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
currentGenesis.StartRecordData();
|
currentGenesis.StartRecordData();
|
||||||
timer1.Enabled = true;
|
timer1.Enabled = true;
|
||||||
|
|
||||||
@@ -624,7 +640,8 @@
|
|||||||
TextAlign = ContentAlignment.MiddleCenter,
|
TextAlign = ContentAlignment.MiddleCenter,
|
||||||
Margin = new Padding(10, 0, 0, 0),
|
Margin = new Padding(10, 0, 0, 0),
|
||||||
Padding = new Padding(10, 0, 10, 0),
|
Padding = new Padding(10, 0, 10, 0),
|
||||||
BackColor = Color.LightGray
|
BackColor = Color.LightGray,
|
||||||
|
Visible = true
|
||||||
};
|
};
|
||||||
this.connectBtn.Click += this.BtnConnect_Click;
|
this.connectBtn.Click += this.BtnConnect_Click;
|
||||||
|
|
||||||
@@ -636,7 +653,8 @@
|
|||||||
TextAlign = ContentAlignment.MiddleCenter,
|
TextAlign = ContentAlignment.MiddleCenter,
|
||||||
Margin = new Padding(10, 0, 0, 0),
|
Margin = new Padding(10, 0, 0, 0),
|
||||||
Padding = new Padding(10, 0, 10, 0),
|
Padding = new Padding(10, 0, 10, 0),
|
||||||
BackColor = Color.LightGray
|
BackColor = Color.LightGray,
|
||||||
|
Visible = true
|
||||||
};
|
};
|
||||||
this.disconnectBtn.Click += this.BtnDisconnect_Click;
|
this.disconnectBtn.Click += this.BtnDisconnect_Click;
|
||||||
|
|
||||||
@@ -660,7 +678,7 @@
|
|||||||
this.mainMenuStrip.Items.Add(this.disconnectBtn);
|
this.mainMenuStrip.Items.Add(this.disconnectBtn);
|
||||||
this.mainMenuStrip.Items.Add(this.testBtn);
|
this.mainMenuStrip.Items.Add(this.testBtn);
|
||||||
|
|
||||||
this.automaticCalibrationTabControl.GotFocus += (Object sender, EventArgs e) =>
|
this.multiflancshCalibration.GotFocus += (Object sender, EventArgs e) =>
|
||||||
{
|
{
|
||||||
this.GMHPort.Text = Appsettings.GMHPort.ToString();
|
this.GMHPort.Text = Appsettings.GMHPort.ToString();
|
||||||
this.messurementStepMS.Text = Appsettings.MessurementStep.ToString();
|
this.messurementStepMS.Text = Appsettings.MessurementStep.ToString();
|
||||||
@@ -674,7 +692,7 @@
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
this.currentGenesis.DisposeMeter();
|
this.currentGenesis.Dispose();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
@@ -682,16 +700,17 @@
|
|||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
this.currentGenesis = null;
|
this.meterBatch.RemoveMeter(this.currentGenesis);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.InvokeOnUIThread(new Action(() =>
|
this.InvokeOnUIThread(new Action(() =>
|
||||||
{
|
{
|
||||||
|
this.currentGenesis = null;
|
||||||
this.txtLuts.Text = string.Empty;
|
this.txtLuts.Text = string.Empty;
|
||||||
this.txtLuts.BackColor = Color.White;
|
this.txtLuts.BackColor = Color.White;
|
||||||
this.pcbidTextBox.Text = "not connected";
|
this.pcbidTextBox.Text = "not connected";
|
||||||
this.SetEnabled(ProgrammState.Start);
|
this.SetEnabled(ProgrammState.Start);
|
||||||
|
this.UpdateConnectedMetersList();
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -707,8 +726,6 @@
|
|||||||
this.btnAddLut.Enabled = false;
|
this.btnAddLut.Enabled = false;
|
||||||
this.nudRef.Visible = false;
|
this.nudRef.Visible = false;
|
||||||
this.btnRefreshLut.Enabled = false;
|
this.btnRefreshLut.Enabled = false;
|
||||||
this.disconnectBtn.Visible = false;
|
|
||||||
this.connectBtn.Visible = true;
|
|
||||||
break;
|
break;
|
||||||
case ProgrammState.Connected:
|
case ProgrammState.Connected:
|
||||||
this.btnStartRecord.Enabled = true;
|
this.btnStartRecord.Enabled = true;
|
||||||
@@ -716,8 +733,6 @@
|
|||||||
this.btnAddLut.Enabled = false;
|
this.btnAddLut.Enabled = false;
|
||||||
this.nudRef.Visible = false;
|
this.nudRef.Visible = false;
|
||||||
this.btnRefreshLut.Enabled = true;
|
this.btnRefreshLut.Enabled = true;
|
||||||
this.disconnectBtn.Visible = true;
|
|
||||||
this.connectBtn.Visible = false;
|
|
||||||
break;
|
break;
|
||||||
case ProgrammState.RecordRuning:
|
case ProgrammState.RecordRuning:
|
||||||
this.btnStartRecord.Enabled = false;
|
this.btnStartRecord.Enabled = false;
|
||||||
@@ -746,27 +761,18 @@
|
|||||||
|
|
||||||
private void StartAutomaticBtn_Clicked(object sender, EventArgs args)
|
private void StartAutomaticBtn_Clicked(object sender, EventArgs args)
|
||||||
{
|
{
|
||||||
if (this.currentGenesis is null)
|
if (this.connectedMeters.Items.Count == 0)
|
||||||
{
|
{
|
||||||
MessageBox.Show(this, "Water meter not connected!", "Start aborted", MessageBoxButtons.OK);
|
MessageBox.Show(this, "There is no meter not connected!", "Start aborted", MessageBoxButtons.OK);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
this.currentGenesis?.WriteRegister(Register.Genesisflow.SampleRate, (byte)16, checkRegister: true);
|
|
||||||
this.currentGenesis?.WriteRegister("GENESISFLOW_MaxValidDeltaToF", 4294967295, checkRegister: true);
|
|
||||||
this.currentGenesis?.WriteRegister("GENESISFLOW_MaxValidToF", 4294967295, checkRegister: true);
|
|
||||||
this.currentGenesis?.WriteRegister("GENESISFLOW_MinValidToF", (uint)0, checkRegister: true);
|
|
||||||
this.currentGenesis?.StartRecordData();
|
|
||||||
|
|
||||||
this.automatic = true;
|
this.automatic = true;
|
||||||
this.start = DateTimeOffset.Now;
|
this.start = DateTimeOffset.Now;
|
||||||
|
this.automaticCalibration = new AutomaticTemperatureCalibration(this);
|
||||||
var pcbid = this.currentGenesis?.PcbId ?? "0000000000";
|
|
||||||
this.automaticCalibration = new AutomaticTemperatureCalibration(pcbid, this);
|
|
||||||
|
|
||||||
this.automaticCalibration.StartMessuring();
|
this.automaticCalibration.StartMessuring();
|
||||||
this.SetEnabled(ProgrammState.RecordRuning);
|
this.SetEnabled(ProgrammState.RecordRuning);
|
||||||
|
|
||||||
@@ -785,10 +791,12 @@
|
|||||||
{
|
{
|
||||||
this.automatic = false;
|
this.automatic = false;
|
||||||
|
|
||||||
this.automaticCalibration.StopMessuring();
|
|
||||||
|
|
||||||
this.MergeToAutoFile();
|
this.MergeToAutoFile();
|
||||||
|
|
||||||
|
this.automaticCalibration.StopMessuring();
|
||||||
|
this.meterBatch.Dispose();
|
||||||
|
this.meterBatch.RemoveAllMeters();
|
||||||
|
|
||||||
this.SetEnabled(ProgrammState.RecordStoped);
|
this.SetEnabled(ProgrammState.RecordStoped);
|
||||||
|
|
||||||
this.startAutomaticBtn.Enabled = true;
|
this.startAutomaticBtn.Enabled = true;
|
||||||
@@ -802,13 +810,12 @@
|
|||||||
|
|
||||||
public void StartRecording()
|
public void StartRecording()
|
||||||
{
|
{
|
||||||
try
|
foreach (var meter in this.meterBatch.ListOfMeters)
|
||||||
{
|
{
|
||||||
this.currentGenesis.StartRecordData();
|
if (meter is ZeroFlowGenesisMeter zfgnsm)
|
||||||
}
|
{
|
||||||
catch (Exception e)
|
zfgnsm.StartRecordData();
|
||||||
{
|
}
|
||||||
this.AddMessage($"{e}");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -821,7 +828,7 @@
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
var text = $"{message}{Environment.NewLine}" + this.automaticContentBox.Text;
|
var text = $"{message}{Environment.NewLine}" + this.automaticContentBox.Text;
|
||||||
text = text.Substring(0, Math.Min(5000, text?.Length ?? 0));
|
text = text.Substring(0, Math.Min(2000, text?.Length ?? 0));
|
||||||
|
|
||||||
this.automaticContentBox.ResetText();
|
this.automaticContentBox.ResetText();
|
||||||
this.automaticContentBox.AppendText(text);
|
this.automaticContentBox.AppendText(text);
|
||||||
@@ -841,6 +848,7 @@
|
|||||||
if (this.automaticCalibration != null)
|
if (this.automaticCalibration != null)
|
||||||
{
|
{
|
||||||
this.automaticCalibration.StopMessuring();
|
this.automaticCalibration.StopMessuring();
|
||||||
|
this.meterBatch.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
@@ -855,30 +863,6 @@
|
|||||||
base.OnClosed(args);
|
base.OnClosed(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Double GetAverageTOF()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (this.currentGenesis is null)
|
|
||||||
{
|
|
||||||
this.automaticCalibration.StopMessuring();
|
|
||||||
|
|
||||||
return double.MinValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.currentGenesis
|
|
||||||
.CurrentRecords
|
|
||||||
.Where(s => s.Channel == 2)
|
|
||||||
.Average(x => x.TotalTimeOfFlightS);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
this.AddMessage($"{e}");
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnFormClosed(FormClosedEventArgs e)
|
protected override void OnFormClosed(FormClosedEventArgs e)
|
||||||
=> this.BtnDisconnect_Click(default(object), EventArgs.Empty);
|
=> this.BtnDisconnect_Click(default(object), EventArgs.Empty);
|
||||||
|
|
||||||
@@ -904,5 +888,64 @@
|
|||||||
|
|
||||||
public void InvokeOnUIThread(Action action)
|
public void InvokeOnUIThread(Action action)
|
||||||
=> this.Invoke(action);
|
=> this.Invoke(action);
|
||||||
|
|
||||||
|
public IDictionary<String, Double> GetAverageTOFForeachMeter()
|
||||||
|
{
|
||||||
|
var results = new Dictionary<string, double>();
|
||||||
|
|
||||||
|
foreach (var meter in this.meterBatch.ListOfMeters)
|
||||||
|
{
|
||||||
|
if (meter is ZeroFlowGenesisMeter zfgnsm)
|
||||||
|
{
|
||||||
|
var avg = default(double);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
avg = zfgnsm
|
||||||
|
.CurrentRecords
|
||||||
|
.Where(s => s.Channel == 2)
|
||||||
|
.Average(x => x.TotalTimeOfFlightS);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
this.AddMessage(e.Message);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
zfgnsm.StartRecordData();
|
||||||
|
}
|
||||||
|
|
||||||
|
var pcbId = zfgnsm.PcbId;
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(pcbId))
|
||||||
|
{
|
||||||
|
pcbId = "---------";
|
||||||
|
}
|
||||||
|
|
||||||
|
results[pcbId] = avg;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void MeterSelected(Object sender, ListViewItemSelectionChangedEventArgs e)
|
||||||
|
{
|
||||||
|
var pcbId = e?.Item?.Text;
|
||||||
|
|
||||||
|
this.InvokeOnUIThread(() =>
|
||||||
|
{
|
||||||
|
foreach (var meter in this.meterBatch.ListOfMeters)
|
||||||
|
{
|
||||||
|
if (meter is ZeroFlowGenesisMeter zfgnsm && zfgnsm.PcbId == pcbId)
|
||||||
|
{
|
||||||
|
this.currentGenesis = zfgnsm;
|
||||||
|
this.pcbidTextBox.Text = pcbId;
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -130,6 +130,6 @@
|
|||||||
<value>278, 17</value>
|
<value>278, 17</value>
|
||||||
</metadata>
|
</metadata>
|
||||||
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
<value>120</value>
|
<value>42</value>
|
||||||
</metadata>
|
</metadata>
|
||||||
</root>
|
</root>
|
||||||
@@ -1,140 +1,103 @@
|
|||||||
namespace Xylem.Common.Ui.GenesisToolBox.Infrastructure
|
namespace Xylem.Common.Ui.GenesisToolBox.Infrastructure
|
||||||
{
|
{
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using System.Timers;
|
using System.Timers;
|
||||||
|
|
||||||
internal interface ITempMeterForm
|
internal interface ITempMeterForm
|
||||||
{
|
{
|
||||||
void AddMessage(string message);
|
void AddMessage(string message);
|
||||||
|
|
||||||
double GetAverageTOF();
|
|
||||||
|
|
||||||
void StartRecording();
|
void StartRecording();
|
||||||
|
|
||||||
void InvokeOnUIThread(Action action);
|
void InvokeOnUIThread(Action action);
|
||||||
|
|
||||||
|
IDictionary<string, double> GetAverageTOFForeachMeter();
|
||||||
}
|
}
|
||||||
|
|
||||||
partial class AutomaticTemperatureCalibration
|
partial class AutomaticTemperatureCalibration
|
||||||
{
|
{
|
||||||
private readonly string pcbId;
|
|
||||||
private readonly ITempMeterForm tempMeterForm;
|
private readonly ITempMeterForm tempMeterForm;
|
||||||
private readonly TemperatureSource temperatureSource;
|
private TemperatureSource temperatureSource;
|
||||||
|
private readonly string outputFile;
|
||||||
|
|
||||||
private string messurementsFile;
|
private Timer timer;
|
||||||
private Timer startTimer;
|
private bool hasHeaders;
|
||||||
private Timer resultsTimer;
|
|
||||||
|
|
||||||
public AutomaticTemperatureCalibration(string pcbId, ITempMeterForm genesisMeter)
|
public AutomaticTemperatureCalibration(ITempMeterForm tempMeterForm)
|
||||||
{
|
{
|
||||||
this.pcbId = pcbId;
|
this.tempMeterForm = tempMeterForm;
|
||||||
this.tempMeterForm = genesisMeter;
|
this.outputFile = Path.Combine(Appsettings.WorkingDirectory, $"{DateTime.Now:yyyy_MM_dd}_mesurements.txt");
|
||||||
|
|
||||||
try
|
Directory.CreateDirectory(Path.GetDirectoryName(this.outputFile));
|
||||||
{
|
File.AppendAllText(this.outputFile, default(string));
|
||||||
this.temperatureSource = new TemperatureSource();
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
this.tempMeterForm.AddMessage($"{e}");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void StartMessuring()
|
public void StartMessuring()
|
||||||
{
|
{
|
||||||
try
|
this.temperatureSource = new TemperatureSource();
|
||||||
|
this.tempMeterForm.StartRecording();
|
||||||
|
this.GetResults(null, null);
|
||||||
|
|
||||||
|
this.timer = new Timer()
|
||||||
{
|
{
|
||||||
this.messurementsFile = Path.Combine(Appsettings.WorkingDirectory, $"{this.pcbId}_{DateTime.Now:yyyyMMddHHmmss}_messurements.txt");
|
AutoReset = true,
|
||||||
|
Interval = Appsettings.MessurementStep,
|
||||||
File.AppendAllText(this.messurementsFile, string.Empty);
|
};
|
||||||
|
this.timer.Elapsed += this.GetResults;
|
||||||
this.resultsTimer = new Timer()
|
this.timer.Start();
|
||||||
{
|
|
||||||
AutoReset = true,
|
|
||||||
Interval = Appsettings.MessurementStep,
|
|
||||||
};
|
|
||||||
this.resultsTimer.Elapsed += this.StartGettingResults;
|
|
||||||
|
|
||||||
this.startTimer = new Timer
|
|
||||||
{
|
|
||||||
AutoReset = true,
|
|
||||||
Interval = Appsettings.MessurementDauer,
|
|
||||||
};
|
|
||||||
this.startTimer.Elapsed += this.StartMessuring;
|
|
||||||
|
|
||||||
this.StartMessuring(null, null);
|
|
||||||
this.startTimer.Start();
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
File.AppendAllText(this.messurementsFile, $"{e}{Environment.NewLine}");
|
|
||||||
|
|
||||||
this.tempMeterForm.AddMessage($"{e}");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void StartMessuring(Object sender, ElapsedEventArgs args)
|
private void GetResults(Object sender, ElapsedEventArgs args)
|
||||||
{
|
{
|
||||||
try
|
this.tempMeterForm.InvokeOnUIThread(() =>
|
||||||
{
|
{
|
||||||
if (this.resultsTimer.Enabled)
|
try
|
||||||
{
|
|
||||||
this.resultsTimer.Stop();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// this.tempMeterForm.StartRecording();
|
|
||||||
this.resultsTimer.Start();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
File.AppendAllText(this.messurementsFile, $"{e}{Environment.NewLine}");
|
|
||||||
|
|
||||||
this.tempMeterForm.AddMessage($"{e}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void StartGettingResults(Object sender, ElapsedEventArgs args)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
this.tempMeterForm.InvokeOnUIThread(() =>
|
|
||||||
{
|
{
|
||||||
var temp = this.temperatureSource.GetTemperature();
|
var temp = this.temperatureSource.GetTemperature();
|
||||||
var avgTOF = this.tempMeterForm.GetAverageTOF();
|
var results = this.tempMeterForm.GetAverageTOFForeachMeter();
|
||||||
var messurement = $"{this.pcbId};{DateTime.Now:yyyy-MM-dd HH:mm:ss:fff};{temp:0.00};{avgTOF:0.0000000000}";
|
|
||||||
|
|
||||||
File.AppendAllText(this.messurementsFile, $"{messurement}{Environment.NewLine}");
|
if (!this.hasHeaders)
|
||||||
|
{
|
||||||
|
File.AppendAllText(this.outputFile, $"Timestamp;°C;{string.Join(";", results.Keys)}{Environment.NewLine}");
|
||||||
|
|
||||||
|
this.hasHeaders = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
var messurement = $"{temp:0.00};{string.Join(";", results.Values.Select(x => $"{x:0.0000000000}"))}";
|
||||||
|
|
||||||
|
File.AppendAllText(this.outputFile, $"{messurement}{Environment.NewLine}");
|
||||||
|
|
||||||
this.tempMeterForm.AddMessage(messurement);
|
this.tempMeterForm.AddMessage(messurement);
|
||||||
// this.tempMeterForm.StartRecording();
|
}
|
||||||
});
|
catch (Exception e)
|
||||||
}
|
{
|
||||||
catch (Exception e)
|
this.tempMeterForm.AddMessage(e.ToString());
|
||||||
{
|
}
|
||||||
File.AppendAllText(this.messurementsFile, $"{e}{Environment.NewLine}");
|
});
|
||||||
|
|
||||||
this.tempMeterForm.AddMessage($"{e}");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void StopMessuring()
|
public void StopMessuring()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
this.resultsTimer.Stop();
|
this.timer.Stop();
|
||||||
this.resultsTimer.Dispose();
|
this.timer.Dispose();
|
||||||
this.resultsTimer = null;
|
this.timer = null;
|
||||||
|
|
||||||
this.startTimer.Stop();
|
|
||||||
this.startTimer.Dispose();
|
|
||||||
this.startTimer = null;
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
File.AppendAllText(this.messurementsFile, $"{e}{Environment.NewLine}");
|
this.tempMeterForm.AddMessage($"{e}");
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
this.temperatureSource.Dispose();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
this.tempMeterForm.AddMessage($"{e}");
|
this.tempMeterForm.AddMessage($"{e}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,11 +21,6 @@
|
|||||||
|
|
||||||
public double GetTemperature()
|
public double GetTemperature()
|
||||||
{
|
{
|
||||||
if (!this.connected)
|
|
||||||
{
|
|
||||||
return default(double);
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var result = default(short);
|
var result = default(short);
|
||||||
@@ -38,9 +33,18 @@
|
|||||||
result = GMH_Transmit(1, 0, &priority, &temperature, &value);
|
result = GMH_Transmit(1, 0, &priority, &temperature, &value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (temperature < 50)
|
||||||
|
{
|
||||||
|
return -1.11;
|
||||||
|
}
|
||||||
|
else if (temperature > 50)
|
||||||
|
{
|
||||||
|
return 1.11;
|
||||||
|
}
|
||||||
|
|
||||||
return temperature;
|
return temperature;
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
namespace LaaProduction.Data.Cordonel
|
||||||
|
{
|
||||||
|
using LaaProduction.Data.SQL;
|
||||||
|
using LaaProduction.Data.SQL.Interfaces;
|
||||||
|
|
||||||
|
using System;
|
||||||
|
|
||||||
|
public class CordonelDbContext
|
||||||
|
{
|
||||||
|
private readonly ISQLConnection sqlConnection;
|
||||||
|
|
||||||
|
public CordonelDbContext(string connectionString, Action<string> errorsCallback = null)
|
||||||
|
=> this.sqlConnection = new SQLConnection(connectionString, errorsCallback);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
namespace LaaProduction.Data.Cordonel
|
||||||
|
{
|
||||||
|
using System;
|
||||||
|
|
||||||
|
public class CordonelStandardRequirement
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
public string Key { get; set; }
|
||||||
|
|
||||||
|
public string Region { get; set; }
|
||||||
|
|
||||||
|
public string MeterSize { get; set; }
|
||||||
|
|
||||||
|
public string FwVersion { get; set; }
|
||||||
|
|
||||||
|
public string LutVersion { get; set; }
|
||||||
|
|
||||||
|
public double RequiredLifeTimeYearsAssembly { get; set; }
|
||||||
|
|
||||||
|
public double RequiredLifeTimeYearsShipping { get; set; }
|
||||||
|
|
||||||
|
public double MaxDrainedBatteryLoadPercentAssembly { get; set; }
|
||||||
|
|
||||||
|
public double MaxDrainedBatteryLoadPercentShipping { get; set; }
|
||||||
|
|
||||||
|
public double MaxStorageMonths { get; set; }
|
||||||
|
|
||||||
|
public double MaxStorageMonthsBigOrders { get; set; }
|
||||||
|
|
||||||
|
public DateTime Timestamp { get; set; }
|
||||||
|
|
||||||
|
public string CreatedBy { get; set; }
|
||||||
|
|
||||||
|
public string Comment { get; set; }
|
||||||
|
|
||||||
|
public bool IsActive { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,8 +4,8 @@
|
|||||||
|
|
||||||
public interface ISQLReader
|
public interface ISQLReader
|
||||||
{
|
{
|
||||||
T GetValue<T>();
|
T GetValue<T>(int index);
|
||||||
|
|
||||||
object GetValue(string column);
|
T GetValue<T>(string column);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -14,9 +14,9 @@
|
|||||||
|
|
||||||
public SQLCommand(SQLConnection sqlConnection, string commandText)
|
public SQLCommand(SQLConnection sqlConnection, string commandText)
|
||||||
{
|
{
|
||||||
this.sqlConnection = sqlConnection.EnsureNotNull(nameof(sqlConnection));
|
|
||||||
this.CommandText = commandText.EnsureNotNullOrWhiteSpace(nameof(commandText));
|
|
||||||
this.parameters = new Dictionary<string, SqlParameter>();
|
this.parameters = new Dictionary<string, SqlParameter>();
|
||||||
|
this.sqlConnection = sqlConnection;
|
||||||
|
this.CommandText = commandText;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal string CommandText { get; }
|
internal string CommandText { get; }
|
||||||
@@ -43,8 +43,6 @@
|
|||||||
|
|
||||||
public ISQLCommand SetParameter(string name, object value)
|
public ISQLCommand SetParameter(string name, object value)
|
||||||
{
|
{
|
||||||
name.ThrowIfNullOrWhiteSpace(nameof(name));
|
|
||||||
|
|
||||||
if (value is null)
|
if (value is null)
|
||||||
{
|
{
|
||||||
value = DBNull.Value;
|
value = DBNull.Value;
|
||||||
|
|||||||
@@ -22,12 +22,8 @@
|
|||||||
/// When <paramref name="connectionString"/> is null, white space or is not a valid connection string exception is thrown.
|
/// When <paramref name="connectionString"/> is null, white space or is not a valid connection string exception is thrown.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="connectionString"><see cref="System.String"/> - SQL connection string.</param>
|
/// <param name="connectionString"><see cref="System.String"/> - SQL connection string.</param>
|
||||||
public SQLConnection(string connectionString)
|
public SQLConnection(string connectionString)
|
||||||
{
|
=> this.connectionString = connectionString;
|
||||||
var connectionStringBuilder = new SqlConnectionStringBuilder(connectionString);
|
|
||||||
|
|
||||||
this.connectionString = connectionStringBuilder.ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// When <paramref name="connectionString"/> is null, white space or is not a valid connection string exception is thrown.
|
/// When <paramref name="connectionString"/> is null, white space or is not a valid connection string exception is thrown.
|
||||||
@@ -48,23 +44,6 @@
|
|||||||
public ISQLCommand CreateCommand(string commandText)
|
public ISQLCommand CreateCommand(string commandText)
|
||||||
=> new SQLCommand(this, commandText);
|
=> new SQLCommand(this, commandText);
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Static method that creates a <see cref="LaaProduction.Data.SQL.ISQLConnection"/> client with given connection string.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="connectionString"><see cref="System.String"/> - SQL connection string.</param>
|
|
||||||
/// <returns><see cref="LaaProduction.Data.SQL.ISQLConnection"/></returns>
|
|
||||||
public static ISQLConnection CreateSQLConnection(string connectionString)
|
|
||||||
=> new SQLConnection(connectionString);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Static method that creates a <see cref="LaaProduction.Data.SQL.ISQLConnection"/> client with given connection string and error callback that receives all error messages.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="connectionString"><see cref="System.String"/> - SQL connection string.</param>
|
|
||||||
/// <param name="errorCallback"><see cref="System.Action{System.String}"/> - error handler for SQL execution errors.</param>
|
|
||||||
/// <returns><see cref="LaaProduction.Data.SQL.ISQLConnection"/></returns>
|
|
||||||
public static ISQLConnection CreateSQLConnection(string connectionString, Action<string> errorCallback = null)
|
|
||||||
=> new SQLConnection(connectionString, errorCallback);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Internal method called from <see cref="LaaProduction.Data.SQL.ISQLCommand"/>.
|
/// Internal method called from <see cref="LaaProduction.Data.SQL.ISQLCommand"/>.
|
||||||
/// Like in a <see cref="System.Data.SqlClient.SqlCommand"/> performs INSERT, UPDATE, DELETE queries and returns the number of rows affected.
|
/// Like in a <see cref="System.Data.SqlClient.SqlCommand"/> performs INSERT, UPDATE, DELETE queries and returns the number of rows affected.
|
||||||
@@ -77,7 +56,7 @@
|
|||||||
|
|
||||||
using (var sqlConnection = new SqlConnection(this.connectionString))
|
using (var sqlConnection = new SqlConnection(this.connectionString))
|
||||||
{
|
{
|
||||||
sqlConnection.OpenWithErrorHandling(this.errorCallback);
|
this.OpenWithErrorHandling(sqlConnection);
|
||||||
|
|
||||||
using (var sqlCommand = sqlConnection.CreateCommand())
|
using (var sqlCommand = sqlConnection.CreateCommand())
|
||||||
{
|
{
|
||||||
@@ -106,7 +85,7 @@
|
|||||||
{
|
{
|
||||||
using (var sqlConnection = new SqlConnection(this.connectionString))
|
using (var sqlConnection = new SqlConnection(this.connectionString))
|
||||||
{
|
{
|
||||||
sqlConnection.OpenWithErrorHandling(this.errorCallback);
|
this.OpenWithErrorHandling(sqlConnection);
|
||||||
|
|
||||||
using (var sqlCommand = sqlConnection.CreateCommand())
|
using (var sqlCommand = sqlConnection.CreateCommand())
|
||||||
{
|
{
|
||||||
@@ -141,7 +120,7 @@
|
|||||||
|
|
||||||
using (var sqlConnection = new SqlConnection(this.connectionString))
|
using (var sqlConnection = new SqlConnection(this.connectionString))
|
||||||
{
|
{
|
||||||
this.OpenWithErrorHandling(sqlConnection, this.errorCallback);
|
this.OpenWithErrorHandling(sqlConnection);
|
||||||
|
|
||||||
using (var sqlCommand = sqlConnection.CreateCommand())
|
using (var sqlCommand = sqlConnection.CreateCommand())
|
||||||
{
|
{
|
||||||
@@ -175,7 +154,7 @@
|
|||||||
.ExecuteReader(command, expression)
|
.ExecuteReader(command, expression)
|
||||||
.FirstOrDefault();
|
.FirstOrDefault();
|
||||||
|
|
||||||
private void OpenWithErrorHandling(SqlConnection connection, Action<string> errorCallback)
|
private void OpenWithErrorHandling(SqlConnection connection)
|
||||||
{
|
{
|
||||||
connection.FireInfoMessageEventOnUserErrors = true;
|
connection.FireInfoMessageEventOnUserErrors = true;
|
||||||
connection.InfoMessage += (sender, args) =>
|
connection.InfoMessage += (sender, args) =>
|
||||||
@@ -184,9 +163,13 @@
|
|||||||
|
|
||||||
foreach (SqlError e in args.Errors)
|
foreach (SqlError e in args.Errors)
|
||||||
{
|
{
|
||||||
errors.Append($"{e.Server}|{e.Source}|{e.S}|{e.Class}|{e.Number}");
|
errors.Append($"Server:{e.Server}|Source:{e.Source}|State:{e.State}|Class:{e.Class}|Number:{e.Number}|Line:{e.LineNumber}|Message:{e.Message}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.errorCallback?.Invoke(errors.ToString());
|
||||||
};
|
};
|
||||||
|
|
||||||
|
connection.Open();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,8 +9,6 @@
|
|||||||
{
|
{
|
||||||
private readonly SqlDataReader sqlDataReader;
|
private readonly SqlDataReader sqlDataReader;
|
||||||
|
|
||||||
private int index;
|
|
||||||
|
|
||||||
private SQLReader(SqlDataReader sqlDataReader)
|
private SQLReader(SqlDataReader sqlDataReader)
|
||||||
=> this.sqlDataReader = sqlDataReader;
|
=> this.sqlDataReader = sqlDataReader;
|
||||||
|
|
||||||
@@ -20,13 +18,11 @@
|
|||||||
this.sqlDataReader.Dispose();
|
this.sqlDataReader.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
public T GetValue<T>()
|
public T GetValue<T>(int index)
|
||||||
{
|
{
|
||||||
this.index++;
|
if (!this.sqlDataReader.IsDBNull(index))
|
||||||
|
|
||||||
if (!this.sqlDataReader.IsDBNull(this.index))
|
|
||||||
{
|
{
|
||||||
var value = this.sqlDataReader.GetValue(this.index);
|
var value = this.sqlDataReader.GetValue(index);
|
||||||
var type = Nullable.GetUnderlyingType(typeof(T));
|
var type = Nullable.GetUnderlyingType(typeof(T));
|
||||||
|
|
||||||
if (type is null)
|
if (type is null)
|
||||||
@@ -52,27 +48,22 @@
|
|||||||
return default(T);
|
return default(T);
|
||||||
}
|
}
|
||||||
|
|
||||||
public object GetValue(string column)
|
public T GetValue<T>(string column)
|
||||||
{
|
{
|
||||||
var colIndex = this.sqlDataReader.GetOrdinal(column);
|
var table = this.sqlDataReader.GetSchemaTable();
|
||||||
|
|
||||||
if (0 <= colIndex && colIndex < this.sqlDataReader.FieldCount)
|
if (table?.Columns?.Contains(column) == true)
|
||||||
{
|
{
|
||||||
if (!this.sqlDataReader.IsDBNull(colIndex))
|
var index = this.sqlDataReader.GetOrdinal(column);
|
||||||
{
|
|
||||||
return this.sqlDataReader.GetValue(colIndex);
|
return this.GetValue<T>(index);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return default(object);
|
return default(T);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal bool Read()
|
internal bool Read()
|
||||||
{
|
=> this.sqlDataReader.Read();
|
||||||
this.index = -1;
|
|
||||||
|
|
||||||
return this.sqlDataReader.Read();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static implicit operator SQLReader(SqlDataReader sqlDataReader)
|
public static implicit operator SQLReader(SqlDataReader sqlDataReader)
|
||||||
=> new SQLReader(sqlDataReader);
|
=> new SQLReader(sqlDataReader);
|
||||||
|
|||||||
Reference in New Issue
Block a user