From 147b84ab19e0c1edfe290472548d9e7e627c2c79 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Wed, 23 Sep 2020 19:04:16 +0200 Subject: [PATCH] NC config per lettura assi (per ora 0 da core_library) --- Thermo.Active.Core/ThreadsFunctions.cs | 9 +- Thermo.Active.NC/NcAdapter.cs | 177 ++++++++++++------------- 2 files changed, 93 insertions(+), 93 deletions(-) diff --git a/Thermo.Active.Core/ThreadsFunctions.cs b/Thermo.Active.Core/ThreadsFunctions.cs index c03471c6..36f057fd 100644 --- a/Thermo.Active.Core/ThreadsFunctions.cs +++ b/Thermo.Active.Core/ThreadsFunctions.cs @@ -29,6 +29,7 @@ using static Thermo.Active.Utils.ExceptionManager; public static class ThreadsFunctions { + public static int axisRtCounter = 0; public static int recipeRtCounter = 0; public static int modulesRtCounter = 0; public static bool reconnectionIsRunning = false; @@ -498,12 +499,18 @@ public static class ThreadsFunctions while (true) { + // ogni n counter leggo anche dati NON RT + axisRtCounter--; + bool onlyRt = axisRtCounter > 0; + //check reset... + axisRtCounter = axisRtCounter < 0 ? 4 : axisRtCounter; + sw.Restart(); if (ncAdapter.numericalControl.NC_IsConnected()) { // Get Data from config and PLC - libraryError = ncAdapter.ReadAxisData(out Dictionary axisData); + libraryError = ncAdapter.ReadAxisData(onlyRt, out Dictionary axisData); if (libraryError.errorCode != 0) ManageLibraryError(libraryError); else diff --git a/Thermo.Active.NC/NcAdapter.cs b/Thermo.Active.NC/NcAdapter.cs index 1a1c62cd..c4470cfe 100644 --- a/Thermo.Active.NC/NcAdapter.cs +++ b/Thermo.Active.NC/NcAdapter.cs @@ -258,6 +258,14 @@ namespace Thermo.Active.NC #region cached data + /// + /// Last recipe data from PLC + /// + protected static Dictionary lastAxisData = new Dictionary(); + /// + /// Last recipe data from PLCINFO data from PLC + /// + protected static Dictionary lastAxisInfoReadData = new Dictionary(); /// /// Last recipe data from PLC /// @@ -277,111 +285,96 @@ namespace Thermo.Active.NC #region Axes -#if false - public CmsError GetAxesPositions(out List axes) - { - axes = new List(); - - // Get NC max process number - ushort maxProcNumber = 0; - CmsError libraryError = numericalControl.NC_RProcessesNum(ref maxProcNumber); - if (libraryError.errorCode != 0) - return libraryError; - - // For each process - for (ushort i = 1; i <= maxProcNumber; i++) - { - libraryError = GetAxesPositionsByProcess(i, out DTOAxesModel axis); - if (libraryError.errorCode != 0) - return libraryError; - - axes.Add(axis); - } - - return libraryError; - } - - public CmsError GetAxesPositionsBySelectedProcess(out DTOAxesModel axes) - { - axes = new DTOAxesModel(); - - // Get selectedProcess process number - ushort selectedProcess = 0; - CmsError libraryError = numericalControl.PROC_RSelectedProcess(ref selectedProcess); - if (libraryError.IsError()) - return libraryError; - - if (selectedProcess > 0) - libraryError = GetAxesPositionsByProcess(selectedProcess, out axes); - - return libraryError; - } - - public CmsError GetAxesPositionsByProcess(ushort processNum, out DTOAxesModel axes) - { - axes = new DTOAxesModel(); - - CmsError libraryError = numericalControl.AXES_RInterpPosition(processNum, ref axes.interpolated); - if (libraryError.errorCode != 0) - return libraryError; - - libraryError = numericalControl.AXES_RMachinePosition(processNum, ref axes.machine); - if (libraryError.errorCode != 0) - return libraryError; - - libraryError = numericalControl.AXES_RProgrPosition(processNum, ref axes.programmePos); - if (libraryError.errorCode != 0) - return libraryError; - - libraryError = numericalControl.AXES_RDistanceToGo(processNum, ref axes.toGo); - if (libraryError.errorCode != 0) - return libraryError; - - //numericalControl.AXES_RFollowingError(1, ref axes.followingErr); - - return libraryError; - } - public CmsError GetAxesPositions(out DTOThermoAxesMovModel axes) - { - CmsError libraryError = NO_ERROR; - axes = new DTOThermoAxesMovModel(); - - // leggo dal PLC in lobocco i dati... -#if fase - libraryError = numericalControl.AXES_RInterpPosition(processNum, ref axes.interpolated); - if (libraryError.errorCode != 0) - return libraryError; -#endif - - return libraryError; - } -#endif - /// /// Dati assi da CONF + letture PLC /// /// /// - public CmsError ReadAxisData(out Dictionary axisData) + public CmsError ReadAxisData(bool refreshOnlyRT, out Dictionary axisData) { CmsError libraryError = NO_ERROR; - - //axisData = new Dictionary(); - - //// parto da elenco config - //List axisConfig = AxesConfig.Select(x => new DTOAxisInfoModel() - //// trasformo in dictionary - - // conversione al volo a dictionary - axisData = AxesConfig.Select(x => new DTOAxisInfoModel() + // initi della config ricetta (x poter poi ciclare...) + var axisConfig = AxesConfig.Select(x => new DTOAxisInfoModel() { ID = x.Id, name = x.Name, type = x.Type.ToString() }).ToDictionary(x => x.ID, x => x); - // leggo da PLC e "completo" i mancanti + + // se ho valori in cache uso quelli, altrimenti init obj + if (lastAxisData != null && lastAxisData.Count > 0) + { + axisData = lastAxisData; + } + else + { + // conversione al volo a dictionary + axisData = AxesConfig.Select(x => new DTOAxisInfoModel() + { + ID = x.Id, + name = x.Name, + type = x.Type.ToString() + }).ToDictionary(x => x.ID, x => x); + } + + // solo x S7Net... + if (NcConfig.NcVendor == NC_VENDOR.S7NET) + { + Dictionary currAxisRtData = new Dictionary(); + Dictionary currAxisInfoData = new Dictionary(); + + if (lastAxisInfoReadData == null) + { + // init! + lastAxisInfoReadData = currAxisInfoData; + } + // leggo SICURAMENTE i dati RT + libraryError = numericalControl.PLC_RAxisRTList(ref currAxisRtData); + if (libraryError.IsError()) + return libraryError; + + // se NON solo RT leggo tutti! + if (!refreshOnlyRT) + { + libraryError = numericalControl.PLC_RAxisInfoList(ref currAxisInfoData); + if (libraryError.IsError()) + return libraryError; + + // salvo valori acquisiti + lastAxisInfoReadData = currAxisInfoData; + } + else + { + currAxisInfoData = lastAxisInfoReadData; + } + + // ora completo i mancanti + foreach (var item in axisConfig) + { + // aggiorno (se c'è) il dato RT + if (currAxisRtData.ContainsKey(item.Key)) + { + axisData[item.Key].position = currAxisRtData[item.Key].Position; + axisData[item.Key].speed = currAxisRtData[item.Key].Speed; + axisData[item.Key].load = currAxisRtData[item.Key].Load; + } + + // aggiorno (se c'è) il dato INFO + if (currAxisInfoData.ContainsKey(item.Key)) + { + axisData[item.Key].errorCode = currAxisInfoData[item.Key].ErrorCode; + axisData[item.Key].movPhase = currAxisInfoData[item.Key].MovPhase; + axisData[item.Key].statusCode = currAxisInfoData[item.Key].StatusWord; + } + } + lastAxisData = axisData; + } + else + { + lastAxisData = axisData; + } return libraryError; } @@ -1785,7 +1778,7 @@ namespace Thermo.Active.NC /// public CmsError ReadRecipeData(bool refreshOnlyRT, bool useLastRead, out Dictionary currentRecipe) { - // per sicurezza: SE NON HO una last recipe -_> leggo cmq tutto! + // per sicurezza: SE NON HO una last recipe --> leggo cmq tutto! if (lastRecipe == null || lastRecipe.Count == 0) { refreshOnlyRT = false;