From 6f81be6ebe0942cbc29ed0083c1422c38204c715 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Mon, 15 Jun 2020 19:29:17 +0200 Subject: [PATCH] Removed old method + fix startup --- .../ServerConfigController.cs | 23 ++++++++++- Thermo.Active.NC/NcAdapter.cs | 38 ++++--------------- .../Controllers/WebApi/RecipeController.cs | 2 +- Thermo.Active/program.cs | 6 +++ 4 files changed, 36 insertions(+), 33 deletions(-) diff --git a/Thermo.Active.Config/ServerConfigController.cs b/Thermo.Active.Config/ServerConfigController.cs index fe3ba0da..d4efe01d 100644 --- a/Thermo.Active.Config/ServerConfigController.cs +++ b/Thermo.Active.Config/ServerConfigController.cs @@ -40,6 +40,27 @@ namespace Thermo.Active.Config // ReadCMSConnectConfig(); ReadMacros(); ReadScadaFile(); + } + catch (XmlException ex) + { + ExceptionManager.ManageError(ERROR_LEVEL.FATAL, + "Error while reading file: " + ex.SourceUri + + "\n Error: " + ex.Message, + true + ); + } + catch (Exception ex) + { + var message = ex.Message; + if (ex.InnerException != null) + message += "\n" + ex.InnerException.Message; + ExceptionManager.ManageError(ERROR_LEVEL.FATAL, message, true); + } + } + public static void ReadLastRecipe() + { + try + { ReadLiveData(); } catch (XmlException ex) @@ -729,7 +750,7 @@ namespace Thermo.Active.Config SetpointThermo = 0, MaxPower = riferimento.Potenza, NumResist = 1, - CalcIchMin=riferimento.Modello.Contains("Quarzo") + CalcIchMin = riferimento.Modello.Contains("Quarzo") }); } else diff --git a/Thermo.Active.NC/NcAdapter.cs b/Thermo.Active.NC/NcAdapter.cs index 9c5dd89b..326538b1 100644 --- a/Thermo.Active.NC/NcAdapter.cs +++ b/Thermo.Active.NC/NcAdapter.cs @@ -1368,39 +1368,15 @@ namespace Thermo.Active.NC // solo x S7... if (NcConfig.NcVendor == NC_VENDOR.S7NET) { - // single old method (OK) - if (false) + // ciclo x ogni valore della ricetta aggiornata ricevuto + foreach (var item in updtRecipe) { -#if false - // ciclo x ogni valore della ricetta aggiornata ricevuto - ThermoModels.RecipeParam currParam; - foreach (var item in updtRecipe) - { - // salvo SOLO il setpoint HMI... - currParam = new ThermoModels.RecipeParam() - { - Id = (short)item.Value.Id, - SetpointHMI = item.Value.SetpointHMI * item.Value.ScaleFactor - }; - // scrivo! - CmsError cmsError = numericalControl.PLC_WRecipeParam(currParam); - if (cmsError.IsError()) - return cmsError; - } -#endif - } - else - { - // ciclo x ogni valore della ricetta aggiornata ricevuto - foreach (var item in updtRecipe) - { - newParameters.Add(item.Value.Id, (int)(item.Value.SetpointHMI * item.Value.ScaleFactor)); - } - // scrivo! - CmsError cmsError = numericalControl.PLC_WRecipeParameters(newParameters); - if (cmsError.IsError()) - return cmsError; + newParameters.Add(item.Value.Id, (int)(item.Value.SetpointHMI * item.Value.ScaleFactor)); } + // scrivo! + CmsError cmsError = numericalControl.PLC_WRecipeParameters(newParameters); + if (cmsError.IsError()) + return cmsError; } else { diff --git a/Thermo.Active/Controllers/WebApi/RecipeController.cs b/Thermo.Active/Controllers/WebApi/RecipeController.cs index c77b079e..50011adc 100644 --- a/Thermo.Active/Controllers/WebApi/RecipeController.cs +++ b/Thermo.Active/Controllers/WebApi/RecipeController.cs @@ -445,7 +445,7 @@ namespace Thermo.Active.Controllers.WebApi } } - protected static CmsError WriteCurrentRecipeToPlc() + public static CmsError WriteCurrentRecipeToPlc() { CmsError checkError = NO_ERROR; diff --git a/Thermo.Active/program.cs b/Thermo.Active/program.cs index b8a3d6ff..fa4ac281 100644 --- a/Thermo.Active/program.cs +++ b/Thermo.Active/program.cs @@ -18,6 +18,7 @@ using static Thermo.Active.Config.ServerConfig; using static Thermo.Active.Model.Constants; using static Thermo.Active.Utils.ThermoActiveLogger; using static Thermo.Active.Utils.ExceptionManager; +using Thermo.Active.Controllers.WebApi; namespace Thermo.Active { @@ -84,6 +85,11 @@ namespace Thermo.Active if (!string.IsNullOrWhiteSpace(ServerStartupConfig.ServerAddress.ToString())) opt.Urls.Add("http://" + ServerStartupConfig.ServerAddress.ToString() + ":" + ServerStartupConfig.ServerPort.ToString()); + // read and save last CURRENT RECIPE data... + ServerConfigController.ReadLastRecipe(); + RecipeController.WriteCurrentRecipeToPlc(); + + //starts threads using (WebApp.Start(opt)) { if (databaseStatus)