From 2feb30bef62ad4fcf835899cbffb76b3cbfca0e9 Mon Sep 17 00:00:00 2001 From: Thermo_SIM Date: Fri, 26 Mar 2021 18:10:32 +0100 Subject: [PATCH] Fix load Recipe --- Thermo.Active.Core/ThreadsFunctions.cs | 13 +++++++++++++ Thermo.Active.Model/Constants.cs | 1 + Thermo.Active.NC/NcFileAdapter.cs | 13 +++++++------ .../Controllers/WebApi/RecipeController.cs | 7 ++++++- 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/Thermo.Active.Core/ThreadsFunctions.cs b/Thermo.Active.Core/ThreadsFunctions.cs index 52d797c3..40ba131b 100644 --- a/Thermo.Active.Core/ThreadsFunctions.cs +++ b/Thermo.Active.Core/ThreadsFunctions.cs @@ -50,6 +50,7 @@ public static class ThreadsFunctions public static int recipeRtCounter = 0; public static bool reconnectionIsRunning = false; public static bool forcetakeSnapshot = false; + public static bool ReloadAfterLoad = false; #endregion Public Fields @@ -1382,6 +1383,13 @@ public static class ThreadsFunctions if (libraryError.errorCode != 0) ManageLibraryError(libraryError); + + MessageServices.Current.Subscribe(RECIPE_LOADED, (a, b) => + { + ReloadAfterLoad = true; + recipeRtCounter = 0; + }); + while (true) { // ogni n counter leggo anche dati NON RT @@ -1426,6 +1434,11 @@ public static class ThreadsFunctions // ora gestisco l'ack della richiesta libraryError = ncAdapter.doAckSetpointInvalidated(); } + if(ReloadAfterLoad) + { + ReloadAfterLoad = false; + setpointHmiInvalidated = true; + } // pubblico booleana dei setpointHMI invalidati MessageServices.Current.Publish(SEND_THERMO_RECIPE_SETPOINTHMI_CHANGED, null, setpointHmiInvalidated); } diff --git a/Thermo.Active.Model/Constants.cs b/Thermo.Active.Model/Constants.cs index 9aa704af..a97e3282 100644 --- a/Thermo.Active.Model/Constants.cs +++ b/Thermo.Active.Model/Constants.cs @@ -143,6 +143,7 @@ namespace Thermo.Active.Model public const string SEND_THERMO_WARMERS_DATA = "SEND_THERMO_WARMERS_DATA"; public const string SEND_THREADS_STATUS = "THREAD_STATUS"; public const string SEND_USER_SOFTKEYS_DATA = "SEND_USER_SOFTKEYS_DATA"; + public const string RECIPE_LOADED = "RECIPE_LOADED"; // Names in the xml file public const string SERVER_CONFIG_KEY = "serverConfig"; diff --git a/Thermo.Active.NC/NcFileAdapter.cs b/Thermo.Active.NC/NcFileAdapter.cs index 4dcab151..db854ca1 100644 --- a/Thermo.Active.NC/NcFileAdapter.cs +++ b/Thermo.Active.NC/NcFileAdapter.cs @@ -724,7 +724,6 @@ namespace Thermo.Active.NC // check filePath... if (File.Exists(RECIPE_TEMPLATE_PATH)) { - answ = true; // load all text data var rawData = File.ReadAllText(RECIPE_TEMPLATE_PATH); @@ -737,18 +736,20 @@ namespace Thermo.Active.NC // fix Modifica dati RecipeLiveData.hasChanged = false; // from template --> reset (if present) overview data... - if (RecipeLiveData.RecipeOverview != null) + /*if (RecipeLiveData.RecipeOverview != null) { foreach (var item in RecipeLiveData.RecipeOverview) { RecipeLiveData.RecipeOverview[item.Key] = RecipeCatStatus.Unchanged; } - } + }*/ // update NAME - RecipeLiveData.RecipeName = $"{DateTime.Now:yyyyMMss_HHmmss}.json"; + RecipeLiveData.RecipeName = $"NEW_RECIPE_{DateTime.Now:HH_mm_ss}"; + + answ = true; } - catch - { } + catch(Exception e) + { return answ; } // update current live data! SaveRecipeCurrent(); } diff --git a/Thermo.Active/Controllers/WebApi/RecipeController.cs b/Thermo.Active/Controllers/WebApi/RecipeController.cs index 6dc3efe6..70492c85 100644 --- a/Thermo.Active/Controllers/WebApi/RecipeController.cs +++ b/Thermo.Active/Controllers/WebApi/RecipeController.cs @@ -7,6 +7,7 @@ using System.Linq; using System.Net; using System.Net.Http; using System.Security.Claims; +using System.Threading; using System.Threading.Tasks; using System.Web; using System.Web.Http; @@ -140,7 +141,8 @@ namespace Thermo.Active.Controllers.WebApi var originalRecipe = NcFileAdapter.LoadRecipe($"{NcAdapter.RecipeLiveData.RecipeDir}{NcAdapter.RecipeLiveData.RecipeName}"); // comparazione parametri... bool isEqual = false; - ncAdapter.paramsComparer(originalRecipe.RecipeParameters, NcAdapter.RecipeLiveData.RecipeParameters, out isEqual); + if(originalRecipe != null) + ncAdapter.paramsComparer(originalRecipe.RecipeParameters, NcAdapter.RecipeLiveData.RecipeParameters, out isEqual); // salvo se la ricetta SIA cambiata NcAdapter.RecipeLiveData.hasChanged = !isEqual; @@ -323,6 +325,7 @@ namespace Thermo.Active.Controllers.WebApi notifyHmi(); // Get new data from PLC + /* libraryError = ncAdapter.ReadWarmers(false, out Dictionary currWarmers); if (libraryError.IsError()) { @@ -331,6 +334,8 @@ namespace Thermo.Active.Controllers.WebApi } // pubblico MessageServices.Current.Publish(SEND_THERMO_WARMERS_DATA, null, currWarmers); + */ + MessageServices.Current.Publish(RECIPE_LOADED, null); // ritorno solo fatto! return Ok();