diff --git a/Thermo.Active.Core/ThreadsFunctions.cs b/Thermo.Active.Core/ThreadsFunctions.cs index 0612efcf..c9f6a249 100644 --- a/Thermo.Active.Core/ThreadsFunctions.cs +++ b/Thermo.Active.Core/ThreadsFunctions.cs @@ -1479,39 +1479,46 @@ public static class ThreadsFunctions // Check if client is connected if (ncAdapter.numericalControl.NC_IsConnected()) { - // Get new data from PLC - libraryError = ncAdapter.ReadRecipeData(onlyRt, false, out Dictionary currRecipe); - if (libraryError.IsError()) - ManageLibraryError(libraryError); - - MessageServices.Current.Publish(SEND_THERMO_RECIPE_FULL, null, currRecipe); - - // ora gestisco la overview! - libraryError = ncAdapter.GetRecipeOverview(out Dictionary currOverview); - if (libraryError.IsError()) - ManageLibraryError(libraryError); - - MessageServices.Current.Publish(SEND_THERMO_RECIPE_OVERWIEW, null, currOverview); - - // ora gestisco la lettura della overview di "modificata - DTORecipeStatus message = new DTORecipeStatus() + // controllo su redis che NON sia bloccata lettura ricetta.. + if (!RedisController.getRecipeReadSem) { - recipeName = NcAdapter.RecipeLiveData.RecipeName, - hasChanged = NcAdapter.RecipeLiveData.hasChanged - }; + // Get new data from PLC + libraryError = ncAdapter.ReadRecipeData(onlyRt, false, out Dictionary currRecipe); + if (libraryError.IsError()) + ManageLibraryError(libraryError); - MessageServices.Current.Publish(SEND_THERMO_RECIPE_CHANGED, null, message); + MessageServices.Current.Publish(SEND_THERMO_RECIPE_FULL, null, currRecipe); - // verifico se dal PLC è segnalato che i setpointHMI sono invalidati, nel qual caso INVIO - bool setpointHmiInvalidated = false; - libraryError = ncAdapter.checkSetpointInvalidated(out setpointHmiInvalidated); - if (setpointHmiInvalidated) - { - // ora gestisco l'ack della richiesta - libraryError = ncAdapter.doAckSetpointInvalidated(); + // ora gestisco la overview! + libraryError = ncAdapter.GetRecipeOverview(out Dictionary currOverview); + if (libraryError.IsError()) + ManageLibraryError(libraryError); + + MessageServices.Current.Publish(SEND_THERMO_RECIPE_OVERWIEW, null, currOverview); + + // ora gestisco la lettura della overview di "modificata + DTORecipeStatus message = new DTORecipeStatus() + { + recipeName = NcAdapter.RecipeLiveData.RecipeName, + hasChanged = NcAdapter.RecipeLiveData.hasChanged + }; + + MessageServices.Current.Publish(SEND_THERMO_RECIPE_CHANGED, null, message); + + // verifico se dal PLC è segnalato che i setpointHMI sono invalidati, nel qual caso INVIO + bool setpointHmiInvalidated = false; + libraryError = ncAdapter.checkSetpointInvalidated(out setpointHmiInvalidated); + if (setpointHmiInvalidated) + { + // ora gestisco l'ack della richiesta + libraryError = ncAdapter.doAckSetpointInvalidated(); + } + // pubblico booleana dei setpointHMI invalidati + MessageServices.Current.Publish(SEND_THERMO_RECIPE_SETPOINTHMI_CHANGED, null, setpointHmiInvalidated); + } + else + { } - // pubblico booleana dei setpointHMI invalidati - MessageServices.Current.Publish(SEND_THERMO_RECIPE_SETPOINTHMI_CHANGED, null, setpointHmiInvalidated); } else RestoreConnection(); @@ -1646,33 +1653,38 @@ public static class ThreadsFunctions bool useCache = false; while (true) { - sw.Restart(); - // Check if client is connected - if (ncAdapter.numericalControl.NC_IsConnected()) + // controllo su redis che NON sia bloccata lettura ricetta.. + if (!RedisController.getWarmersReadSem) { - if (cacheWarmers) + sw.Restart(); + + // Check if client is connected + if (ncAdapter.numericalControl.NC_IsConnected()) { - // every 10 reads all data... - useCache = (readCount != 0); - readCount++; - // ciclo resettato ogni 20 - readCount = readCount % 20; + if (cacheWarmers) + { + // every 10 reads all data... + useCache = (readCount != 0); + readCount++; + // ciclo resettato ogni 20 + readCount = readCount % 20; + } + // Get new data from PLC + libraryError = ncAdapter.ReadWarmers(useCache, out Dictionary currWarmers); + if (libraryError.IsError()) + ManageLibraryError(libraryError); + // pubblico + MessageServices.Current.Publish(SEND_THERMO_WARMERS_DATA, null, currWarmers); } - // Get new data from PLC - libraryError = ncAdapter.ReadWarmers(useCache, out Dictionary currWarmers); - if (libraryError.IsError()) - ManageLibraryError(libraryError); - // pubblico - MessageServices.Current.Publish(SEND_THERMO_WARMERS_DATA, null, currWarmers); + else + RestoreConnection(); + + sw.Stop(); + + // Update thread timer + UpdateStat(MethodBase.GetCurrentMethod().Name, sw.ElapsedMilliseconds); } - else - RestoreConnection(); - - sw.Stop(); - - // Update thread timer - UpdateStat(MethodBase.GetCurrentMethod().Name, sw.ElapsedMilliseconds); // Wait Thread.Sleep(CalcSleepTime(samplMsec("warmers"), (int)sw.ElapsedMilliseconds)); } diff --git a/Thermo.Active.NC/NcAdapter.cs b/Thermo.Active.NC/NcAdapter.cs index 1e99891f..2b4eee9c 100644 --- a/Thermo.Active.NC/NcAdapter.cs +++ b/Thermo.Active.NC/NcAdapter.cs @@ -3669,8 +3669,15 @@ namespace Thermo.Active.NC /// public CmsError WriteRecipeParams(Dictionary updtRecipe, int nMaxParamWrite, int delayParamWrite) { + + // registro in redis blocco x lettura ricetta... + RedisController.setRecipeReadSem(true); + CmsError libraryError = WriteRecipeParametersToPLC(updtRecipe, nMaxParamWrite, delayParamWrite); + // tolgo blocco x lettura ricetta... + RedisController.setRecipeReadSem(false); + return libraryError; } @@ -3681,8 +3688,15 @@ namespace Thermo.Active.NC /// public CmsError WriteRecipeWarmChSetpHMI(Dictionary updtSetpHmi) { + // registro in redis blocco x lettura warmers... + RedisController.setWarmersReadSem(true); + CmsError libraryError = numericalControl.PLC_WWarmerChSetpHmi(updtSetpHmi); + // tolgo blocco x lettura warmers... + RedisController.setWarmersReadSem(false); + + return libraryError; } @@ -3693,8 +3707,14 @@ namespace Thermo.Active.NC /// public CmsError WriteRecipeWarmChTCamEnab(Dictionary actualStates) { + // registro in redis blocco x lettura warmers... + RedisController.setWarmersReadSem(true); + CmsError libraryError = numericalControl.PLC_WWarmerChTCamEnab(actualStates); + // tolgo blocco x lettura warmers... + RedisController.setWarmersReadSem(false); + return libraryError; } @@ -3705,8 +3725,14 @@ namespace Thermo.Active.NC /// public CmsError WriteRecipeWarmChTCamTempAct(Dictionary actualTemp) { + // registro in redis blocco x lettura warmers... + RedisController.setWarmersReadSem(true); + CmsError libraryError = numericalControl.PLC_WWarmerChTCamTempAct(actualTemp); + // tolgo blocco x lettura warmers... + RedisController.setWarmersReadSem(false); + return libraryError; } @@ -3717,8 +3743,14 @@ namespace Thermo.Active.NC /// public CmsError WriteRecipeWarmChTCamTempSet(Dictionary referenceTemp) { + // registro in redis blocco x lettura warmers... + RedisController.setWarmersReadSem(true); + CmsError libraryError = numericalControl.PLC_WWarmerChTCamTempSet(referenceTemp); + // tolgo blocco x lettura warmers... + RedisController.setWarmersReadSem(false); + return libraryError; } @@ -3732,6 +3764,9 @@ namespace Thermo.Active.NC Dictionary newData = new Dictionary(); CmsError libraryError = NO_ERROR; + // registro in redis blocco x lettura warmers... + RedisController.setWarmersReadSem(true); + // scrivo l'abilitazione dei canali... foreach (var item in RiskBoardConfig) { @@ -3793,6 +3828,10 @@ namespace Thermo.Active.NC numericalControl.PLC_WWarmerChTCamEnab(resetTCamEnab); numericalControl.PLC_WWarmerChTCamTempAct(resetTCamTemp); numericalControl.PLC_WWarmerChTCamTempSet(resetTCamTemp); + + // tolgo blocco x lettura warmers... + RedisController.setWarmersReadSem(false); + // esce return libraryError; } diff --git a/Thermo.Active/Controllers/WebApi/RecipeController.cs b/Thermo.Active/Controllers/WebApi/RecipeController.cs index e9c8a2b7..54975505 100644 --- a/Thermo.Active/Controllers/WebApi/RecipeController.cs +++ b/Thermo.Active/Controllers/WebApi/RecipeController.cs @@ -701,6 +701,7 @@ namespace Thermo.Active.Controllers.WebApi } + // copy data to PLC checkError = ncAdapter.ReadFullRecipe(out Dictionary prevRecipe); if (checkError.IsError())