start recording for each temperature messurement
This commit is contained in:
parent
93466bfe7a
commit
4115dec3f0
@ -4,90 +4,120 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.IO.Ports;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
[DllImport("GMH3x32E.dll")]
|
||||
public static extern Int16 UniversalOpenCom(Int16 ini16COMPortNumber, UInt32 inui32BaudRate, Int16 inui16ConverterType, Int16 ini16Parity, Int16 ini16StoppBits);
|
||||
[DllImport("GMH3x32E.dll")]
|
||||
public static extern Int16 GMH_CloseCom();
|
||||
[DllImport("GMH3x32E.dll")]
|
||||
unsafe public static extern Int16 GMH_Transmit(Int16 ini16DeviceAddress, Int16 ini16TransmitCode, Int16* refi16ptrPriority, double* refdblptrFloatValue, Int32* refi32ptrIntegerValue);
|
||||
|
||||
public static void Main()
|
||||
{
|
||||
var messurementLines = File.ReadLines(@".\messurements.txt");
|
||||
var messurements = new List<Messurement>();
|
||||
UniversalOpenCom(12, 4800, 8, 0, 0);
|
||||
|
||||
var parsedData = new List<MessurementData>();
|
||||
var us = new CultureInfo("en-US");
|
||||
var de = new CultureInfo("de-DE");
|
||||
var any = NumberStyles.Any;
|
||||
var skipNext = true;
|
||||
Int16 i16Priority;
|
||||
Double dblFloatValue;
|
||||
Int32 i32IntergerValue;
|
||||
|
||||
foreach (var line in messurementLines)
|
||||
unsafe
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(line))
|
||||
{
|
||||
if (parsedData.Count > 0)
|
||||
{
|
||||
messurements.Add(new Messurement
|
||||
{
|
||||
PcbId = parsedData.First().PcbId,
|
||||
Start = parsedData.Min(x => x.Timestamp),
|
||||
MinT = parsedData.Min(x => x.CurrentT),
|
||||
MinTOF = parsedData.Min(x => x.CurrentTOF),
|
||||
AvgT = parsedData.Average(x => x.CurrentT),
|
||||
AvgTOF = parsedData.Average(x => x.CurrentTOF),
|
||||
MaxT = parsedData.Max(x => x.CurrentT),
|
||||
MaxTOF = parsedData.Max(x => x.CurrentTOF),
|
||||
End = parsedData.Max(x => x.Timestamp),
|
||||
});
|
||||
}
|
||||
|
||||
parsedData = new List<MessurementData>();
|
||||
skipNext = true;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (skipNext)
|
||||
{
|
||||
skipNext = false;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
var lineTokens = line.Split(new[] { '\t' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
if (lineTokens.Length != 4)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var dateString = lineTokens[0];
|
||||
var pcbId = lineTokens[1];
|
||||
var temperatureString = lineTokens[2];
|
||||
var tofString = lineTokens[3];
|
||||
|
||||
_ = DateTime.TryParse(dateString.Substring(1, dateString.Length - 2), out var timestamp);
|
||||
_ = double.TryParse(temperatureString, any, us, out var currentT) || double.TryParse(temperatureString, any, de, out currentT);
|
||||
_ = double.TryParse(tofString, any, us, out var currentTOF) || double.TryParse(tofString, any, de, out currentT);
|
||||
|
||||
parsedData.Add(new MessurementData
|
||||
{
|
||||
PcbId = pcbId,
|
||||
CurrentT = currentT,
|
||||
CurrentTOF = currentTOF,
|
||||
Timestamp = timestamp
|
||||
});
|
||||
var i16ErrorCode = GMH_Transmit(1, 0, &i16Priority, &dblFloatValue, &i32IntergerValue);
|
||||
}
|
||||
|
||||
File.WriteAllLines(@".\messurements.csv", messurements.Select(x
|
||||
=> $"{x.PcbId,10}\t"
|
||||
+ $"{x.AvgT,5:0.00}\t"
|
||||
+ $"{x.AvgTOF,12:0.0000000000}\t"
|
||||
+ $"{x.DifferenceT,5:00.00}\t"
|
||||
+ $"{x.DifferenceTOF,12:0.0000000000}"));
|
||||
|
||||
Console.WriteLine(Messurement.Header);
|
||||
|
||||
messurements.ForEach(Console.WriteLine);
|
||||
Console.WriteLine(dblFloatValue);
|
||||
|
||||
GMH_CloseCom();
|
||||
}
|
||||
|
||||
|
||||
//public static void Main(string[] args)
|
||||
//{
|
||||
// var messurementLines = File.ReadLines(@".\messurements.txt");
|
||||
// var messurements = new List<Messurement>();
|
||||
|
||||
// var parsedData = new List<MessurementData>();
|
||||
// var us = new CultureInfo("en-US");
|
||||
// var de = new CultureInfo("de-DE");
|
||||
// var any = NumberStyles.Any;
|
||||
// var skipNext = true;
|
||||
|
||||
// foreach (var line in messurementLines)
|
||||
// {
|
||||
// if (string.IsNullOrWhiteSpace(line))
|
||||
// {
|
||||
// if (parsedData.Count > 0)
|
||||
// {
|
||||
// messurements.Add(new Messurement
|
||||
// {
|
||||
// PcbId = parsedData.First().PcbId,
|
||||
// Start = parsedData.Min(x => x.Timestamp),
|
||||
// MinT = parsedData.Min(x => x.CurrentT),
|
||||
// MinTOF = parsedData.Min(x => x.CurrentTOF),
|
||||
// AvgT = parsedData.Average(x => x.CurrentT),
|
||||
// AvgTOF = parsedData.Average(x => x.CurrentTOF),
|
||||
// MaxT = parsedData.Max(x => x.CurrentT),
|
||||
// MaxTOF = parsedData.Max(x => x.CurrentTOF),
|
||||
// End = parsedData.Max(x => x.Timestamp),
|
||||
// });
|
||||
// }
|
||||
|
||||
// parsedData = new List<MessurementData>();
|
||||
// skipNext = true;
|
||||
|
||||
// continue;
|
||||
// }
|
||||
|
||||
// if (skipNext)
|
||||
// {
|
||||
// skipNext = false;
|
||||
|
||||
// continue;
|
||||
// }
|
||||
|
||||
// var lineTokens = line.Split(new[] { '\t' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
// if (lineTokens.Length != 4)
|
||||
// {
|
||||
// continue;
|
||||
// }
|
||||
|
||||
// var dateString = lineTokens[0];
|
||||
// var pcbId = lineTokens[1];
|
||||
// var temperatureString = lineTokens[2];
|
||||
// var tofString = lineTokens[3];
|
||||
|
||||
// _ = DateTime.TryParse(dateString.Substring(1, dateString.Length - 2), out var timestamp);
|
||||
// _ = double.TryParse(temperatureString, any, us, out var currentT) || double.TryParse(temperatureString, any, de, out currentT);
|
||||
// _ = double.TryParse(tofString, any, us, out var currentTOF) || double.TryParse(tofString, any, de, out currentT);
|
||||
|
||||
// parsedData.Add(new MessurementData
|
||||
// {
|
||||
// PcbId = pcbId,
|
||||
// CurrentT = currentT,
|
||||
// CurrentTOF = currentTOF,
|
||||
// Timestamp = timestamp
|
||||
// });
|
||||
// }
|
||||
|
||||
// File.WriteAllLines(@".\messurements.csv", messurements.Select(x
|
||||
// => $"{x.PcbId,10}\t"
|
||||
// + $"{x.AvgT,5:0.00}\t"
|
||||
// + $"{x.AvgTOF,12:0.0000000000}\t"
|
||||
// + $"{x.DifferenceT,5:00.00}\t"
|
||||
// + $"{x.DifferenceTOF,12:0.0000000000}"));
|
||||
|
||||
// Console.WriteLine(Messurement.Header);
|
||||
|
||||
// messurements.ForEach(Console.WriteLine);
|
||||
//}
|
||||
}
|
||||
|
||||
public class MessurementData
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2"/>
|
||||
</startup>
|
||||
</configuration>
|
||||
</configuration>
|
||||
|
||||
44
Common/TempFlansh/Properties/Resources.Designer.cs
generated
44
Common/TempFlansh/Properties/Resources.Designer.cs
generated
@ -8,10 +8,10 @@
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace TempFlansh.Properties
|
||||
{
|
||||
|
||||
|
||||
namespace TempFlansh.Properties {
|
||||
using System;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// A strongly-typed resource class, for looking up localized strings, etc.
|
||||
/// </summary>
|
||||
@ -19,51 +19,43 @@ namespace TempFlansh.Properties
|
||||
// class via a tool like ResGen or Visual Studio.
|
||||
// To add or remove a member, edit your .ResX file then rerun ResGen
|
||||
// with the /str option, or rebuild your VS project.
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
internal class Resources
|
||||
{
|
||||
|
||||
internal class Resources {
|
||||
|
||||
private static global::System.Resources.ResourceManager resourceMan;
|
||||
|
||||
|
||||
private static global::System.Globalization.CultureInfo resourceCulture;
|
||||
|
||||
|
||||
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||
internal Resources()
|
||||
{
|
||||
internal Resources() {
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Returns the cached ResourceManager instance used by this class.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Resources.ResourceManager ResourceManager
|
||||
{
|
||||
get
|
||||
{
|
||||
if ((resourceMan == null))
|
||||
{
|
||||
internal static global::System.Resources.ResourceManager ResourceManager {
|
||||
get {
|
||||
if (object.ReferenceEquals(resourceMan, null)) {
|
||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("TempFlansh.Properties.Resources", typeof(Resources).Assembly);
|
||||
resourceMan = temp;
|
||||
}
|
||||
return resourceMan;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Overrides the current thread's CurrentUICulture property for all
|
||||
/// resource lookups using this strongly typed resource class.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Globalization.CultureInfo Culture
|
||||
{
|
||||
get
|
||||
{
|
||||
internal static global::System.Globalization.CultureInfo Culture {
|
||||
get {
|
||||
return resourceCulture;
|
||||
}
|
||||
set
|
||||
{
|
||||
set {
|
||||
resourceCulture = value;
|
||||
}
|
||||
}
|
||||
|
||||
22
Common/TempFlansh/Properties/Settings.Designer.cs
generated
22
Common/TempFlansh/Properties/Settings.Designer.cs
generated
@ -8,21 +8,17 @@
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace TempFlansh.Properties
|
||||
{
|
||||
|
||||
|
||||
namespace TempFlansh.Properties {
|
||||
|
||||
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
|
||||
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
|
||||
{
|
||||
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.9.0.0")]
|
||||
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
|
||||
|
||||
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
|
||||
|
||||
public static Settings Default
|
||||
{
|
||||
get
|
||||
{
|
||||
|
||||
public static Settings Default {
|
||||
get {
|
||||
return defaultInstance;
|
||||
}
|
||||
}
|
||||
|
||||
@ -13,6 +13,7 @@
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
<Deterministic>true</Deterministic>
|
||||
<IsWebBootstrapper>false</IsWebBootstrapper>
|
||||
<TargetFrameworkProfile />
|
||||
<PublishUrl>C:\Users\SZLATEV\Desktop\TempFlansh\</PublishUrl>
|
||||
<Install>true</Install>
|
||||
<InstallFrom>Disk</InstallFrom>
|
||||
@ -134,6 +135,7 @@
|
||||
<Compile Include="Properties\Resources.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
<DesignTime>True</DesignTime>
|
||||
</Compile>
|
||||
<None Include="packages.config" />
|
||||
<None Include="Properties\Settings.settings">
|
||||
@ -147,7 +149,9 @@
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
<None Include="App.config">
|
||||
<SubType>Designer</SubType>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="GMH3x32E.dll">
|
||||
|
||||
140
Common/Ui/GenesisToolBox/FrmTempMeter.Designer.cs
generated
140
Common/Ui/GenesisToolBox/FrmTempMeter.Designer.cs
generated
@ -58,12 +58,16 @@ namespace Xylem.Common.Ui.GenesisToolBox
|
||||
this.automaticContentBox = new System.Windows.Forms.RichTextBox();
|
||||
this.autometicControlsSplitter = new System.Windows.Forms.Splitter();
|
||||
this.automaticControlsPanel = new System.Windows.Forms.Panel();
|
||||
this.saveSettingsBtn = new System.Windows.Forms.Button();
|
||||
this.messurementDauerMS = new System.Windows.Forms.TextBox();
|
||||
this.label3 = new System.Windows.Forms.Label();
|
||||
this.stopAutomaticBtn = new System.Windows.Forms.Button();
|
||||
this.startAutomaticBtn = new System.Windows.Forms.Button();
|
||||
this.temperatureCheckInC = new System.Windows.Forms.TextBox();
|
||||
this.messurementStepMS = new System.Windows.Forms.TextBox();
|
||||
this.label2 = new System.Windows.Forms.Label();
|
||||
this.temperatureCheckInMs = new System.Windows.Forms.TextBox();
|
||||
this.GMHPort = new System.Windows.Forms.TextBox();
|
||||
this.label1 = new System.Windows.Forms.Label();
|
||||
this.tabPage4 = new System.Windows.Forms.TabPage();
|
||||
this.timer3 = new System.Windows.Forms.Timer(this.components);
|
||||
this.mainMenuStrip = new System.Windows.Forms.MenuStrip();
|
||||
this.automaticCalibrationTabControl.SuspendLayout();
|
||||
@ -90,6 +94,7 @@ namespace Xylem.Common.Ui.GenesisToolBox
|
||||
this.automaticCalibrationTabControl.Controls.Add(this.tabPage2);
|
||||
this.automaticCalibrationTabControl.Controls.Add(this.tabPage3);
|
||||
this.automaticCalibrationTabControl.Controls.Add(this.AutomaticCalibrationTab);
|
||||
this.automaticCalibrationTabControl.Controls.Add(this.tabPage4);
|
||||
this.automaticCalibrationTabControl.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.automaticCalibrationTabControl.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.automaticCalibrationTabControl.Location = new System.Drawing.Point(0, 24);
|
||||
@ -97,7 +102,7 @@ namespace Xylem.Common.Ui.GenesisToolBox
|
||||
this.automaticCalibrationTabControl.Name = "automaticCalibrationTabControl";
|
||||
this.automaticCalibrationTabControl.Padding = new System.Drawing.Point(0, 0);
|
||||
this.automaticCalibrationTabControl.SelectedIndex = 0;
|
||||
this.automaticCalibrationTabControl.Size = new System.Drawing.Size(1245, 724);
|
||||
this.automaticCalibrationTabControl.Size = new System.Drawing.Size(1225, 676);
|
||||
this.automaticCalibrationTabControl.TabIndex = 55;
|
||||
this.automaticCalibrationTabControl.Tag = "";
|
||||
//
|
||||
@ -108,7 +113,7 @@ namespace Xylem.Common.Ui.GenesisToolBox
|
||||
this.tabPage1.Location = new System.Drawing.Point(4, 25);
|
||||
this.tabPage1.Name = "tabPage1";
|
||||
this.tabPage1.Padding = new System.Windows.Forms.Padding(3);
|
||||
this.tabPage1.Size = new System.Drawing.Size(1237, 695);
|
||||
this.tabPage1.Size = new System.Drawing.Size(1217, 647);
|
||||
this.tabPage1.TabIndex = 0;
|
||||
this.tabPage1.Text = "Current entrys in LUT";
|
||||
this.tabPage1.UseVisualStyleBackColor = true;
|
||||
@ -139,7 +144,7 @@ namespace Xylem.Common.Ui.GenesisToolBox
|
||||
this.tabPage2.Location = new System.Drawing.Point(4, 25);
|
||||
this.tabPage2.Name = "tabPage2";
|
||||
this.tabPage2.Padding = new System.Windows.Forms.Padding(3);
|
||||
this.tabPage2.Size = new System.Drawing.Size(1237, 695);
|
||||
this.tabPage2.Size = new System.Drawing.Size(1217, 647);
|
||||
this.tabPage2.TabIndex = 1;
|
||||
this.tabPage2.Text = "Manual check temp";
|
||||
this.tabPage2.UseVisualStyleBackColor = true;
|
||||
@ -189,7 +194,7 @@ namespace Xylem.Common.Ui.GenesisToolBox
|
||||
this.tabPage3.Location = new System.Drawing.Point(4, 25);
|
||||
this.tabPage3.Name = "tabPage3";
|
||||
this.tabPage3.Padding = new System.Windows.Forms.Padding(3);
|
||||
this.tabPage3.Size = new System.Drawing.Size(1237, 695);
|
||||
this.tabPage3.Size = new System.Drawing.Size(1217, 647);
|
||||
this.tabPage3.TabIndex = 2;
|
||||
this.tabPage3.Text = "Manual add LUT";
|
||||
this.tabPage3.UseVisualStyleBackColor = true;
|
||||
@ -328,7 +333,7 @@ namespace Xylem.Common.Ui.GenesisToolBox
|
||||
this.AutomaticCalibrationTab.Location = new System.Drawing.Point(4, 25);
|
||||
this.AutomaticCalibrationTab.Margin = new System.Windows.Forms.Padding(0);
|
||||
this.AutomaticCalibrationTab.Name = "AutomaticCalibrationTab";
|
||||
this.AutomaticCalibrationTab.Size = new System.Drawing.Size(1237, 695);
|
||||
this.AutomaticCalibrationTab.Size = new System.Drawing.Size(1217, 647);
|
||||
this.AutomaticCalibrationTab.TabIndex = 3;
|
||||
this.AutomaticCalibrationTab.Text = "Automatic Calibration";
|
||||
//
|
||||
@ -339,7 +344,7 @@ namespace Xylem.Common.Ui.GenesisToolBox
|
||||
this.automaticContentBox.Font = new System.Drawing.Font("Consolas", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.automaticContentBox.Location = new System.Drawing.Point(331, 0);
|
||||
this.automaticContentBox.Name = "automaticContentBox";
|
||||
this.automaticContentBox.Size = new System.Drawing.Size(906, 695);
|
||||
this.automaticContentBox.Size = new System.Drawing.Size(886, 647);
|
||||
this.automaticContentBox.TabIndex = 2;
|
||||
this.automaticContentBox.Text = "";
|
||||
//
|
||||
@ -349,32 +354,75 @@ namespace Xylem.Common.Ui.GenesisToolBox
|
||||
this.autometicControlsSplitter.Cursor = System.Windows.Forms.Cursors.VSplit;
|
||||
this.autometicControlsSplitter.Location = new System.Drawing.Point(328, 0);
|
||||
this.autometicControlsSplitter.Name = "autometicControlsSplitter";
|
||||
this.autometicControlsSplitter.Size = new System.Drawing.Size(3, 695);
|
||||
this.autometicControlsSplitter.Size = new System.Drawing.Size(3, 647);
|
||||
this.autometicControlsSplitter.TabIndex = 1;
|
||||
this.autometicControlsSplitter.TabStop = false;
|
||||
//
|
||||
// automaticControlsPanel
|
||||
//
|
||||
this.automaticControlsPanel.BackColor = System.Drawing.SystemColors.Menu;
|
||||
this.automaticControlsPanel.Controls.Add(this.saveSettingsBtn);
|
||||
this.automaticControlsPanel.Controls.Add(this.messurementDauerMS);
|
||||
this.automaticControlsPanel.Controls.Add(this.label3);
|
||||
this.automaticControlsPanel.Controls.Add(this.stopAutomaticBtn);
|
||||
this.automaticControlsPanel.Controls.Add(this.startAutomaticBtn);
|
||||
this.automaticControlsPanel.Controls.Add(this.temperatureCheckInC);
|
||||
this.automaticControlsPanel.Controls.Add(this.messurementStepMS);
|
||||
this.automaticControlsPanel.Controls.Add(this.label2);
|
||||
this.automaticControlsPanel.Controls.Add(this.temperatureCheckInMs);
|
||||
this.automaticControlsPanel.Controls.Add(this.GMHPort);
|
||||
this.automaticControlsPanel.Controls.Add(this.label1);
|
||||
this.automaticControlsPanel.Dock = System.Windows.Forms.DockStyle.Left;
|
||||
this.automaticControlsPanel.Location = new System.Drawing.Point(0, 0);
|
||||
this.automaticControlsPanel.Name = "automaticControlsPanel";
|
||||
this.automaticControlsPanel.Padding = new System.Windows.Forms.Padding(5);
|
||||
this.automaticControlsPanel.Size = new System.Drawing.Size(328, 695);
|
||||
this.automaticControlsPanel.Size = new System.Drawing.Size(328, 647);
|
||||
this.automaticControlsPanel.TabIndex = 0;
|
||||
//
|
||||
// saveSettingsBtn
|
||||
//
|
||||
this.saveSettingsBtn.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.saveSettingsBtn.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
|
||||
this.saveSettingsBtn.Location = new System.Drawing.Point(5, 149);
|
||||
this.saveSettingsBtn.Margin = new System.Windows.Forms.Padding(5);
|
||||
this.saveSettingsBtn.Name = "saveSettingsBtn";
|
||||
this.saveSettingsBtn.Padding = new System.Windows.Forms.Padding(0, 5, 0, 5);
|
||||
this.saveSettingsBtn.Size = new System.Drawing.Size(318, 36);
|
||||
this.saveSettingsBtn.TabIndex = 16;
|
||||
this.saveSettingsBtn.Text = "Save settings";
|
||||
this.saveSettingsBtn.UseVisualStyleBackColor = true;
|
||||
this.saveSettingsBtn.Click += new System.EventHandler(this.SaveSettingsBtn_Click);
|
||||
//
|
||||
// messurementDauerMS
|
||||
//
|
||||
this.messurementDauerMS.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.messurementDauerMS.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
this.messurementDauerMS.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.messurementDauerMS.Location = new System.Drawing.Point(5, 114);
|
||||
this.messurementDauerMS.Margin = new System.Windows.Forms.Padding(0);
|
||||
this.messurementDauerMS.Name = "messurementDauerMS";
|
||||
this.messurementDauerMS.Size = new System.Drawing.Size(318, 24);
|
||||
this.messurementDauerMS.TabIndex = 15;
|
||||
//
|
||||
// label3
|
||||
//
|
||||
this.label3.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.label3.FlatStyle = System.Windows.Forms.FlatStyle.System;
|
||||
this.label3.Location = new System.Drawing.Point(5, 97);
|
||||
this.label3.Margin = new System.Windows.Forms.Padding(5);
|
||||
this.label3.Name = "label3";
|
||||
this.label3.Size = new System.Drawing.Size(318, 18);
|
||||
this.label3.TabIndex = 14;
|
||||
this.label3.Text = "Messurement dauer (ms)";
|
||||
this.label3.TextAlign = System.Drawing.ContentAlignment.BottomLeft;
|
||||
//
|
||||
// stopAutomaticBtn
|
||||
//
|
||||
this.stopAutomaticBtn.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.stopAutomaticBtn.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
|
||||
this.stopAutomaticBtn.Location = new System.Drawing.Point(5, 153);
|
||||
this.stopAutomaticBtn.Location = new System.Drawing.Point(5, 241);
|
||||
this.stopAutomaticBtn.Margin = new System.Windows.Forms.Padding(5);
|
||||
this.stopAutomaticBtn.Name = "stopAutomaticBtn";
|
||||
this.stopAutomaticBtn.Padding = new System.Windows.Forms.Padding(0, 5, 0, 5);
|
||||
@ -389,7 +437,7 @@ namespace Xylem.Common.Ui.GenesisToolBox
|
||||
this.startAutomaticBtn.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.startAutomaticBtn.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
|
||||
this.startAutomaticBtn.Location = new System.Drawing.Point(5, 107);
|
||||
this.startAutomaticBtn.Location = new System.Drawing.Point(5, 195);
|
||||
this.startAutomaticBtn.Margin = new System.Windows.Forms.Padding(5);
|
||||
this.startAutomaticBtn.Name = "startAutomaticBtn";
|
||||
this.startAutomaticBtn.Padding = new System.Windows.Forms.Padding(0, 5, 0, 5);
|
||||
@ -399,17 +447,17 @@ namespace Xylem.Common.Ui.GenesisToolBox
|
||||
this.startAutomaticBtn.UseVisualStyleBackColor = true;
|
||||
this.startAutomaticBtn.Click += new System.EventHandler(this.StartAutomaticBtn_Clicked);
|
||||
//
|
||||
// temperatureCheckInC
|
||||
// messurementStepMS
|
||||
//
|
||||
this.temperatureCheckInC.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
|
||||
this.messurementStepMS.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.temperatureCheckInC.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
this.temperatureCheckInC.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.temperatureCheckInC.Location = new System.Drawing.Point(5, 68);
|
||||
this.temperatureCheckInC.Margin = new System.Windows.Forms.Padding(0);
|
||||
this.temperatureCheckInC.Name = "temperatureCheckInC";
|
||||
this.temperatureCheckInC.Size = new System.Drawing.Size(318, 24);
|
||||
this.temperatureCheckInC.TabIndex = 3;
|
||||
this.messurementStepMS.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
this.messurementStepMS.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.messurementStepMS.Location = new System.Drawing.Point(5, 68);
|
||||
this.messurementStepMS.Margin = new System.Windows.Forms.Padding(0);
|
||||
this.messurementStepMS.Name = "messurementStepMS";
|
||||
this.messurementStepMS.Size = new System.Drawing.Size(318, 24);
|
||||
this.messurementStepMS.TabIndex = 3;
|
||||
//
|
||||
// label2
|
||||
//
|
||||
@ -421,21 +469,21 @@ namespace Xylem.Common.Ui.GenesisToolBox
|
||||
this.label2.Name = "label2";
|
||||
this.label2.Size = new System.Drawing.Size(318, 18);
|
||||
this.label2.TabIndex = 2;
|
||||
this.label2.Text = "How long should messure (minutes)";
|
||||
this.label2.Text = "Messurement step (ms)";
|
||||
this.label2.TextAlign = System.Drawing.ContentAlignment.BottomLeft;
|
||||
//
|
||||
// temperatureCheckInMs
|
||||
// GMHPort
|
||||
//
|
||||
this.temperatureCheckInMs.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
|
||||
this.GMHPort.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.temperatureCheckInMs.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
this.temperatureCheckInMs.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.temperatureCheckInMs.Location = new System.Drawing.Point(5, 22);
|
||||
this.temperatureCheckInMs.Margin = new System.Windows.Forms.Padding(0);
|
||||
this.temperatureCheckInMs.MinimumSize = new System.Drawing.Size(2, 25);
|
||||
this.temperatureCheckInMs.Name = "temperatureCheckInMs";
|
||||
this.temperatureCheckInMs.Size = new System.Drawing.Size(318, 24);
|
||||
this.temperatureCheckInMs.TabIndex = 1;
|
||||
this.GMHPort.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
this.GMHPort.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.GMHPort.Location = new System.Drawing.Point(5, 22);
|
||||
this.GMHPort.Margin = new System.Windows.Forms.Padding(0);
|
||||
this.GMHPort.MinimumSize = new System.Drawing.Size(2, 25);
|
||||
this.GMHPort.Name = "GMHPort";
|
||||
this.GMHPort.Size = new System.Drawing.Size(318, 24);
|
||||
this.GMHPort.TabIndex = 1;
|
||||
//
|
||||
// label1
|
||||
//
|
||||
@ -447,9 +495,19 @@ namespace Xylem.Common.Ui.GenesisToolBox
|
||||
this.label1.Name = "label1";
|
||||
this.label1.Size = new System.Drawing.Size(318, 18);
|
||||
this.label1.TabIndex = 0;
|
||||
this.label1.Text = "Time to wait before next messurement (minutes)";
|
||||
this.label1.Text = "Messgerät (COM port)";
|
||||
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
|
||||
//
|
||||
this.timer3.Interval = 10000;
|
||||
@ -460,7 +518,7 @@ namespace Xylem.Common.Ui.GenesisToolBox
|
||||
this.mainMenuStrip.BackColor = System.Drawing.SystemColors.Control;
|
||||
this.mainMenuStrip.Location = new System.Drawing.Point(0, 0);
|
||||
this.mainMenuStrip.Name = "mainMenuStrip";
|
||||
this.mainMenuStrip.Size = new System.Drawing.Size(1245, 24);
|
||||
this.mainMenuStrip.Size = new System.Drawing.Size(1225, 24);
|
||||
this.mainMenuStrip.TabIndex = 57;
|
||||
this.mainMenuStrip.Text = "menuStrip1";
|
||||
//
|
||||
@ -468,7 +526,7 @@ namespace Xylem.Common.Ui.GenesisToolBox
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(1245, 748);
|
||||
this.ClientSize = new System.Drawing.Size(1225, 700);
|
||||
this.Controls.Add(this.automaticCalibrationTabControl);
|
||||
this.Controls.Add(this.mainMenuStrip);
|
||||
this.MainMenuStrip = this.mainMenuStrip;
|
||||
@ -521,10 +579,14 @@ namespace Xylem.Common.Ui.GenesisToolBox
|
||||
private System.Windows.Forms.Splitter autometicControlsSplitter;
|
||||
private System.Windows.Forms.Panel automaticControlsPanel;
|
||||
private System.Windows.Forms.Label label1;
|
||||
private System.Windows.Forms.TextBox temperatureCheckInMs;
|
||||
private System.Windows.Forms.TextBox temperatureCheckInC;
|
||||
private System.Windows.Forms.TextBox GMHPort;
|
||||
private System.Windows.Forms.TextBox messurementStepMS;
|
||||
private System.Windows.Forms.Label label2;
|
||||
private System.Windows.Forms.Button stopAutomaticBtn;
|
||||
private System.Windows.Forms.Button startAutomaticBtn;
|
||||
private System.Windows.Forms.TextBox messurementDauerMS;
|
||||
private System.Windows.Forms.Label label3;
|
||||
private System.Windows.Forms.Button saveSettingsBtn;
|
||||
private System.Windows.Forms.TabPage tabPage4;
|
||||
}
|
||||
}
|
||||
@ -23,13 +23,14 @@
|
||||
using Xylem.Common.Logic.SoftwareAccessHelper;
|
||||
using Xylem.Common.Ui.GenesisToolBox.Infrastructure;
|
||||
|
||||
public partial class FrmTempMeter : Form
|
||||
public partial class FrmTempMeter : Form, ITempMeterForm
|
||||
{
|
||||
private ToolStripLabel slotsLabel;
|
||||
private ToolStripComboBox slotsList;
|
||||
private ToolStripLabel pcbidLabel;
|
||||
private ToolStripTextBox pcbidTextBox;
|
||||
private ToolStripButton connectBtn;
|
||||
private ToolStripButton disconnectBtn;
|
||||
private ToolStripButton testBtn;
|
||||
|
||||
private ProgrammState programmState;
|
||||
@ -529,14 +530,14 @@
|
||||
while (needUp >= 0)
|
||||
{
|
||||
|
||||
var temp = rramp.NextDouble() / (needUp * 100);//+0
|
||||
var temp = rramp.NextDouble() / (needUp * 100); // +0
|
||||
needUp = needUp - temp;
|
||||
refTemp = refTemp + temp;
|
||||
refTempss.Add(new TempTofCalc() { RefDate = sDate.AddSeconds(refTempss.Count), RefTemp = refTemp, Tof = generateTof(rtof, refTemp) });
|
||||
}
|
||||
|
||||
var ra = new Random();
|
||||
var tillI = ra.Next(150, 4000);//+0
|
||||
var tillI = ra.Next(150, 4000); // +0
|
||||
var r = new Random(tillI);
|
||||
for (Int32 platI = 0; platI < tillI; platI++)
|
||||
{
|
||||
@ -607,6 +608,18 @@
|
||||
};
|
||||
this.connectBtn.Click += this.BtnConnect_Click;
|
||||
|
||||
this.disconnectBtn = new ToolStripButton
|
||||
{
|
||||
Text = "Disconnect",
|
||||
AutoSize = true,
|
||||
Font = fontBold,
|
||||
TextAlign = ContentAlignment.MiddleCenter,
|
||||
Margin = new Padding(10, 0, 0, 0),
|
||||
Padding = new Padding(10, 0, 10, 0),
|
||||
BackColor = Color.LightGray
|
||||
};
|
||||
this.disconnectBtn.Click += this.BtnDisconnect_Click;
|
||||
|
||||
this.testBtn = new ToolStripButton
|
||||
{
|
||||
Text = "Test",
|
||||
@ -624,14 +637,44 @@
|
||||
this.mainMenuStrip.Items.Add(this.pcbidLabel);
|
||||
this.mainMenuStrip.Items.Add(this.pcbidTextBox);
|
||||
this.mainMenuStrip.Items.Add(this.connectBtn);
|
||||
this.mainMenuStrip.Items.Add(this.disconnectBtn);
|
||||
this.mainMenuStrip.Items.Add(this.testBtn);
|
||||
|
||||
this.AutomaticCalibrationTab.HandleCreated += this.AddTextBoxBindings;
|
||||
this.AutomaticCalibrationTab.HandleDestroyed += this.RemoveTextBoxBindings;
|
||||
this.automaticCalibrationTabControl.GotFocus += (Object sender, EventArgs e) =>
|
||||
{
|
||||
this.GMHPort.Text = Appsettings.GMHPort.ToString();
|
||||
this.messurementStepMS.Text = Appsettings.MessurementStep.ToString();
|
||||
this.messurementDauerMS.Text = Appsettings.MessurementDauer.ToString();
|
||||
};
|
||||
|
||||
this.SetEnabled(ProgrammState.Start);
|
||||
}
|
||||
|
||||
private void BtnDisconnect_Click(Object sender, EventArgs args)
|
||||
{
|
||||
try
|
||||
{
|
||||
this.currentGenesis.DisposeMeter();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
this.currentGenesis = null;
|
||||
}
|
||||
|
||||
this.Invoke(new Action(() =>
|
||||
{
|
||||
this.txtLuts.Text = string.Empty;
|
||||
this.txtLuts.BackColor = Color.White;
|
||||
this.pcbidTextBox.Text = "not connected";
|
||||
this.SetEnabled(ProgrammState.Start);
|
||||
|
||||
}));
|
||||
}
|
||||
|
||||
private void SetEnabled(ProgrammState state)
|
||||
{
|
||||
this.programmState = state;
|
||||
@ -644,6 +687,8 @@
|
||||
this.btnAddLut.Enabled = false;
|
||||
this.nudRef.Visible = false;
|
||||
this.btnRefreshLut.Enabled = false;
|
||||
this.disconnectBtn.Visible = false;
|
||||
this.connectBtn.Visible = true;
|
||||
break;
|
||||
case ProgrammState.Connected:
|
||||
this.btnStartRecord.Enabled = true;
|
||||
@ -651,6 +696,8 @@
|
||||
this.btnAddLut.Enabled = false;
|
||||
this.nudRef.Visible = false;
|
||||
this.btnRefreshLut.Enabled = true;
|
||||
this.disconnectBtn.Visible = true;
|
||||
this.connectBtn.Visible = false;
|
||||
break;
|
||||
case ProgrammState.RecordRuning:
|
||||
this.btnStartRecord.Enabled = false;
|
||||
@ -674,22 +721,6 @@
|
||||
this.stopAutomaticBtn.Enabled = false;
|
||||
}
|
||||
|
||||
private void AddTextBoxBindings(Object sender, EventArgs e)
|
||||
{
|
||||
var property = nameof(this.temperatureCheckInC.Text);
|
||||
var source = Appsettings.Model;
|
||||
var mode = DataSourceUpdateMode.OnPropertyChanged;
|
||||
|
||||
this.temperatureCheckInMs.DataBindings.Add(property, source, nameof(source.WaitingTimeInMinutes), false, mode);
|
||||
this.temperatureCheckInC.DataBindings.Add(property, source, nameof(source.MessuringTimeInMinutes), false, mode);
|
||||
}
|
||||
|
||||
private void RemoveTextBoxBindings(object sender, EventArgs e)
|
||||
{
|
||||
this.temperatureCheckInC.DataBindings.Clear();
|
||||
this.temperatureCheckInMs.DataBindings.Clear();
|
||||
}
|
||||
|
||||
private bool automatic = false;
|
||||
private AutomaticTemperatureCalibration automaticCalibration;
|
||||
|
||||
@ -702,17 +733,16 @@
|
||||
return;
|
||||
}
|
||||
|
||||
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.automatic = true;
|
||||
this.start = DateTimeOffset.Now;
|
||||
|
||||
this.currentGenesis.StartRecordData();
|
||||
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);
|
||||
|
||||
var pcbid = this.currentGenesis?.PcbId ?? "*********";
|
||||
this.automaticCalibration = new AutomaticTemperatureCalibration(pcbid, () => this.OutputAvgTof());
|
||||
this.automaticCalibration = new AutomaticTemperatureCalibration(pcbid, this);
|
||||
|
||||
this.automaticCalibration.StartMessuring();
|
||||
this.SetEnabled(ProgrammState.RecordRuning);
|
||||
@ -729,28 +759,31 @@
|
||||
|
||||
this.MergeToAutoFile();
|
||||
|
||||
this.currentGenesis.WriteRegister(Register.Genesisflow.SampleRate, (byte)0, 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.StopRecordData();
|
||||
|
||||
this.SetEnabled(ProgrammState.RecordStoped);
|
||||
|
||||
this.startAutomaticBtn.Enabled = true;
|
||||
this.stopAutomaticBtn.Enabled = false;
|
||||
|
||||
this.AddMessage("Automatic temperature calibration stoped.", Color.Black);
|
||||
}
|
||||
|
||||
private void UpdateAutomaticBtn_Clicked(object sender, EventArgs args)
|
||||
{
|
||||
|
||||
}
|
||||
const int TAKE_LINES = 50;
|
||||
|
||||
private void AddMessage(string message, Color color)
|
||||
public void AddMessage(string message)
|
||||
{
|
||||
|
||||
this.BeginInvoke(new Action(() =>
|
||||
{
|
||||
this.automaticContentBox.AppendText($"{message}{Environment.NewLine}");
|
||||
|
||||
var skipLines = this.automaticContentBox.Lines.Length - TAKE_LINES;
|
||||
|
||||
if (skipLines > 0)
|
||||
{
|
||||
this.automaticContentBox.Lines = this.automaticContentBox
|
||||
.Lines
|
||||
.Skip(skipLines)
|
||||
.Take(TAKE_LINES)
|
||||
.ToArray();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
private void SaveMessurement(double currentT, double meterTOF, DateTime timestamp)
|
||||
@ -785,5 +818,47 @@
|
||||
// TODO:
|
||||
}
|
||||
}
|
||||
|
||||
public void StartRecording()
|
||||
=> this.currentGenesis
|
||||
?.StartRecordData();
|
||||
|
||||
public Double AvgTOF()
|
||||
{
|
||||
if (this.currentGenesis is null)
|
||||
{
|
||||
this.automaticCalibration.StopMessuring();
|
||||
|
||||
return double.MinValue;
|
||||
}
|
||||
|
||||
return this.currentGenesis
|
||||
.CurrentRecords
|
||||
.Where(s => s.Channel == 2)
|
||||
.Average(x => x.TotalTimeOfFlightS);
|
||||
}
|
||||
|
||||
protected override void OnFormClosed(FormClosedEventArgs e)
|
||||
=> this.BtnDisconnect_Click(default(object), EventArgs.Empty);
|
||||
|
||||
private void SaveSettingsBtn_Click(Object sender, EventArgs e)
|
||||
{
|
||||
if (short.TryParse($"{this.GMHPort.Text}", out short gmhPort))
|
||||
{
|
||||
Appsettings.GMHPort = gmhPort;
|
||||
}
|
||||
|
||||
if (int.TryParse($"{this.messurementStepMS.Text}", out int msStep))
|
||||
{
|
||||
Appsettings.MessurementStep = msStep;
|
||||
}
|
||||
|
||||
if (int.TryParse($"{this.messurementDauerMS.Text}", out int msDauer))
|
||||
{
|
||||
Appsettings.MessurementDauer = msDauer;
|
||||
}
|
||||
|
||||
Appsettings.SaveSettings();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,134 +1,82 @@
|
||||
namespace Xylem.Common.Ui.GenesisToolBox.Infrastructure
|
||||
{
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Configuration;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Windows.Forms;
|
||||
|
||||
internal static class Appsettings
|
||||
{
|
||||
private const string EMPTY = "";
|
||||
private const string SETTINGS_SECTION = "appSettings";
|
||||
private static Configuration configuration
|
||||
= ConfigurationManager.OpenExeConfiguration(Application.ExecutablePath);
|
||||
private static KeyValueConfigurationCollection settings
|
||||
=> configuration.AppSettings.Settings;
|
||||
|
||||
private static readonly Configuration configuration = ConfigurationManager.OpenExeConfiguration(Application.ExecutablePath);
|
||||
|
||||
private class DefaultValues
|
||||
public static short GMHPort
|
||||
{
|
||||
public const int WaitingTimeInMinutes = 2;
|
||||
public const int MessuringTimeInMinutes = 2;
|
||||
get => GetInt16();
|
||||
set => SetValue(value);
|
||||
}
|
||||
|
||||
public class AppsettingsModel : INotifyPropertyChanged
|
||||
public static int MessurementStep
|
||||
{
|
||||
public AppsettingsModel()
|
||||
get => GetInt32();
|
||||
set => SetValue(value);
|
||||
}
|
||||
|
||||
public static int MessurementDauer
|
||||
{
|
||||
get => GetInt32();
|
||||
set => SetValue(value);
|
||||
}
|
||||
|
||||
private static short GetInt16([CallerMemberName] string property = EMPTY)
|
||||
{
|
||||
var value = settings[property]?.Value?.ToString() ?? string.Empty;
|
||||
|
||||
if (short.TryParse(value, out short result))
|
||||
{
|
||||
this.WaitingTimeInMinutes = DefaultValues.WaitingTimeInMinutes.ToString();
|
||||
this.MessuringTimeInMinutes = DefaultValues.MessuringTimeInMinutes.ToString();
|
||||
return result;
|
||||
}
|
||||
|
||||
return default(short);
|
||||
}
|
||||
|
||||
private static int GetInt32([CallerMemberName] string property = EMPTY)
|
||||
{
|
||||
var value = settings[property]?.Value?.ToString() ?? string.Empty;
|
||||
|
||||
if (int.TryParse(value, out int result))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
return default(short);
|
||||
}
|
||||
|
||||
private static void SetValue<T>(this T value, [CallerMemberName] string property = EMPTY)
|
||||
{
|
||||
var key = settings.AllKeys.FirstOrDefault(x => x.Equals(property, StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
if (string.IsNullOrWhiteSpace(key))
|
||||
{
|
||||
key = property;
|
||||
|
||||
settings.Add(key, string.Empty);
|
||||
}
|
||||
|
||||
public string WaitingTimeInMinutes // { get; set; }
|
||||
{
|
||||
get => GetStringValue(DefaultValues.WaitingTimeInMinutes);
|
||||
set => this.NotifyPropertyChanged(value, DefaultValues.WaitingTimeInMinutes);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The mark on whitch should be notified for temperature change.
|
||||
/// By default +/-1°C.
|
||||
/// </summary>
|
||||
public string MessuringTimeInMinutes // { get; set; }
|
||||
{
|
||||
get => GetStringValue(DefaultValues.MessuringTimeInMinutes);
|
||||
set => this.NotifyPropertyChanged(value, DefaultValues.MessuringTimeInMinutes);
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
protected void NotifyPropertyChanged<T>(object currentValue, T defaultValue, [CallerMemberName] string property = EMPTY)
|
||||
{
|
||||
try
|
||||
{
|
||||
currentValue = Convert.ChangeType(currentValue, typeof(T));
|
||||
}
|
||||
catch
|
||||
{
|
||||
currentValue = defaultValue;
|
||||
}
|
||||
|
||||
currentValue.SetValue<T>(defaultValue, property);
|
||||
|
||||
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(property));
|
||||
}
|
||||
settings[key].Value = value?.ToString() ?? EMPTY;
|
||||
}
|
||||
|
||||
public static AppsettingsModel Model { get; } = new AppsettingsModel();
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="AppsettingsModel.WaitingTimeInMinutes"/>
|
||||
/// </summary>
|
||||
public static int WaitingTimeInMinutes => GetValue(DefaultValues.WaitingTimeInMinutes);
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="AppsettingsModel.MessuringTimeInMinutes"/>
|
||||
/// </summary>
|
||||
public static double MessuringTimeInMinutes => GetValue(DefaultValues.MessuringTimeInMinutes);
|
||||
|
||||
public static void Refresh()
|
||||
internal static void SaveSettings()
|
||||
{
|
||||
configuration.Save(ConfigurationSaveMode.Full);
|
||||
ConfigurationManager.RefreshSection("appSettings");
|
||||
}
|
||||
ConfigurationManager.RefreshSection(SETTINGS_SECTION);
|
||||
|
||||
private static int GetValue(int defaultValue, [CallerMemberName] string property = EMPTY)
|
||||
{
|
||||
var setting = configuration.AppSettings.Settings[property]?.Value;
|
||||
|
||||
if (int.TryParse($"{setting}", out var value))
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
private static double GetValue(double defaultValue, [CallerMemberName] string property = EMPTY)
|
||||
{
|
||||
var setting = configuration.AppSettings.Settings[property]?.Value;
|
||||
|
||||
if (double.TryParse($"{setting}", out var value))
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
private static string GetStringValue(object defaultValue, string format = EMPTY, [CallerMemberName] string property = EMPTY)
|
||||
{
|
||||
return configuration.AppSettings.Settings[property]?.Value ?? defaultValue?.ToString();
|
||||
}
|
||||
|
||||
private static void SetValue<T>(this object value, object @default, [CallerMemberName] string property = EMPTY)
|
||||
{
|
||||
if (value == null || value.Equals(default(T)))
|
||||
{
|
||||
value = @default;
|
||||
}
|
||||
|
||||
var saved = configuration.AppSettings.Settings[property];
|
||||
var currentValue = $"{value}";
|
||||
|
||||
if (saved is null)
|
||||
{
|
||||
configuration.AppSettings.Settings.Add(property, currentValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
configuration.AppSettings.Settings[property].Value = currentValue;
|
||||
}
|
||||
|
||||
configuration.Save(ConfigurationSaveMode.Modified);
|
||||
ConfigurationManager.RefreshSection("appSettings");
|
||||
configuration = ConfigurationManager.OpenExeConfiguration(Application.ExecutablePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,15 +1,27 @@
|
||||
namespace Xylem.Common.Ui.GenesisToolBox.Infrastructure
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.IO.Pipes;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Timers;
|
||||
|
||||
using static System.Globalization.NumberStyles;
|
||||
using SystemThreadingThread = System.Threading.Thread;
|
||||
|
||||
public class CordonelTempLut
|
||||
internal interface ITempMeterForm
|
||||
{
|
||||
void AddMessage(string message);
|
||||
|
||||
double AvgTOF();
|
||||
|
||||
IAsyncResult BeginInvoke(Delegate @delegate);
|
||||
|
||||
void StartRecording();
|
||||
}
|
||||
|
||||
public class CordonelTempLut
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
@ -31,162 +43,260 @@
|
||||
public Double Max { get; set; }
|
||||
}
|
||||
|
||||
class TemperatureSource : IDisposable
|
||||
public class TemperatureSource : IDisposable
|
||||
{
|
||||
private readonly NamedPipeClientStream pipeStream;
|
||||
private readonly StreamReader pipeReader;
|
||||
private readonly CultureInfo de;
|
||||
private readonly CultureInfo us;
|
||||
[DllImport("GMH3x32E.dll")]
|
||||
public static extern Int16 UniversalOpenCom(Int16 ini16COMPortNumber, UInt32 inui32BaudRate, Int16 inui16ConverterType, Int16 ini16Parity, Int16 ini16StoppBits);
|
||||
|
||||
public TemperatureSource()
|
||||
{
|
||||
try
|
||||
{
|
||||
this.pipeStream = new NamedPipeClientStream(".", "TempPipe", PipeDirection.In);
|
||||
this.pipeStream.Connect(3000);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
[DllImport("GMH3x32E.dll")]
|
||||
public static extern Int16 GMH_CloseCom();
|
||||
|
||||
if (this.pipeStream.IsConnected)
|
||||
{
|
||||
this.pipeReader = new StreamReader(this.pipeStream);
|
||||
}
|
||||
|
||||
this.de = new CultureInfo("de-DE");
|
||||
this.us = new CultureInfo("en-US");
|
||||
}
|
||||
[DllImport("GMH3x32E.dll")]
|
||||
unsafe public static extern Int16 GMH_Transmit(Int16 ini16DeviceAddress, Int16 ini16TransmitCode, Int16* refi16ptrPriority, double* refdblptrFloatValue, Int32* refi32ptrIntegerValue);
|
||||
|
||||
public TemperatureSource() => UniversalOpenCom(Appsettings.GMHPort, 4800, 8, 0, 0);
|
||||
|
||||
public double GetTemperature()
|
||||
{
|
||||
var result = default(short);
|
||||
var priority = default(short);
|
||||
var temperature = default(double);
|
||||
var value = default(int);
|
||||
|
||||
try
|
||||
unsafe
|
||||
{
|
||||
lock (this.pipeReader)
|
||||
{
|
||||
var value = $"{this.pipeReader.ReadLine()}";
|
||||
|
||||
if (double.TryParse(value, Any, this.us, out temperature) || double.TryParse(value, Any, this.de, out temperature))
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.Error.WriteLine(e.Message);
|
||||
result = GMH_Transmit(1, 0, &priority, &temperature, &value);
|
||||
}
|
||||
|
||||
return temperature;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
this.pipeReader?.Dispose();
|
||||
this.pipeStream?.Dispose();
|
||||
}
|
||||
|
||||
public void Flush()
|
||||
{
|
||||
this.pipeStream.Flush();
|
||||
this.pipeReader.BaseStream.Flush();
|
||||
}
|
||||
public void Dispose() => GMH_CloseCom();
|
||||
}
|
||||
|
||||
partial class AutomaticTemperatureCalibration
|
||||
{
|
||||
private const string WORKING_DIR = @".\temperature_calibrations";
|
||||
private const string MESSUREMENTS_FILE = @"_messurements.txt";
|
||||
private const string AGGREGATIONS_FILE = @"_aggregations.txt";
|
||||
private const NumberStyles ANY = NumberStyles.Any;
|
||||
|
||||
private readonly string pcbId;
|
||||
private readonly string messurementsFile;
|
||||
private readonly Func<double> sourceTOF;
|
||||
private readonly TemperatureSource temperature;
|
||||
private readonly string aggregationsFile;
|
||||
private readonly ITempMeterForm tempMeterForm;
|
||||
private readonly CultureInfo en;
|
||||
private readonly CultureInfo de;
|
||||
|
||||
private TemperatureSource temperatureSource;
|
||||
private Timer longTimer;
|
||||
private Timer shortTimer;
|
||||
private bool messuring;
|
||||
|
||||
public AutomaticTemperatureCalibration(string pcbId, Func<double> sourceTOF)
|
||||
public AutomaticTemperatureCalibration(string pcbId, ITempMeterForm genesisMeter)
|
||||
{
|
||||
this.pcbId = pcbId;
|
||||
this.sourceTOF = sourceTOF;
|
||||
this.messurementsFile = this.GetNextFile();
|
||||
this.temperature = new TemperatureSource();
|
||||
this.shortTimer = new Timer();
|
||||
this.longTimer = new Timer();
|
||||
this.tempMeterForm = genesisMeter;
|
||||
this.messurementsFile = this.GetOrCreateMessurementsFile(this.pcbId);
|
||||
this.aggregationsFile = this.GetOrCreateAggregationsFile(this.pcbId);
|
||||
this.temperatureSource = new TemperatureSource();
|
||||
this.en = new CultureInfo("en-US");
|
||||
this.de = new CultureInfo("de-DE");
|
||||
}
|
||||
|
||||
public void StartMessuring()
|
||||
{
|
||||
this.shortTimer.Enabled = true;
|
||||
this.shortTimer.AutoReset = true;
|
||||
this.shortTimer.Interval = 1_000;
|
||||
this.messuring = false;
|
||||
this.temperatureSource = new TemperatureSource();
|
||||
|
||||
this.shortTimer = new Timer(Appsettings.MessurementStep)
|
||||
{
|
||||
Enabled = true,
|
||||
AutoReset = true
|
||||
};
|
||||
this.shortTimer.Elapsed += this.ShortTimerElapsed;
|
||||
|
||||
// this.shortTimer.Start();
|
||||
|
||||
this.shortTimer.Stop();
|
||||
|
||||
this.longTimer.Enabled = true;
|
||||
this.longTimer.AutoReset = true;
|
||||
this.longTimer.Interval = 300_000;
|
||||
this.longTimer = new Timer(Appsettings.MessurementDauer)
|
||||
{
|
||||
Enabled = true,
|
||||
AutoReset = true
|
||||
};
|
||||
this.longTimer.Elapsed += this.LongTimerElapsed;
|
||||
|
||||
this.LongTimerElapsed(null, null);
|
||||
this.longTimer.Start();
|
||||
|
||||
File.AppendAllText(this.aggregationsFile, Environment.NewLine);
|
||||
}
|
||||
|
||||
private void LongTimerElapsed(Object sender, ElapsedEventArgs args)
|
||||
public void StopMessuring()
|
||||
{
|
||||
this.shortTimer?.Stop();
|
||||
this.shortTimer?.Dispose();
|
||||
this.shortTimer = null;
|
||||
|
||||
this.longTimer?.Stop();
|
||||
this.longTimer?.Dispose();
|
||||
this.longTimer = null;
|
||||
|
||||
this.temperatureSource?.Dispose();
|
||||
this.temperatureSource = null;
|
||||
}
|
||||
|
||||
private void LongTimerElapsed(Object sender, ElapsedEventArgs _)
|
||||
{
|
||||
this.messuring = !this.messuring;
|
||||
|
||||
SystemThreadingThread.Sleep(1_000);
|
||||
|
||||
if (this.messuring)
|
||||
{
|
||||
System.Threading.Thread.Sleep(1_000);
|
||||
|
||||
this.shortTimer.Enabled = true;
|
||||
this.shortTimer.AutoReset = true;
|
||||
this.shortTimer.Interval = 1_000;
|
||||
this.tempMeterForm.StartRecording();
|
||||
this.shortTimer.Start();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.shortTimer.Stop();
|
||||
|
||||
System.Threading.Thread.Sleep(1_000);
|
||||
File.AppendAllText(this.messurementsFile, Environment.NewLine);
|
||||
this.ParseMessurements();
|
||||
}
|
||||
}
|
||||
|
||||
private void ShortTimerElapsed(Object sender, ElapsedEventArgs args)
|
||||
{
|
||||
var currentTOF = this.sourceTOF();
|
||||
var currentT = this.temperature.GetTemperature();
|
||||
lock (this.shortTimer)
|
||||
{
|
||||
this.tempMeterForm.BeginInvoke(new Action(() =>
|
||||
{
|
||||
var currentTOF = this.tempMeterForm.AvgTOF();
|
||||
var currentT = this.temperatureSource.GetTemperature();
|
||||
var messurement = $"[{args.SignalTime:yyyy-MM-dd hh:mm:ss}]\t{this.pcbId,9}\t{currentT,5:00.00}\t{currentTOF,14:0.000000000000}";
|
||||
|
||||
File.AppendAllText(
|
||||
path: this.messurementsFile,
|
||||
contents: $"[{args.SignalTime:yyyy-MM-dd hh:mm:ss}]\t{this.pcbId,9}\t{currentT,5:00.00}\t{currentTOF,14:0.000000000000}{Environment.NewLine}");
|
||||
if (this.messuring)
|
||||
{
|
||||
this.tempMeterForm.AddMessage(messurement);
|
||||
File.AppendAllLines(this.messurementsFile, new[] { messurement });
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
public void StopMessuring()
|
||||
private String GetOrCreateMessurementsFile(string pcbId)
|
||||
{
|
||||
this.shortTimer.Stop();
|
||||
this.shortTimer.Dispose();
|
||||
Directory.CreateDirectory(WORKING_DIR);
|
||||
|
||||
this.longTimer.Stop();
|
||||
this.longTimer.Dispose();
|
||||
var filePath = $@"{WORKING_DIR}\{this.pcbId}{MESSUREMENTS_FILE}";
|
||||
|
||||
File.AppendAllText(filePath, Environment.NewLine);
|
||||
|
||||
return filePath;
|
||||
}
|
||||
|
||||
private String GetNextFile()
|
||||
private String GetOrCreateAggregationsFile(string pcbId)
|
||||
{
|
||||
var filesCount = Directory
|
||||
.CreateDirectory(@".\temperature_calibration")
|
||||
.GetFiles("*_messurements.txt")
|
||||
.Count();
|
||||
var nextFilePath = $@".\temperature_calibration\{filesCount + 1}_messurements.txt";
|
||||
Directory.CreateDirectory(WORKING_DIR);
|
||||
|
||||
File.WriteAllText(nextFilePath, string.Empty);
|
||||
var filePath = $@"{WORKING_DIR}\{this.pcbId}{AGGREGATIONS_FILE}";
|
||||
|
||||
return nextFilePath;
|
||||
if (!File.Exists(filePath))
|
||||
{
|
||||
File.WriteAllLines(filePath, new[] { Messurements.Header });
|
||||
}
|
||||
|
||||
return filePath;
|
||||
}
|
||||
|
||||
private void ParseMessurements()
|
||||
{
|
||||
var messurementLines = File.ReadAllLines(this.messurementsFile);
|
||||
var messurements = new Messurements(this.pcbId);
|
||||
|
||||
File.WriteAllText(this.messurementsFile, string.Empty);
|
||||
|
||||
foreach (var messurementLine in messurementLines)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(messurementLine))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var tokens = messurementLine
|
||||
.Split(new[] { '\t' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
if (tokens.Length != 4)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var dateString = tokens[0];
|
||||
var pcbString = tokens[1];
|
||||
var tString = tokens[2];
|
||||
var tofString = tokens[3];
|
||||
|
||||
var currentT = default(double);
|
||||
var currentTOF = default(double);
|
||||
|
||||
try
|
||||
{
|
||||
var tParsed = double.TryParse(tString, ANY, this.en, out currentT) || double.TryParse(tString, ANY, this.de, out currentT);
|
||||
var tofParsed = double.TryParse(tofString, ANY, this.en, out currentTOF) || double.TryParse(tofString, ANY, this.de, out currentTOF);
|
||||
}
|
||||
catch
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
messurements.Add(currentT, currentTOF);
|
||||
}
|
||||
|
||||
File.AppendAllLines(this.aggregationsFile, new[] { messurements.ToString() });
|
||||
}
|
||||
}
|
||||
|
||||
class Messurements
|
||||
{
|
||||
private readonly string pcbId;
|
||||
|
||||
// _______________________________ t _____ tof _________________
|
||||
private readonly ICollection<Tuple<double, double>> messurements
|
||||
= new List<Tuple<double, double>>();
|
||||
|
||||
public Messurements(string pcbId)
|
||||
=> this.pcbId = pcbId;
|
||||
|
||||
public double MinT => this.messurements.Min(x => x.Item1);
|
||||
|
||||
public double MinTOF => this.messurements.Min(x => x.Item2);
|
||||
|
||||
public double AvgT => this.messurements.Average(x => x.Item1);
|
||||
|
||||
public double AvgTOF => this.messurements.Average(x => x.Item2);
|
||||
|
||||
public double MaxT => this.messurements.Max(x => x.Item1);
|
||||
|
||||
public double MaxTOF => this.messurements.Max(x => x.Item2);
|
||||
|
||||
public double DifT => Math.Abs(this.MinT - this.MaxT);
|
||||
|
||||
public double DifTOF => Math.Abs(this.MinTOF - this.MaxTOF);
|
||||
|
||||
public int Count => this.messurements.Count;
|
||||
|
||||
public override String ToString()
|
||||
=> $"{this.pcbId}"
|
||||
+ $"\t{this.MinT:0.00}"
|
||||
+ $"\t{this.MinTOF:0.0000000000}"
|
||||
+ $"\t{this.AvgT:0.00}"
|
||||
+ $"\t{this.AvgTOF:0.0000000000}"
|
||||
+ $"\t{this.MaxT:0.00}"
|
||||
+ $"\t{this.MaxTOF:0.0000000000}"
|
||||
+ $"\t{this.DifT:0.00}"
|
||||
+ $"\t{this.DifTOF:0.0000000000}"
|
||||
+ $"\t{this.Count}";
|
||||
|
||||
public void Add(double t, double tof)
|
||||
=> this.messurements.Add(new Tuple<double, double>(t, tof));
|
||||
|
||||
public static string Header
|
||||
=> $"Pcb Id\tMin °C\tMin TOF\tAvg °C\tAvg TOF\tMax °C\tMax TOF\tDif °C\tDif TOF\tCount";
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,121 @@
|
||||
namespace LaaProductionWeb.API.Production
|
||||
{
|
||||
using LaaProductionSQL.Interfaces;
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Web.Http;
|
||||
|
||||
[Authorize]
|
||||
[RoutePrefix("API/Production/TempMeter")]
|
||||
public class TempMeterController : ApiController
|
||||
{
|
||||
private readonly ISQLConnection sqlConnection;
|
||||
|
||||
public TempMeterController(ISQLConnection sqlConnection)
|
||||
=> this.sqlConnection = sqlConnection;
|
||||
|
||||
[HttpGet]
|
||||
[Route(nameof(All))]
|
||||
public IHttpActionResult All()
|
||||
{
|
||||
var messurements = this.sqlConnection
|
||||
.CreateCommand(@"SELECT [Id]
|
||||
, [PcbId]
|
||||
, [RefTempC]
|
||||
, [AvgTof]
|
||||
FROM [CordonelTempLuts]
|
||||
WHERE [Active] = 1
|
||||
ORDER BY [PcbId], [RefTempC]")
|
||||
.ExecuteReader(x => new Messurement
|
||||
{
|
||||
Id = x.GetInt(),
|
||||
PcbId = x.GetInt(),
|
||||
AvgT = x.GetValue<double>(),
|
||||
AvgTOF = x.GetValue<double>()
|
||||
});
|
||||
|
||||
return this.Json(messurements);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("{pcbId}")]
|
||||
public IHttpActionResult Get(int pcbId)
|
||||
{
|
||||
var messurement = this.sqlConnection
|
||||
.CreateCommand($@"SELECT [Id]
|
||||
, [PcbId]
|
||||
, [RefTempC]
|
||||
, [AvgTof]
|
||||
FROM [CordonelTempLuts]
|
||||
WHERE [Active] = 1
|
||||
AND [PcbId] = @{nameof(pcbId)}
|
||||
ORDER BY [PcbId], [RefTempC]")
|
||||
.SetParameter(nameof(pcbId), pcbId)
|
||||
.FirstOrDefault(x => new Messurement
|
||||
{
|
||||
Id = x.GetInt(),
|
||||
PcbId = x.GetInt(),
|
||||
AvgT = x.GetValue<double>(),
|
||||
AvgTOF = x.GetValue<double>()
|
||||
});
|
||||
|
||||
return this.Json(messurement);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IHttpActionResult Post([FromBody] Messurement[] messurements)
|
||||
{
|
||||
if (messurements?.Length <= 0)
|
||||
{
|
||||
return this.StatusCode(HttpStatusCode.NotModified);
|
||||
}
|
||||
|
||||
var pcbs = messurements
|
||||
.Select(x => x.PcbId)
|
||||
.Distinct();
|
||||
|
||||
if (pcbs.Count() > 1)
|
||||
{
|
||||
return this.StatusCode(HttpStatusCode.Conflict);
|
||||
}
|
||||
|
||||
var pcbId = pcbs.First();
|
||||
var recordsDeleted = this.sqlConnection
|
||||
.CreateCommand($"DELETE FROM [CordonelTempLuts] WHERE [PcbId] = @{nameof(pcbId)}")
|
||||
.SetParameter(nameof(pcbId), pcbId)
|
||||
.ExecuteNonQuery();
|
||||
|
||||
var values = new List<string>();
|
||||
var id = 1;
|
||||
|
||||
foreach (var m in messurements.OrderBy(x => x.AvgT))
|
||||
{
|
||||
values.Add($"('{pcbId}', '{id++}', '{m.AvgT:0.00}', '{m.AvgTOF:0.0000000000}')");
|
||||
}
|
||||
|
||||
var recordsAdded = this.sqlConnection
|
||||
.CreateCommand($@"INSERT INTO [CordonelTempLuts]
|
||||
( [PcbId]
|
||||
, [Id]
|
||||
, [RefTempC]
|
||||
, [AvgTof])
|
||||
VALUES {string.Join(", ", values)}")
|
||||
.ExecuteNonQuery();
|
||||
|
||||
return this.Ok(recordsAdded);
|
||||
}
|
||||
}
|
||||
|
||||
public class Messurement
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public int PcbId { get; set; }
|
||||
|
||||
public double AvgT { get; set; }
|
||||
|
||||
public double AvgTOF { get; set; }
|
||||
}
|
||||
}
|
||||
@ -179,6 +179,7 @@
|
||||
<Compile Include="API\Personalization\EmployeesController.cs" />
|
||||
<Compile Include="API\Personalization\RolesController.cs" />
|
||||
<Compile Include="API\Personalization\SoftwareController.cs" />
|
||||
<Compile Include="API\Production\TempMeterController.cs" />
|
||||
<Compile Include="API\Production\VFMController.cs" />
|
||||
<Compile Include="API\Search\WildcardController.cs" />
|
||||
<Compile Include="App_Infrastructure\AllowedRolesAttribute.cs" />
|
||||
|
||||
Loading…
Reference in New Issue
Block a user