From cd2f21fe0190c4a30a5a8f7410e1e44431029049 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Thu, 11 Jun 2020 19:45:31 +0200 Subject: [PATCH 1/6] preliminary management of config request strb/ack --- Thermo.Active.Core/ThreadsFunctions.cs | 122 +++++++++++++++++++++++ Thermo.Active.Core/ThreadsHandler.cs | 1 + Thermo.Active.NC/NcAdapter.cs | 83 +++++++++++++++ Thermo.Active/Properties/AssemblyInfo.cs | 2 +- 4 files changed, 207 insertions(+), 1 deletion(-) diff --git a/Thermo.Active.Core/ThreadsFunctions.cs b/Thermo.Active.Core/ThreadsFunctions.cs index 2731f119..9d8c00d6 100644 --- a/Thermo.Active.Core/ThreadsFunctions.cs +++ b/Thermo.Active.Core/ThreadsFunctions.cs @@ -87,6 +87,128 @@ public static class ThreadsFunctions } } + /// + /// Manage status/command words for actions + /// + public static void ManageStatusCommand() + { + NcAdapter ncAdapter = new NcAdapter(); + Stopwatch sw = new Stopwatch(); + try + { + CmsError libraryError = ncAdapter.Connect(); + if (libraryError.errorCode != 0) + ManageLibraryError(libraryError); + + while (true) + { + sw.Restart(); + + // Check if client is connected + if (ncAdapter.numericalControl.NC_IsConnected()) + { + // Manage status command + libraryError = ncAdapter.ManageStatusCommand(); + } + else + RestoreConnection(); + + sw.Stop(); + + //Update thread timer + UpdateStat(MethodBase.GetCurrentMethod().Name, sw.ElapsedMilliseconds); + + // Wait + Thread.Sleep(CalcSleepTime(250, (int)sw.ElapsedMilliseconds)); + } + } + catch (ThreadAbortException ex) + { + ncAdapter.Dispose(); + } + } + + /// + /// Manage action for conf request + /// + public static void ManageConfRequest() + { + NcAdapter ncAdapter = new NcAdapter(); + Stopwatch sw = new Stopwatch(); + try + { + CmsError libraryError = ncAdapter.Connect(); + if (libraryError.errorCode != 0) + ManageLibraryError(libraryError); + + while (true) + { + sw.Restart(); + + // Check if client is connected + if (ncAdapter.numericalControl.NC_IsConnected()) + { + // Manage status command + libraryError = ncAdapter.ManageConfRequest(); + } + else + RestoreConnection(); + + sw.Stop(); + + //Update thread timer + UpdateStat(MethodBase.GetCurrentMethod().Name, sw.ElapsedMilliseconds); + + // Wait + Thread.Sleep(CalcSleepTime(1000, (int)sw.ElapsedMilliseconds)); + } + } + catch (ThreadAbortException ex) + { + ncAdapter.Dispose(); + } + } + /// + /// Manage action for conf request + /// + public static void ManageProdUpdate() + { + NcAdapter ncAdapter = new NcAdapter(); + Stopwatch sw = new Stopwatch(); + try + { + CmsError libraryError = ncAdapter.Connect(); + if (libraryError.errorCode != 0) + ManageLibraryError(libraryError); + + while (true) + { + sw.Restart(); + + // Check if client is connected + if (ncAdapter.numericalControl.NC_IsConnected()) + { + // Manage status command + libraryError = ncAdapter.ManageProdUpdate(); + } + else + RestoreConnection(); + + sw.Stop(); + + //Update thread timer + UpdateStat(MethodBase.GetCurrentMethod().Name, sw.ElapsedMilliseconds); + + // Wait + Thread.Sleep(CalcSleepTime(1000, (int)sw.ElapsedMilliseconds)); + } + } + catch (ThreadAbortException ex) + { + ncAdapter.Dispose(); + } + } + public static void ReadAlarms() { NcAdapter ncAdapter = new NcAdapter(); diff --git a/Thermo.Active.Core/ThreadsHandler.cs b/Thermo.Active.Core/ThreadsHandler.cs index 5b7b22b3..50186c37 100644 --- a/Thermo.Active.Core/ThreadsHandler.cs +++ b/Thermo.Active.Core/ThreadsHandler.cs @@ -11,6 +11,7 @@ namespace Thermo.Active.Core private static List ThreadsFunctionsList = new List { ThreadsFunctions.ManageWatchdog, + ThreadsFunctions.ManageStatusCommand, ThreadsFunctions.ReadAlarms, ThreadsFunctions.ReadPowerOnData, ThreadsFunctions.StatThread, diff --git a/Thermo.Active.NC/NcAdapter.cs b/Thermo.Active.NC/NcAdapter.cs index 529de3b2..30ab937e 100644 --- a/Thermo.Active.NC/NcAdapter.cs +++ b/Thermo.Active.NC/NcAdapter.cs @@ -28,6 +28,15 @@ namespace Thermo.Active.NC { public class NcAdapter : IDisposable { + + // variabili delle richieste da PLC + private static bool ThermoReqConfWarmerStr; + private static bool ThermoReqConfWarmerAck; + private static bool ThermoReqConfRecipeStr; + private static bool ThermoReqConfRecipeAck; + private static bool ThermoProdUpdatedStr; + private static bool ThermoProdUpdatedAck; + public NcThermo numericalControl; public NcAdapter() => @@ -168,6 +177,80 @@ namespace Thermo.Active.NC return numericalControl.PLC_RWManageWatchdog(); } + public CmsError ManageStatusCommand() + { + CmsError cmsError = NO_ERROR; + // recupero i dati + List statusCmd = new List(); + cmsError = numericalControl.PLC_RManageStatusCommand(ref statusCmd); + if (cmsError.IsError()) + return cmsError; + + // verifico richieste di processing... + ThermoReqConfWarmerStr = checkBitOnWord(statusCmd[0], 7); + ThermoReqConfRecipeStr = checkBitOnWord(statusCmd[0], 8); + ThermoProdUpdatedStr = checkBitOnWord(statusCmd[0], 3); + + ThermoReqConfWarmerAck = checkBitOnWord(statusCmd[1], 7); + ThermoReqConfRecipeAck = checkBitOnWord(statusCmd[1], 8); + ThermoProdUpdatedAck = checkBitOnWord(statusCmd[1], 3); + + // restituisco errore + return cmsError; + } + /// + /// CHeck bit on word + /// + /// + /// + /// + protected bool checkBitOnWord(ushort value, int numBit) + { + bool answ = false; + ushort pow = (ushort)(1 << numBit); + answ = (value & pow) == pow; + return answ; + } + public CmsError ManageConfRequest() + { + // controllo SE HO richieste di configurazione + if (ThermoProdUpdatedStr) + { + // se si in questo caso scrivo configurazione... + WriteRecipeWarmConfig(); + // gestisco strobe/ack in risposta... + + } + else + { + // se è zero e il mio ack fosse 1 --> resetto il mio! + + } + + return numericalControl.PLC_WManageConfRequest(); + } + public CmsError ManageProdUpdate() + { + // controllo SE HO segnalazioni produzione + if (ThermoProdUpdatedStr) + { + // se si in questo caso leggo il record produzione... + + /// e quindi lo passo all'NC + + // do il bit di ack + } + else + { + // se è zero e il mio ack fosse 1 --> resetto il mio! + + } + + return numericalControl.PLC_WManageProdUpdate(); + } + + + public CmsError GetNcGenericData(out DTONcGenericDataModel genericData) { genericData = new DTONcGenericDataModel(MachineConfig.Model); diff --git a/Thermo.Active/Properties/AssemblyInfo.cs b/Thermo.Active/Properties/AssemblyInfo.cs index 9425cccd..32016308 100644 --- a/Thermo.Active/Properties/AssemblyInfo.cs +++ b/Thermo.Active/Properties/AssemblyInfo.cs @@ -31,4 +31,4 @@ using System.Runtime.InteropServices; // // You can specify all the values or you can default the Revision and Build Numbers // by using the '*' as shown below: -[assembly: AssemblyVersion("0.6.2")] +[assembly: AssemblyVersion("0.6.3")] From 50d0c4a94898fd853498f013f1c352a6dd3e0c1c Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Fri, 12 Jun 2020 11:39:26 +0200 Subject: [PATCH 2/6] Added flux for recipe/risk setup conf on request --- Thermo.Active.Core/ThreadsHandler.cs | 2 + Thermo.Active.NC/NcAdapter.cs | 162 ++++++++++++++++++++------- 2 files changed, 123 insertions(+), 41 deletions(-) diff --git a/Thermo.Active.Core/ThreadsHandler.cs b/Thermo.Active.Core/ThreadsHandler.cs index 50186c37..8f9c137a 100644 --- a/Thermo.Active.Core/ThreadsHandler.cs +++ b/Thermo.Active.Core/ThreadsHandler.cs @@ -12,6 +12,8 @@ namespace Thermo.Active.Core { ThreadsFunctions.ManageWatchdog, ThreadsFunctions.ManageStatusCommand, + ThreadsFunctions.ManageConfRequest, + ThreadsFunctions.ManageProdUpdate, ThreadsFunctions.ReadAlarms, ThreadsFunctions.ReadPowerOnData, ThreadsFunctions.StatThread, diff --git a/Thermo.Active.NC/NcAdapter.cs b/Thermo.Active.NC/NcAdapter.cs index 30ab937e..903aab34 100644 --- a/Thermo.Active.NC/NcAdapter.cs +++ b/Thermo.Active.NC/NcAdapter.cs @@ -29,14 +29,6 @@ namespace Thermo.Active.NC public class NcAdapter : IDisposable { - // variabili delle richieste da PLC - private static bool ThermoReqConfWarmerStr; - private static bool ThermoReqConfWarmerAck; - private static bool ThermoReqConfRecipeStr; - private static bool ThermoReqConfRecipeAck; - private static bool ThermoProdUpdatedStr; - private static bool ThermoProdUpdatedAck; - public NcThermo numericalControl; public NcAdapter() => @@ -75,6 +67,90 @@ namespace Thermo.Active.NC return null; } + #region StatusCommand words + + + // variabili delle richieste da PLC: tutte nella status command + private static List statusCmd = new List(); + /// + /// Check bit on word + /// + /// + /// + /// + protected static bool checkBitOnWord(ushort value, int numBit) + { + bool answ = false; + try + { + ushort pow = (ushort)(1 << numBit); + answ = (value & pow) == pow; + } + catch + { } + return answ; + } + private static bool ThermoReqConfWarmerStr + { + get + { + bool answ = false; + if (statusCmd.Count > 0) + { + answ = checkBitOnWord(statusCmd[0], 7); + } + return answ; + } + } + //private static bool ThermoReqConfWarmerAck + //{ + // get + // { + // return checkBitOnWord(statusCmd[1], 7); + // } + //} + private static bool ThermoReqConfRecipeStr + { + get + { + bool answ = false; + if (statusCmd.Count > 0) + { + answ = checkBitOnWord(statusCmd[0], 8); + } + return answ; + } + } + //private static bool ThermoReqConfRecipeAck + //{ + // get + // { + // return checkBitOnWord(statusCmd[1], 8); + // } + //} + private static bool ThermoProdUpdatedStr + { + get + { + bool answ = false; + if (statusCmd.Count > 0) + { + answ = checkBitOnWord(statusCmd[0], 3); + } + return answ; + } + } + //private static bool ThermoProdUpdatedAck + //{ + // get + // { + // return checkBitOnWord(statusCmd[1], 3); + // } + //} + + #endregion + + #region Read Data #region Axes @@ -181,64 +257,68 @@ namespace Thermo.Active.NC { CmsError cmsError = NO_ERROR; // recupero i dati - List statusCmd = new List(); - cmsError = numericalControl.PLC_RManageStatusCommand(ref statusCmd); + //statusCmd = new List(); + cmsError = numericalControl.PLC_RStatusCommand(ref statusCmd); if (cmsError.IsError()) return cmsError; - // verifico richieste di processing... - ThermoReqConfWarmerStr = checkBitOnWord(statusCmd[0], 7); - ThermoReqConfRecipeStr = checkBitOnWord(statusCmd[0], 8); - ThermoProdUpdatedStr = checkBitOnWord(statusCmd[0], 3); - - ThermoReqConfWarmerAck = checkBitOnWord(statusCmd[1], 7); - ThermoReqConfRecipeAck = checkBitOnWord(statusCmd[1], 8); - ThermoProdUpdatedAck = checkBitOnWord(statusCmd[1], 3); - // restituisco errore return cmsError; } - /// - /// CHeck bit on word - /// - /// - /// - /// - protected bool checkBitOnWord(ushort value, int numBit) - { - bool answ = false; - ushort pow = (ushort)(1 << numBit); - answ = (value & pow) == pow; - return answ; - } public CmsError ManageConfRequest() { + CmsError cmsError = NO_ERROR; // controllo SE HO richieste di configurazione - if (ThermoProdUpdatedStr) + if (ThermoReqConfWarmerStr) { // se si in questo caso scrivo configurazione... WriteRecipeWarmConfig(); - // gestisco strobe/ack in risposta... - + // Ack ! + cmsError = numericalControl.PLC_WAckConfRiskRequest(); } - else + else if (ThermoReqConfRecipeStr) { - // se è zero e il mio ack fosse 1 --> resetto il mio! - + // copy data to PLC + cmsError = ReadFullRecipe(out Dictionary prevRecipe); + if (cmsError.IsError()) + return cmsError; + // save parameters to PLC!!! + Dictionary updtRecipe = new Dictionary(); + foreach (var item in RecipeLiveData.RecipeParameters) + { + if (prevRecipe.ContainsKey(item.Key)) + { + // aggiorno il valore HMI nel parametro + var currParam = prevRecipe[item.Key]; + currParam.SetpointHMI = item.Value; + // salvo (1 parametro, potrei fare N...) + updtRecipe.Add(item.Key, currParam); + } + else + { + return NOT_FOUND_ERROR; + } + } + // se si in questo caso scrivo configurazione attuale... + WriteRecipeParams(updtRecipe); + // Ack ! + cmsError = numericalControl.PLC_WAckConfRecipeRequest(); } - return numericalControl.PLC_WManageConfRequest(); + return cmsError; } public CmsError ManageProdUpdate() { + CmsError cmsError = NO_ERROR; // controllo SE HO segnalazioni produzione if (ThermoProdUpdatedStr) { // se si in questo caso leggo il record produzione... - /// e quindi lo passo all'NC + /// e quindi lo gestisco (salvataggio su DB) // do il bit di ack + cmsError = numericalControl.PLC_WAckProdUpdate(); } else { @@ -246,7 +326,7 @@ namespace Thermo.Active.NC } - return numericalControl.PLC_WManageProdUpdate(); + return cmsError; } From 82a25ae0700f8654950bd95b8f58f2c580a61e1f Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Fri, 12 Jun 2020 15:07:22 +0200 Subject: [PATCH 3/6] completed test for ACK to PLC --- Thermo.Active.Core/ThreadsFunctions.cs | 2 +- Thermo.Active.NC/NcAdapter.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Thermo.Active.Core/ThreadsFunctions.cs b/Thermo.Active.Core/ThreadsFunctions.cs index 9d8c00d6..1bbf73df 100644 --- a/Thermo.Active.Core/ThreadsFunctions.cs +++ b/Thermo.Active.Core/ThreadsFunctions.cs @@ -160,7 +160,7 @@ public static class ThreadsFunctions UpdateStat(MethodBase.GetCurrentMethod().Name, sw.ElapsedMilliseconds); // Wait - Thread.Sleep(CalcSleepTime(1000, (int)sw.ElapsedMilliseconds)); + Thread.Sleep(CalcSleepTime(2000, (int)sw.ElapsedMilliseconds)); } } catch (ThreadAbortException ex) diff --git a/Thermo.Active.NC/NcAdapter.cs b/Thermo.Active.NC/NcAdapter.cs index 903aab34..262aaeff 100644 --- a/Thermo.Active.NC/NcAdapter.cs +++ b/Thermo.Active.NC/NcAdapter.cs @@ -276,7 +276,7 @@ namespace Thermo.Active.NC // Ack ! cmsError = numericalControl.PLC_WAckConfRiskRequest(); } - else if (ThermoReqConfRecipeStr) + if (ThermoReqConfRecipeStr) { // copy data to PLC cmsError = ReadFullRecipe(out Dictionary prevRecipe); From 169c07fc1ac8b4af9cdc6124d4ac30390e438f86 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Fri, 12 Jun 2020 17:00:15 +0200 Subject: [PATCH 4/6] new method for material dimension % calc --- Thermo.Active.NC/NcAdapter.cs | 40 +++++++++++++++++++ .../Controllers/WebApi/RecipeController.cs | 13 ++++-- .../Controllers/WebApi/WarmersController.cs | 18 +++++++++ 3 files changed, 67 insertions(+), 4 deletions(-) diff --git a/Thermo.Active.NC/NcAdapter.cs b/Thermo.Active.NC/NcAdapter.cs index 262aaeff..3692288b 100644 --- a/Thermo.Active.NC/NcAdapter.cs +++ b/Thermo.Active.NC/NcAdapter.cs @@ -2120,6 +2120,46 @@ namespace Thermo.Active.NC // restituisco cod errore se trovato return cmsError; } + /// + /// Get area for material from parameters list + /// + /// dictionary X/Y and double value + /// + public CmsError GetWarmMaterialArea(out Dictionary currAreaPerc) + { + CmsError cmsError = NO_ERROR; + currAreaPerc = new Dictionary(); + DTORecipeParam currParam = new DTORecipeParam(); + var currRecipe = new Dictionary(); + + // read recipe + cmsError = ReadRecipeData(false, true, out currRecipe); + if (cmsError.IsError()) + return cmsError; + + // use 2 fixed data for calculus: general_sizes_sheet_dim_x / general_sizes_sheet_dim_y + currAreaPerc.Add("X", getDimRatio(currRecipe["general_sizes_sheet_dim_x"])); + currAreaPerc.Add("Y", getDimRatio(currRecipe["general_sizes_sheet_dim_y"])); + + // restituisco cod errore se trovato + return cmsError; + } + + protected double getDimRatio(DTORecipeParam singlePar) + { + double ratio = 1; + if (singlePar!=null) + { + try + { + if (singlePar.Range.Max > 0) + ratio = singlePar.SetpointPLC / singlePar.Range.Max; + } + catch + { } + } + return ratio; + } /// /// Write all warmers load for recipe diff --git a/Thermo.Active/Controllers/WebApi/RecipeController.cs b/Thermo.Active/Controllers/WebApi/RecipeController.cs index bed83865..62338b86 100644 --- a/Thermo.Active/Controllers/WebApi/RecipeController.cs +++ b/Thermo.Active/Controllers/WebApi/RecipeController.cs @@ -344,10 +344,15 @@ namespace Thermo.Active.Controllers.WebApi /// private static void saveCurrentRecipeParams(Dictionary currParams) { - // ora salvo ANCHE i dati live... - RecipeLiveData.RecipeParameters = currParams; - // e salvo su disco - ServerConfigController.SaveRecipeCurrent(); + try + { + // ora salvo ANCHE i dati live... + RecipeLiveData.RecipeParameters = currParams; + // e salvo su disco + ServerConfigController.SaveRecipeCurrent(); + } + catch + { } } protected static CmsError writeCurrentRecipeToPlc() diff --git a/Thermo.Active/Controllers/WebApi/WarmersController.cs b/Thermo.Active/Controllers/WebApi/WarmersController.cs index 4e989bfc..8294ed1e 100644 --- a/Thermo.Active/Controllers/WebApi/WarmersController.cs +++ b/Thermo.Active/Controllers/WebApi/WarmersController.cs @@ -55,6 +55,24 @@ namespace Thermo.Active.Controllers.WebApi } } + [Route("area"), HttpGet] + public IHttpActionResult GetCurrentAreaPerc() + { + using (NcAdapter ncAdapter = new NcAdapter()) + { + // Try connection + CmsError libraryError = ncAdapter.Connect(); + if (libraryError.errorCode != 0) + return NotFound(); + + // recupera aree % X / Y + CmsError cmsError = ncAdapter.GetWarmMaterialArea(out Dictionary currAreaPerc); + if (cmsError.IsError()) + return BadRequest(cmsError.localizationKey); + + return Ok(currAreaPerc); + } + } [Route("update"), HttpPut] public IHttpActionResult WriteSetpoints(Dictionary channelsLoad) From 4fa253fd3bc2d6387d69da54f296105f2d68559b Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Fri, 12 Jun 2020 17:17:05 +0200 Subject: [PATCH 5/6] fixn recipe editing for action required too early --- .../Controllers/WebApi/RecipeController.cs | 184 ++++++++++-------- 1 file changed, 104 insertions(+), 80 deletions(-) diff --git a/Thermo.Active/Controllers/WebApi/RecipeController.cs b/Thermo.Active/Controllers/WebApi/RecipeController.cs index 62338b86..eca92022 100644 --- a/Thermo.Active/Controllers/WebApi/RecipeController.cs +++ b/Thermo.Active/Controllers/WebApi/RecipeController.cs @@ -60,41 +60,49 @@ namespace Thermo.Active.Controllers.WebApi { if (parametersList != null) { - using (NcAdapter ncAdapter = new NcAdapter()) + if (RecipeLiveData != null) { - // Try connection - CmsError libraryError = ncAdapter.Connect(); - if (libraryError.errorCode != 0) - return NotFound(); - - // read recipe! - CmsError cmsError = ncAdapter.ReadFullRecipe(out Dictionary prevRecipe); - if (cmsError.IsError()) - return BadRequest(cmsError.localizationKey); - - Dictionary updtRecipe = new Dictionary(); - - foreach (var item in parametersList) + using (NcAdapter ncAdapter = new NcAdapter()) { - if (prevRecipe.ContainsKey(item.Key)) - { - // aggiorno il valore HMI nel parametro - var currParam = prevRecipe[item.Key]; - currParam.SetpointHMI = item.Value; - // salvo (1 parametro, potrei fare N...) - updtRecipe.Add(item.Key, currParam); - } - else - { + // Try connection + CmsError libraryError = ncAdapter.Connect(); + if (libraryError.errorCode != 0) return NotFound(); + + // read recipe! + CmsError cmsError = ncAdapter.ReadFullRecipe(out Dictionary prevRecipe); + if (cmsError.IsError()) + return BadRequest(cmsError.localizationKey); + + Dictionary updtRecipe = new Dictionary(); + + foreach (var item in parametersList) + { + if (prevRecipe.ContainsKey(item.Key)) + { + // aggiorno il valore HMI nel parametro + var currParam = prevRecipe[item.Key]; + currParam.SetpointHMI = item.Value; + // salvo (1 parametro, potrei fare N...) + updtRecipe.Add(item.Key, currParam); + } + else + { + return NotFound(); + } } + + // scrivo sul PLC + ncAdapter.WriteRecipeParams(updtRecipe); + + // ritorno solo fatto! + return Ok(); } - - // scrivo sul PLC - ncAdapter.WriteRecipeParams(updtRecipe); - - // ritorno solo fatto! - return Ok(); + } + else + { + // non pronto! + return InternalServerError(); } } else @@ -110,34 +118,42 @@ namespace Thermo.Active.Controllers.WebApi [Route("confirm"), HttpPut] public IHttpActionResult ConfirmEdit() { - using (NcAdapter ncAdapter = new NcAdapter()) + if (RecipeLiveData != null) { - // Try connection - CmsError libraryError = ncAdapter.Connect(); - if (libraryError.errorCode != 0) - return NotFound(); - - // scrivo sul PLC il comando conferma! - CmsError cmsError = ncAdapter.ConfirmRecipeData(true); - if (cmsError.IsError()) - return BadRequest(cmsError.localizationKey); - - // recupero i dati LIVE dei parametri HMI della ricetta... - cmsError = ncAdapter.ReadFullRecipe(out Dictionary currRecipe); - if (cmsError.IsError()) - return BadRequest(cmsError.localizationKey); - - // rileggo la ricetta - var currParams = new Dictionary(); - foreach (var item in currRecipe) + using (NcAdapter ncAdapter = new NcAdapter()) { - currParams.Add(item.Key, item.Value.SetpointHMI); + // Try connection + CmsError libraryError = ncAdapter.Connect(); + if (libraryError.errorCode != 0) + return NotFound(); + + // scrivo sul PLC il comando conferma! + CmsError cmsError = ncAdapter.ConfirmRecipeData(true); + if (cmsError.IsError()) + return BadRequest(cmsError.localizationKey); + + // recupero i dati LIVE dei parametri HMI della ricetta... + cmsError = ncAdapter.ReadFullRecipe(out Dictionary currRecipe); + if (cmsError.IsError()) + return BadRequest(cmsError.localizationKey); + + // rileggo la ricetta + var currParams = new Dictionary(); + foreach (var item in currRecipe) + { + currParams.Add(item.Key, item.Value.SetpointHMI); + } + + saveCurrentRecipeParams(currParams); + + // ritorno solo fatto! + return Ok(); } - - saveCurrentRecipeParams(currParams); - - // ritorno solo fatto! - return Ok(); + } + else + { + // non pronto! + return InternalServerError(); } } @@ -148,34 +164,42 @@ namespace Thermo.Active.Controllers.WebApi [Route("cancel"), HttpPut] public IHttpActionResult CancelEdit() { - using (NcAdapter ncAdapter = new NcAdapter()) + if (RecipeLiveData != null) { - // Try connection - CmsError libraryError = ncAdapter.Connect(); - if (libraryError.errorCode != 0) - return NotFound(); - - // scrivo sul PLC il comando annula! - CmsError cmsError = ncAdapter.ConfirmRecipeData(false); - if (cmsError.IsError()) - return BadRequest(cmsError.localizationKey); - - // recupero i dati LIVE dei parametri HMI della ricetta... - cmsError = ncAdapter.ReadFullRecipe(out Dictionary currRecipe); - if (cmsError.IsError()) - return BadRequest(cmsError.localizationKey); - - var currParams = new Dictionary(); - foreach (var item in currRecipe) + using (NcAdapter ncAdapter = new NcAdapter()) { - currParams.Add(item.Key, item.Value.SetpointPLC); + // Try connection + CmsError libraryError = ncAdapter.Connect(); + if (libraryError.errorCode != 0) + return NotFound(); + + // scrivo sul PLC il comando annula! + CmsError cmsError = ncAdapter.ConfirmRecipeData(false); + if (cmsError.IsError()) + return BadRequest(cmsError.localizationKey); + + // recupero i dati LIVE dei parametri HMI della ricetta... + cmsError = ncAdapter.ReadFullRecipe(out Dictionary currRecipe); + if (cmsError.IsError()) + return BadRequest(cmsError.localizationKey); + + var currParams = new Dictionary(); + foreach (var item in currRecipe) + { + currParams.Add(item.Key, item.Value.SetpointPLC); + } + + // ora salvo ANCHE i dati live... + saveCurrentRecipeParams(currParams); + + // ritorno solo fatto! + return Ok(); } - - // ora salvo ANCHE i dati live... - saveCurrentRecipeParams(currParams); - - // ritorno solo fatto! - return Ok(); + } + else + { + // non pronto! + return InternalServerError(); } } From 6e5bf0888fd9e11f0e07e35d4525e8b9ddfeda78 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Fri, 12 Jun 2020 17:17:33 +0200 Subject: [PATCH 6/6] change LiveData init --- Thermo.Active.Config/ServerConfig.cs | 2 +- Thermo.Active.Config/ServerConfigController.cs | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Thermo.Active.Config/ServerConfig.cs b/Thermo.Active.Config/ServerConfig.cs index 732926fd..9f479ce2 100644 --- a/Thermo.Active.Config/ServerConfig.cs +++ b/Thermo.Active.Config/ServerConfig.cs @@ -62,7 +62,7 @@ namespace Thermo.Active.Config public static List RiskChannelConfig; public static List RiskBoardConfig; - public static LiveData RecipeLiveData; + public static LiveData RecipeLiveData = new LiveData(); } } \ No newline at end of file diff --git a/Thermo.Active.Config/ServerConfigController.cs b/Thermo.Active.Config/ServerConfigController.cs index f3172c2b..d106b195 100644 --- a/Thermo.Active.Config/ServerConfigController.cs +++ b/Thermo.Active.Config/ServerConfigController.cs @@ -856,6 +856,8 @@ namespace Thermo.Active.Config } catch { } + // write template to current data... + File.WriteAllText(LIVE_RECIPE_PATH, rawData); answ = true; } // rendo se fatto