From 3db4f8ded4a391599b05b0be28c7e41b75d1e5fb Mon Sep 17 00:00:00 2001 From: "Samuele E. Locatelli" Date: Tue, 23 Feb 2021 15:41:32 +0100 Subject: [PATCH] Fix gestione chiusura thread discovery x setup e active --- .../ThermoCamComunicator.cs | 10 ++++ Thermo.Active.Core/ThreadsFunctions.cs | 5 ++ Thermo.Cam.Setup/MainForm.Designer.cs | 36 +++++++++++-- Thermo.Cam.Setup/MainForm.cs | 26 +++++++++- Thermo.Cam.Setup/Thermo.Cam.Setup.csproj | 1 + Thermo.Cam.Setup/app.config | 25 +++++---- Thermo.Cam.Utils/TCContr.cs | 51 +++++++++++++++---- 7 files changed, 128 insertions(+), 26 deletions(-) diff --git a/THermo.Active.Thermocamera/ThermoCamComunicator.cs b/THermo.Active.Thermocamera/ThermoCamComunicator.cs index 41cea967..7639c5d8 100644 --- a/THermo.Active.Thermocamera/ThermoCamComunicator.cs +++ b/THermo.Active.Thermocamera/ThermoCamComunicator.cs @@ -74,6 +74,16 @@ namespace Thermo.Active.Thermocamera #region Public Methods + /// + /// chiusura metodi legati a ThermoCam (discovery e connessione) + /// + public void Dispose() + { + TCamLive.stopDiscovery(); + TCamLive.DisconnectCamera(); + TCamLive.DisposeCamera(); + } + /// /// Restituisce lettura di tutti i punti richiesti (es centroidi riscaldi) /// diff --git a/Thermo.Active.Core/ThreadsFunctions.cs b/Thermo.Active.Core/ThreadsFunctions.cs index 4d718f0c..be559e9c 100644 --- a/Thermo.Active.Core/ThreadsFunctions.cs +++ b/Thermo.Active.Core/ThreadsFunctions.cs @@ -385,6 +385,11 @@ public static class ThreadsFunctions { ncAdapter.Dispose(); } + finally + { + // chiudo thermocam + TCCom.Dispose(); + } } public static void ManageLibraryError(CmsError libraryError) diff --git a/Thermo.Cam.Setup/MainForm.Designer.cs b/Thermo.Cam.Setup/MainForm.Designer.cs index 5f84371a..9703b6b8 100644 --- a/Thermo.Cam.Setup/MainForm.Designer.cs +++ b/Thermo.Cam.Setup/MainForm.Designer.cs @@ -83,6 +83,8 @@ this.columnHeader2 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.columnHeader3 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.timerUI = new System.Windows.Forms.Timer(this.components); + this.lblMs = new System.Windows.Forms.Label(); + this.btnExportConfig = new System.Windows.Forms.Button(); this.menuStrip1.SuspendLayout(); this.statusStrip1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pBoxA)).BeginInit(); @@ -97,6 +99,7 @@ // // menuStrip1 // + this.menuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20); this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.fileToolStripMenuItem, this.cameraToolStripMenuItem}); @@ -144,6 +147,7 @@ // // statusStrip1 // + this.statusStrip1.ImageScalingSize = new System.Drawing.Size(20, 20); this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.toolStripConnectionStatus, this.progBar, @@ -186,6 +190,7 @@ this.panelCmd.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left))); this.panelCmd.BackColor = System.Drawing.SystemColors.ControlDark; + this.panelCmd.Controls.Add(this.btnExportConfig); this.panelCmd.Controls.Add(this.groupBox5); this.panelCmd.Controls.Add(this.groupBox4); this.panelCmd.Controls.Add(this.groupBox3); @@ -199,6 +204,7 @@ // // groupBox5 // + this.groupBox5.Controls.Add(this.lblMs); this.groupBox5.Controls.Add(this.txtSPeriod); this.groupBox5.Controls.Add(this.chkSaveAll); this.groupBox5.Controls.Add(this.chkLive); @@ -211,11 +217,11 @@ // // txtSPeriod // - this.txtSPeriod.Location = new System.Drawing.Point(120, 37); + this.txtSPeriod.Location = new System.Drawing.Point(99, 18); this.txtSPeriod.Name = "txtSPeriod"; this.txtSPeriod.Size = new System.Drawing.Size(49, 20); this.txtSPeriod.TabIndex = 21; - this.txtSPeriod.Text = "100"; + this.txtSPeriod.Text = "200"; this.txtSPeriod.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; // // chkSaveAll @@ -223,9 +229,9 @@ this.chkSaveAll.AutoSize = true; this.chkSaveAll.Location = new System.Drawing.Point(8, 39); this.chkSaveAll.Name = "chkSaveAll"; - this.chkSaveAll.Size = new System.Drawing.Size(96, 17); + this.chkSaveAll.Size = new System.Drawing.Size(51, 17); this.chkSaveAll.TabIndex = 20; - this.chkSaveAll.Text = "Save every ms"; + this.chkSaveAll.Text = "Save"; this.chkSaveAll.UseVisualStyleBackColor = true; // // chkLive @@ -625,6 +631,26 @@ // this.timerUI.Tick += new System.EventHandler(this.timerUI_Tick); // + // lblMs + // + this.lblMs.AutoSize = true; + this.lblMs.Location = new System.Drawing.Point(149, 21); + this.lblMs.Name = "lblMs"; + this.lblMs.Size = new System.Drawing.Size(20, 13); + this.lblMs.TabIndex = 22; + this.lblMs.Text = "ms"; + // + // btnExportConfig + // + this.btnExportConfig.Font = new System.Drawing.Font("Microsoft Sans Serif", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.btnExportConfig.Location = new System.Drawing.Point(8, 491); + this.btnExportConfig.Name = "btnExportConfig"; + this.btnExportConfig.Size = new System.Drawing.Size(177, 64); + this.btnExportConfig.TabIndex = 20; + this.btnExportConfig.Text = "Export Config"; + this.btnExportConfig.UseVisualStyleBackColor = true; + this.btnExportConfig.Click += new System.EventHandler(this.btnExportConfig_Click); + // // MainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -725,6 +751,8 @@ private System.Windows.Forms.Button btnDeleteOlder; private System.Windows.Forms.TextBox txtMaxHours; private System.Windows.Forms.Timer timerUI; + private System.Windows.Forms.Button btnExportConfig; + private System.Windows.Forms.Label lblMs; } } diff --git a/Thermo.Cam.Setup/MainForm.cs b/Thermo.Cam.Setup/MainForm.cs index 0bc4b9f9..60e9108c 100644 --- a/Thermo.Cam.Setup/MainForm.cs +++ b/Thermo.Cam.Setup/MainForm.cs @@ -201,6 +201,12 @@ namespace Thermo.Cam.Setup #endregion Protected Properties + #region Public Properties + + public object ConfigurationManager { get; private set; } + + #endregion Public Properties + #region Private Methods private void btnDeleteOlder_Click(object sender, EventArgs e) @@ -210,6 +216,20 @@ namespace Thermo.Cam.Setup TCamCtrl.cleanDataDir(maxHours); } + private void btnExportConfig_Click(object sender, EventArgs e) + { + // effettua esportazione config in area ThermoActive + string ThermoConfPath = System.Configuration.ConfigurationManager.AppSettings["ThermoConfPath"]; + if (!Directory.Exists(ThermoConfPath)) + { + Directory.CreateDirectory(ThermoConfPath); + } + // salvo conf corrente + TCamCtrl.saveConf(); + // salvo in folder target + TCamCtrl.saveConf(ThermoConfPath); + } + private void btnLoad_Click(object sender, EventArgs e) { // "" --> carica ultima scattata (altrimenti nome) @@ -350,7 +370,11 @@ namespace Thermo.Cam.Setup private void MainForm_FormClosing(object sender, FormClosingEventArgs e) { timerUI.Stop(); + TCamCtrl.stopDiscovery(); + TCamCtrl.DisconnectCamera(); TCamCtrl.DisposeCamera(); + //this.Dispose(true); + //this.Close(); } private void MainForm_Load(object sender, EventArgs e) @@ -584,7 +608,7 @@ namespace Thermo.Cam.Setup } } // avanzo prog bar - progBar.Increment(3); + progBar.Increment(5); if (progBar.Value >= progBar.Maximum) { progBar.Value = 0; diff --git a/Thermo.Cam.Setup/Thermo.Cam.Setup.csproj b/Thermo.Cam.Setup/Thermo.Cam.Setup.csproj index 2001be79..486e73f5 100644 --- a/Thermo.Cam.Setup/Thermo.Cam.Setup.csproj +++ b/Thermo.Cam.Setup/Thermo.Cam.Setup.csproj @@ -65,6 +65,7 @@ ..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll + diff --git a/Thermo.Cam.Setup/app.config b/Thermo.Cam.Setup/app.config index 3ce1d1a5..45bcae17 100644 --- a/Thermo.Cam.Setup/app.config +++ b/Thermo.Cam.Setup/app.config @@ -1,12 +1,17 @@  - - - - - - - - - - + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Thermo.Cam.Utils/TCContr.cs b/Thermo.Cam.Utils/TCContr.cs index 714fdcf3..ae2979bf 100644 --- a/Thermo.Cam.Utils/TCContr.cs +++ b/Thermo.Cam.Utils/TCContr.cs @@ -443,20 +443,21 @@ namespace Thermo.Cam.Utils public void discoveryCamera() { - try { - // se no connesso così prosegue... - if (!IRCam.ThermoCamera.IsConnected) + try { - DiscoThread.CameraAddress = currConf.CameraAddress; - DiscoThread.CameraName = currConf.CameraName; - if (DiscoThread.doAutoConnect) + // se no connesso così prosegue... + if (!IRCam.ThermoCamera.IsConnected) { - // avvio - DiscoThread.Start(); + DiscoThread.CameraAddress = currConf.CameraAddress; + DiscoThread.CameraName = currConf.CameraName; + if (DiscoThread.doAutoConnect) + { + // avvio + DiscoThread.Start(); + } } } - } - catch(Exception exc) + catch (Exception exc) { Console.WriteLine($"EXCEPTION discoveryCamera: {Environment.NewLine}{exc}"); } @@ -769,7 +770,7 @@ namespace Thermo.Cam.Utils } /// - /// Salva su file il file di conf corrente + /// Salva il file di conf corrente (in path default) /// /// public bool saveConf() @@ -786,6 +787,34 @@ namespace Thermo.Cam.Utils return answ; } + /// + /// Salva su file nella dir richiesta il file di conf corrente + /// + /// directory destinazione x conf + /// + public bool saveConf(string destPath) + { + bool answ = false; + try + { + string rawData = JsonConvert.SerializeObject(currConf, Formatting.Indented); + File.WriteAllText($"{destPath}\\{confFileName}", rawData); + answ = true; + } + catch + { } + return answ; + } + + /// + /// fermo discovery camera + /// + public void stopDiscovery() + { + // fermo camera discovery + DiscoThread.Stop(); + } + /// /// Acquisisce immagine da FLIR Cam ///