From 79f28bc41505094f9e0f081ea068c45d96f0f2d7 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Sun, 20 Sep 2020 10:19:22 +0200 Subject: [PATCH 1/7] Update datamodel in OUT --- .../DTOModels/ThAxes/DTOAxesModel.cs | 214 ++++++++++++++++++ .../Thermo.Active.Model.csproj | 1 + 2 files changed, 215 insertions(+) create mode 100644 Thermo.Active.Model/DTOModels/ThAxes/DTOAxesModel.cs diff --git a/Thermo.Active.Model/DTOModels/ThAxes/DTOAxesModel.cs b/Thermo.Active.Model/DTOModels/ThAxes/DTOAxesModel.cs new file mode 100644 index 00000000..ef20e790 --- /dev/null +++ b/Thermo.Active.Model/DTOModels/ThAxes/DTOAxesModel.cs @@ -0,0 +1,214 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using static Thermo.Active.Model.Constants; + +namespace Thermo.Active.Model.DTOModels.ThAxes +{ +#if false + public class DTOThermoAxes + { + public int Id { get; set; } = 0; + public string Label { get; set; } = ""; + public TACT_MBLOCK_TYPE Type { get; set; } = TACT_MBLOCK_TYPE.ND; + public TACT_MBLOCK_SECTION Section { get; set; } = TACT_MBLOCK_SECTION.ND; + public int IdParam { get; set; } = 0; + public bool ShowDelay { get; set; } = false; + public int Priority { get; set; } = 0; + public int ScaleFactor { get; set; } = 1000; + public int NumDec { get; set; } = 1; + public double ActualDelay { get; set; } = 0; + public double ActualDuration { get; set; } = 0; + public double EstimatedDelay { get; set; } = 0; + public double EstimatedDuration { get; set; } = 0; + public List PrecedingId { get; set; } = new List(); + public bool Visible { get; set; } = false; + public bool Running { get; set; } = false; + public bool HasError { get; set; } = false; + public bool Terminated { get; set; } = false; + public string Category { get; set; } = ""; + public string SubCategory_1 { get; set; } = ""; + public string SubCategory_2 { get; set; } = ""; + + + public override bool Equals(object obj) + { + if (!(obj is DTOThermoAxes item)) + return false; + + if (Id != item.Id) + return false; + if (Label != item.Label) + return false; + if (Type != item.Type) + return false; + if (Section != item.Section) + return false; + if (IdParam != item.IdParam) + return false; + if (ShowDelay != item.ShowDelay) + return false; + if (Priority != item.Priority) + return false; + if (ScaleFactor != item.ScaleFactor) + return false; + if (NumDec != item.NumDec) + return false; + if (ActualDelay != item.ActualDelay) + return false; + if (ActualDuration != item.ActualDuration) + return false; + if (EstimatedDelay != item.EstimatedDelay) + return false; + if (EstimatedDuration != item.EstimatedDuration) + return false; + if (!Enumerable.SequenceEqual(PrecedingId, item.PrecedingId)) + return false; + if (Visible != item.Visible) + return false; + if (Running != item.Running) + return false; + if (HasError != item.HasError) + return false; + if (Terminated != item.Terminated) + return false; + if (Category != item.Category) + return false; + if (SubCategory_1 != item.SubCategory_1) + return false; + if (SubCategory_2 != item.SubCategory_2) + return false; + + return true; + } + + public override int GetHashCode() + { + return base.GetHashCode(); + } + } +#endif + + public class DTOThermoAxesModel + { + /// + /// Actual position + /// + public Dictionary actPosition; + /// + /// Actual Speed + /// + public Dictionary actSpeed; + /// + /// Carico attuale assi + /// + public Dictionary actLoad; + /// + /// Errori attuali su assi + /// + public Dictionary errorCode; + /// + /// Fase movimento attuale + /// + public Dictionary movPhase; + /// + /// Status Word attuale + /// + public Dictionary statusCode; + + public DTOThermoAxesModel() + { + actPosition = new Dictionary(); + actSpeed = new Dictionary(); + actLoad = new Dictionary(); + errorCode = new Dictionary(); + movPhase = new Dictionary(); + statusCode = new Dictionary(); + } + + public struct AxisModel + { + public string name; + public double value; + } + + public override bool Equals(object obj) + { + if (!(obj is DTOThermoAxesModel item)) + return false; + + if (!CheckDictDouble(actPosition, item.actPosition)) + return false; + if (!CheckDictDouble(actSpeed, item.actSpeed)) + return false; + if (!CheckDictDouble(actLoad, item.actLoad)) + return false; + if (!CheckDictInt(errorCode, item.errorCode)) + return false; + if (!CheckDictInt(movPhase, item.movPhase)) + return false; + if (!CheckDictInt(statusCode, item.statusCode)) + return false; + + return true; + } + + public override int GetHashCode() + { + return base.GetHashCode(); + } + + private bool CheckDictDouble(IDictionary x, IDictionary y) + { + // early-exit checks + if (y == null) + return x == null; + if (x == null) + return false; + + if (x.Count != y.Count) + return false; + + // Check keys are the same + foreach (string k in x.Keys) + if (!y.ContainsKey(k)) + return false; + + // Check values are different + foreach (string k in x.Keys) + { + double a = Math.Abs(y[k] - x[k]); + + if (Math.Round(a, 3) >= Constants.EPSILON) + return false; + } + + return true; + } + private bool CheckDictInt(IDictionary x, IDictionary y) + { + // early-exit checks + if (y == null) + return x == null; + if (x == null) + return false; + + if (x.Count != y.Count) + return false; + + // Check keys are the same + foreach (string k in x.Keys) + if (!y.ContainsKey(k)) + return false; + + // Check values are different + foreach (string k in x.Keys) + { + if (y[k] != x[k]) + return false; + } + + return true; + } + } +} diff --git a/Thermo.Active.Model/Thermo.Active.Model.csproj b/Thermo.Active.Model/Thermo.Active.Model.csproj index 344bb2ce..cd397d0a 100644 --- a/Thermo.Active.Model/Thermo.Active.Model.csproj +++ b/Thermo.Active.Model/Thermo.Active.Model.csproj @@ -108,6 +108,7 @@ + From e509c83b90269cd3d706c3756aef862c5badfe5c Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Sun, 20 Sep 2020 10:19:55 +0200 Subject: [PATCH 2/7] start new rel 88 --- Thermo.Active/Properties/AssemblyInfo.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Thermo.Active/Properties/AssemblyInfo.cs b/Thermo.Active/Properties/AssemblyInfo.cs index 521a4f22..38424c26 100644 --- a/Thermo.Active/Properties/AssemblyInfo.cs +++ b/Thermo.Active/Properties/AssemblyInfo.cs @@ -30,4 +30,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.15.87")] \ No newline at end of file +[assembly: AssemblyVersion("0.15.88")] \ No newline at end of file From e42a231989a2354d96c7f91d20e0158ba1d1a931 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Sun, 20 Sep 2020 11:53:46 +0200 Subject: [PATCH 3/7] Aggiunta xsd x conf assi + update conf assi --- Thermo.Active.Config/Config/axesConfig.xml | 56 +++++++++++-------- .../Config/axesConfigValidator.xsd | 31 ++++++++++ 2 files changed, 63 insertions(+), 24 deletions(-) create mode 100644 Thermo.Active.Config/Config/axesConfigValidator.xsd diff --git a/Thermo.Active.Config/Config/axesConfig.xml b/Thermo.Active.Config/Config/axesConfig.xml index 8105de47..812e8aa2 100644 --- a/Thermo.Active.Config/Config/axesConfig.xml +++ b/Thermo.Active.Config/Config/axesConfig.xml @@ -1,27 +1,35 @@ - X - Y - Z - B - C - V - - - - - - - - - - - SP - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Thermo.Active.Config/Config/axesConfigValidator.xsd b/Thermo.Active.Config/Config/axesConfigValidator.xsd new file mode 100644 index 00000000..67b59ad2 --- /dev/null +++ b/Thermo.Active.Config/Config/axesConfigValidator.xsd @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From 5da1afa0eb1782d7156d81c9ae06c5bf7376fb04 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Sun, 20 Sep 2020 11:54:23 +0200 Subject: [PATCH 4/7] Prosegue gestione dati assi (da conf con XML) --- Thermo.Active.Config/ServerConfig.cs | 1 + .../ServerConfigController.cs | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/Thermo.Active.Config/ServerConfig.cs b/Thermo.Active.Config/ServerConfig.cs index 6ead2f2e..3146aa0b 100644 --- a/Thermo.Active.Config/ServerConfig.cs +++ b/Thermo.Active.Config/ServerConfig.cs @@ -63,6 +63,7 @@ namespace Thermo.Active.Config public static List RiskResistConfig; public static List RiskChannelConfig; public static List RiskBoardConfig; + public static List AxesConfig; } diff --git a/Thermo.Active.Config/ServerConfigController.cs b/Thermo.Active.Config/ServerConfigController.cs index d16e497b..68b0ce0a 100644 --- a/Thermo.Active.Config/ServerConfigController.cs +++ b/Thermo.Active.Config/ServerConfigController.cs @@ -38,6 +38,7 @@ namespace Thermo.Active.Config ReadRecipeConfig(); ReadModBlockConfig(); ReadRiskConfig(); + ReadAxesConfig(); // ReadCMSConnectConfig(); ReadMacros(); ReadScadaFile(); @@ -867,6 +868,25 @@ namespace Thermo.Active.Config } } + /// + /// Axes config setup from file + /// + private static void ReadAxesConfig() + { + XDocument xmlConfigFile = GetXmlHandlerWithValidator(AXES_CONFIG_SCHEMA_PATH, AXES_CONFIG_PATH); + + // Read head config from XML file + AxesConfig = xmlConfigFile + .Root + .Elements() + .Select(x => new AxesConfigModel() + { + Id = Convert.ToInt16(x.Attribute("id").Value), + Name = x.Attribute("name").Value, + Type = GetTActAxes_Type(x.Attribute("type").Value) + }) + .ToList(); + } private static void ReadCMSConnectConfig() { String _tempUSR, _tempPSW; From 134981c2d7f5a94e4edf660335f0840712b8a06b Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Sun, 20 Sep 2020 11:54:38 +0200 Subject: [PATCH 5/7] Aggiunta metodi preliminari gestione dati ASSI --- .../Thermo.Active.Config.csproj | 4 + Thermo.Active.Core/ThreadsFunctions.cs | 55 ++++- Thermo.Active.Core/ThreadsHandler.cs | 5 +- .../ConfigModels/AxesConfigModel.cs | 13 ++ Thermo.Active.Model/Constants.cs | 13 +- .../DTOModels/ThAxes/DTOAxesInfoModel.cs | 76 +++++++ .../DTOModels/ThAxes/DTOAxesModel.cs | 214 ------------------ .../DTOModels/ThAxes/DTOAxesMovModel.cs | 86 +++++++ .../Thermo.Active.Model.csproj | 4 +- Thermo.Active.Utils/supportFunctions.cs | 15 ++ Thermo.Active/Listeners/ListenersHandler.cs | 8 +- .../Listeners/SignalR/SignalRListener.cs | 61 +++-- .../Listeners/SignalRStaticObjects.cs | 9 +- 13 files changed, 314 insertions(+), 249 deletions(-) create mode 100644 Thermo.Active.Model/ConfigModels/AxesConfigModel.cs create mode 100644 Thermo.Active.Model/DTOModels/ThAxes/DTOAxesInfoModel.cs delete mode 100644 Thermo.Active.Model/DTOModels/ThAxes/DTOAxesModel.cs create mode 100644 Thermo.Active.Model/DTOModels/ThAxes/DTOAxesMovModel.cs diff --git a/Thermo.Active.Config/Thermo.Active.Config.csproj b/Thermo.Active.Config/Thermo.Active.Config.csproj index 0ed9fc88..dd4d411a 100644 --- a/Thermo.Active.Config/Thermo.Active.Config.csproj +++ b/Thermo.Active.Config/Thermo.Active.Config.csproj @@ -207,6 +207,10 @@ Designer Always + + Designer + Always + Always diff --git a/Thermo.Active.Core/ThreadsFunctions.cs b/Thermo.Active.Core/ThreadsFunctions.cs index 0f39008b..5061f5d8 100644 --- a/Thermo.Active.Core/ThreadsFunctions.cs +++ b/Thermo.Active.Core/ThreadsFunctions.cs @@ -507,7 +507,7 @@ public static class ThreadsFunctions MessageServices.Current.Publish(SEND_AXIS_NAMES_DATA, null, axes); } else - RestoreConnection(); + RestoreConnection(); sw.Stop(); @@ -539,6 +539,7 @@ public static class ThreadsFunctions { sw.Restart(); +#if false if (ncAdapter.numericalControl.NC_IsConnected()) { // Get Data from NC @@ -547,10 +548,11 @@ public static class ThreadsFunctions ManageLibraryError(libraryError); else // Send through signalR - MessageServices.Current.Publish(SEND_AXES, null, axesPositions); + MessageServices.Current.Publish(SEND_AXIS_POS, null, axesPositions); } else - RestoreConnection(); + RestoreConnection(); +#endif sw.Stop(); @@ -558,7 +560,52 @@ public static class ThreadsFunctions UpdateStat(MethodBase.GetCurrentMethod().Name, sw.ElapsedMilliseconds); // Wait - Thread.Sleep(CalcSleepTime(100, (int)sw.ElapsedMilliseconds)); + Thread.Sleep(CalcSleepTime(200, (int)sw.ElapsedMilliseconds)); + } + } + catch (ThreadAbortException) + { + ncAdapter.Dispose(); + } + } + public static void ReadAxesInfoData() + { + NcAdapter ncAdapter = new NcAdapter(); + Stopwatch sw = new Stopwatch(); + + try + { + // Try connection + CmsError libraryError = ncAdapter.Connect(); + if (libraryError.errorCode != 0) + ManageLibraryError(libraryError); + + while (true) + { + sw.Restart(); + +#if false + if (ncAdapter.numericalControl.NC_IsConnected()) + { + // Get Data from NC + libraryError = ncAdapter.GetAxesPositionsBySelectedProcess(out DTOAxesModel axesPositions); + if (libraryError.errorCode != 0) + ManageLibraryError(libraryError); + else + // Send through signalR + MessageServices.Current.Publish(SEND_AXIS_INFO, null, axesPositions); + } + else + RestoreConnection(); +#endif + + sw.Stop(); + + //Update thread timer + UpdateStat(MethodBase.GetCurrentMethod().Name, sw.ElapsedMilliseconds); + + // Wait + Thread.Sleep(CalcSleepTime(500, (int)sw.ElapsedMilliseconds)); } } catch (ThreadAbortException) diff --git a/Thermo.Active.Core/ThreadsHandler.cs b/Thermo.Active.Core/ThreadsHandler.cs index 18c678b6..7d61e920 100644 --- a/Thermo.Active.Core/ThreadsHandler.cs +++ b/Thermo.Active.Core/ThreadsHandler.cs @@ -19,10 +19,8 @@ namespace Thermo.Active.Core ThreadsFunctions.ReadProcessesPPStatus, ThreadsFunctions.ReadEnabledFunctionality, ThreadsFunctions.ReadExpiredMaintenances, - //ThreadsFunctions.ReadAxesPositionsData, ThreadsFunctions.ReadUserSoftKeysData, //ThreadsFunctions.ReadHeadsData, - //ThreadsFunctions.ReadAxesNamesData, //ThreadsFunctions.ReadActiveProgramData, //ThreadsFunctions.ReadPartProgramQueueData, // ThreadsFunctions.ReadNcSoftKeysData, @@ -36,6 +34,9 @@ namespace Thermo.Active.Core ThreadsFunctions.ReadModulesData, ThreadsFunctions.ReadScadaData, ThreadsFunctions.ReadMComandsData, + ThreadsFunctions.ReadAxesNamesData, + ThreadsFunctions.ReadAxesPositionsData, + ThreadsFunctions.ReadAxesInfoData, ThreadsFunctions.ReadM154Data // levare? }; diff --git a/Thermo.Active.Model/ConfigModels/AxesConfigModel.cs b/Thermo.Active.Model/ConfigModels/AxesConfigModel.cs new file mode 100644 index 00000000..6e25805d --- /dev/null +++ b/Thermo.Active.Model/ConfigModels/AxesConfigModel.cs @@ -0,0 +1,13 @@ +using System.Collections.Generic; +using static Thermo.Active.Model.Constants; + +namespace Thermo.Active.Model.ConfigModels +{ + public class AxesConfigModel + { + public int Id; + public string Name { get; set; } + public bool IsSelectable { get; set; } = true; + public TACT_AXES_TYPE Type { get; set; } + } +} diff --git a/Thermo.Active.Model/Constants.cs b/Thermo.Active.Model/Constants.cs index e3644036..e5a8b156 100644 --- a/Thermo.Active.Model/Constants.cs +++ b/Thermo.Active.Model/Constants.cs @@ -102,6 +102,12 @@ namespace Thermo.Active.Model COOLING, EXTRACTION } + public enum TACT_AXES_TYPE + { + NA = 0, + LINEAR, + ROTATIONAL + } [JsonConverter(typeof(StringEnumConverter))] public enum TACT_PROD_CATEGORY @@ -272,6 +278,10 @@ namespace Thermo.Active.Model public const string MACROS_CONFIG_SCHEMA_PATH = RESOURCE_DIRECTORY + "macrosConfigValidator.xsd"; public const string MACROS_CONFIG_PATH = CONFIG_DIRECTORY + "macrosConfig.xml"; + + public const string AXES_CONFIG_SCHEMA_PATH = RESOURCE_DIRECTORY + @"axesConfigValidator.xsd"; + public const string AXES_CONFIG_PATH = CONFIG_DIRECTORY + "axesConfig.xml"; + public const string MAIN_PROGRAM_CONFIG_PATH = CONFIG_DIRECTORY + "customMainProgram.txt"; @@ -300,7 +310,6 @@ namespace Thermo.Active.Model public const string SEND_POWER_ON_DATA = "SEND_POWER_ON_DATA"; public const string SEND_GENERIC_DATA = "SEND_GENERIC_DATA"; - public const string SEND_AXES = "SEND_AXES"; public const string SEND_PROCESSES_DATA = "SEND_PROCESSES_STATUS"; public const string SEND_FUNCTIONALITY_DATA = "SEND_FUNCTION_DATA"; public const string SEND_EXPIRED_MAINTENANCES_DATA = "SEND_EXPIRED_MAINTENANCES_DATA"; @@ -308,6 +317,8 @@ namespace Thermo.Active.Model public const string SEND_NC_SOFTKEYS_DATA = "SEND_NC_SOFTKEYS_DATA"; public const string SEND_HEADS_DATA = "SEND_HEADS_DATA"; public const string SEND_AXIS_NAMES_DATA = "SEND_AXIS_NAMES_DATA"; + public const string SEND_AXIS_POS = "SEND_AXIS_POS"; + public const string SEND_AXIS_INFO = "SEND_AXIS_INFO"; public const string SEND_ACTIVE_PROGRAM_DATA = "SEND_ACTIVE_PROGRAM_DATA"; public const string SEND_QUEUE_DATA = "SEND_QUEUE_DATA"; public const string SEND_M155_DATA = "SEND_M155_DATA"; diff --git a/Thermo.Active.Model/DTOModels/ThAxes/DTOAxesInfoModel.cs b/Thermo.Active.Model/DTOModels/ThAxes/DTOAxesInfoModel.cs new file mode 100644 index 00000000..c89476a9 --- /dev/null +++ b/Thermo.Active.Model/DTOModels/ThAxes/DTOAxesInfoModel.cs @@ -0,0 +1,76 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using static Thermo.Active.Model.Constants; + +namespace Thermo.Active.Model.DTOModels.ThAxes +{ + public class DTOAxesInfoModel + { + /// + /// Errori attuali su assi + /// + public Dictionary errorCode; + /// + /// Fase movimento attuale + /// + public Dictionary movPhase; + /// + /// Status Word attuale + /// + public Dictionary statusCode; + + public DTOAxesInfoModel() + { + errorCode = new Dictionary(); + movPhase = new Dictionary(); + statusCode = new Dictionary(); + } + + public override bool Equals(object obj) + { + if (!(obj is DTOAxesInfoModel item)) + return false; + + if (!CheckDictInt(errorCode, item.errorCode)) + return false; + if (!CheckDictInt(movPhase, item.movPhase)) + return false; + if (!CheckDictInt(statusCode, item.statusCode)) + return false; + + return true; + } + + public override int GetHashCode() + { + return base.GetHashCode(); + } + + private bool CheckDictInt(IDictionary x, IDictionary y) + { + // early-exit checks + if (y == null) + return x == null; + if (x == null) + return false; + + if (x.Count != y.Count) + return false; + + // Check keys are the same + foreach (string k in x.Keys) + if (!y.ContainsKey(k)) + return false; + + // Check values are different + foreach (string k in x.Keys) + { + if (y[k] != x[k]) + return false; + } + + return true; + } + } +} diff --git a/Thermo.Active.Model/DTOModels/ThAxes/DTOAxesModel.cs b/Thermo.Active.Model/DTOModels/ThAxes/DTOAxesModel.cs deleted file mode 100644 index ef20e790..00000000 --- a/Thermo.Active.Model/DTOModels/ThAxes/DTOAxesModel.cs +++ /dev/null @@ -1,214 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using static Thermo.Active.Model.Constants; - -namespace Thermo.Active.Model.DTOModels.ThAxes -{ -#if false - public class DTOThermoAxes - { - public int Id { get; set; } = 0; - public string Label { get; set; } = ""; - public TACT_MBLOCK_TYPE Type { get; set; } = TACT_MBLOCK_TYPE.ND; - public TACT_MBLOCK_SECTION Section { get; set; } = TACT_MBLOCK_SECTION.ND; - public int IdParam { get; set; } = 0; - public bool ShowDelay { get; set; } = false; - public int Priority { get; set; } = 0; - public int ScaleFactor { get; set; } = 1000; - public int NumDec { get; set; } = 1; - public double ActualDelay { get; set; } = 0; - public double ActualDuration { get; set; } = 0; - public double EstimatedDelay { get; set; } = 0; - public double EstimatedDuration { get; set; } = 0; - public List PrecedingId { get; set; } = new List(); - public bool Visible { get; set; } = false; - public bool Running { get; set; } = false; - public bool HasError { get; set; } = false; - public bool Terminated { get; set; } = false; - public string Category { get; set; } = ""; - public string SubCategory_1 { get; set; } = ""; - public string SubCategory_2 { get; set; } = ""; - - - public override bool Equals(object obj) - { - if (!(obj is DTOThermoAxes item)) - return false; - - if (Id != item.Id) - return false; - if (Label != item.Label) - return false; - if (Type != item.Type) - return false; - if (Section != item.Section) - return false; - if (IdParam != item.IdParam) - return false; - if (ShowDelay != item.ShowDelay) - return false; - if (Priority != item.Priority) - return false; - if (ScaleFactor != item.ScaleFactor) - return false; - if (NumDec != item.NumDec) - return false; - if (ActualDelay != item.ActualDelay) - return false; - if (ActualDuration != item.ActualDuration) - return false; - if (EstimatedDelay != item.EstimatedDelay) - return false; - if (EstimatedDuration != item.EstimatedDuration) - return false; - if (!Enumerable.SequenceEqual(PrecedingId, item.PrecedingId)) - return false; - if (Visible != item.Visible) - return false; - if (Running != item.Running) - return false; - if (HasError != item.HasError) - return false; - if (Terminated != item.Terminated) - return false; - if (Category != item.Category) - return false; - if (SubCategory_1 != item.SubCategory_1) - return false; - if (SubCategory_2 != item.SubCategory_2) - return false; - - return true; - } - - public override int GetHashCode() - { - return base.GetHashCode(); - } - } -#endif - - public class DTOThermoAxesModel - { - /// - /// Actual position - /// - public Dictionary actPosition; - /// - /// Actual Speed - /// - public Dictionary actSpeed; - /// - /// Carico attuale assi - /// - public Dictionary actLoad; - /// - /// Errori attuali su assi - /// - public Dictionary errorCode; - /// - /// Fase movimento attuale - /// - public Dictionary movPhase; - /// - /// Status Word attuale - /// - public Dictionary statusCode; - - public DTOThermoAxesModel() - { - actPosition = new Dictionary(); - actSpeed = new Dictionary(); - actLoad = new Dictionary(); - errorCode = new Dictionary(); - movPhase = new Dictionary(); - statusCode = new Dictionary(); - } - - public struct AxisModel - { - public string name; - public double value; - } - - public override bool Equals(object obj) - { - if (!(obj is DTOThermoAxesModel item)) - return false; - - if (!CheckDictDouble(actPosition, item.actPosition)) - return false; - if (!CheckDictDouble(actSpeed, item.actSpeed)) - return false; - if (!CheckDictDouble(actLoad, item.actLoad)) - return false; - if (!CheckDictInt(errorCode, item.errorCode)) - return false; - if (!CheckDictInt(movPhase, item.movPhase)) - return false; - if (!CheckDictInt(statusCode, item.statusCode)) - return false; - - return true; - } - - public override int GetHashCode() - { - return base.GetHashCode(); - } - - private bool CheckDictDouble(IDictionary x, IDictionary y) - { - // early-exit checks - if (y == null) - return x == null; - if (x == null) - return false; - - if (x.Count != y.Count) - return false; - - // Check keys are the same - foreach (string k in x.Keys) - if (!y.ContainsKey(k)) - return false; - - // Check values are different - foreach (string k in x.Keys) - { - double a = Math.Abs(y[k] - x[k]); - - if (Math.Round(a, 3) >= Constants.EPSILON) - return false; - } - - return true; - } - private bool CheckDictInt(IDictionary x, IDictionary y) - { - // early-exit checks - if (y == null) - return x == null; - if (x == null) - return false; - - if (x.Count != y.Count) - return false; - - // Check keys are the same - foreach (string k in x.Keys) - if (!y.ContainsKey(k)) - return false; - - // Check values are different - foreach (string k in x.Keys) - { - if (y[k] != x[k]) - return false; - } - - return true; - } - } -} diff --git a/Thermo.Active.Model/DTOModels/ThAxes/DTOAxesMovModel.cs b/Thermo.Active.Model/DTOModels/ThAxes/DTOAxesMovModel.cs new file mode 100644 index 00000000..19de96f0 --- /dev/null +++ b/Thermo.Active.Model/DTOModels/ThAxes/DTOAxesMovModel.cs @@ -0,0 +1,86 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using static Thermo.Active.Model.Constants; + +namespace Thermo.Active.Model.DTOModels.ThAxes +{ + public class DTOThermoAxesMovModel + { + /// + /// Actual position + /// + public Dictionary actPosition; + /// + /// Actual Speed + /// + public Dictionary actSpeed; + /// + /// Carico attuale assi + /// + public Dictionary actLoad; + + public DTOThermoAxesMovModel() + { + actPosition = new Dictionary(); + actSpeed = new Dictionary(); + actLoad = new Dictionary(); + } + +#if false + public struct AxisModel + { + public string name; + public double value; + } +#endif + + public override bool Equals(object obj) + { + if (!(obj is DTOThermoAxesMovModel item)) + return false; + + if (!CheckDictDouble(actPosition, item.actPosition)) + return false; + if (!CheckDictDouble(actSpeed, item.actSpeed)) + return false; + if (!CheckDictDouble(actLoad, item.actLoad)) + return false; + + return true; + } + + public override int GetHashCode() + { + return base.GetHashCode(); + } + + private bool CheckDictDouble(IDictionary x, IDictionary y) + { + // early-exit checks + if (y == null) + return x == null; + if (x == null) + return false; + + if (x.Count != y.Count) + return false; + + // Check keys are the same + foreach (string k in x.Keys) + if (!y.ContainsKey(k)) + return false; + + // Check values are different + foreach (string k in x.Keys) + { + double a = Math.Abs(y[k] - x[k]); + + if (Math.Round(a, 3) >= Constants.EPSILON) + return false; + } + + return true; + } + } +} diff --git a/Thermo.Active.Model/Thermo.Active.Model.csproj b/Thermo.Active.Model/Thermo.Active.Model.csproj index cd397d0a..1de1e92c 100644 --- a/Thermo.Active.Model/Thermo.Active.Model.csproj +++ b/Thermo.Active.Model/Thermo.Active.Model.csproj @@ -64,6 +64,7 @@ + @@ -108,7 +109,8 @@ - + + diff --git a/Thermo.Active.Utils/supportFunctions.cs b/Thermo.Active.Utils/supportFunctions.cs index 5defccca..3cd93d2f 100644 --- a/Thermo.Active.Utils/supportFunctions.cs +++ b/Thermo.Active.Utils/supportFunctions.cs @@ -70,6 +70,21 @@ namespace Thermo.Active.Utils return answ; } /// + /// Conversion string --> TACT_AXIS_TYPE + /// + /// + /// + public static TACT_AXES_TYPE GetTActAxes_Type(string strValue) + { + TACT_AXES_TYPE answ = TACT_AXES_TYPE.NA; + try + { + answ = (TACT_AXES_TYPE)Enum.Parse(typeof(TACT_AXES_TYPE), strValue); + } + catch { } + return answ; + } + /// /// Conversion string --> TACT_MBLOCK_TYPE /// /// diff --git a/Thermo.Active/Listeners/ListenersHandler.cs b/Thermo.Active/Listeners/ListenersHandler.cs index 98e6b5ac..f15b66d3 100644 --- a/Thermo.Active/Listeners/ListenersHandler.cs +++ b/Thermo.Active/Listeners/ListenersHandler.cs @@ -64,9 +64,13 @@ namespace Thermo.Active.Listeners { SignalRListener.SendAxesNamesData(a); })); - infos.Add(MessageServices.Current.Subscribe(SEND_AXES, (a, b) => + infos.Add(MessageServices.Current.Subscribe(SEND_AXIS_POS, (a, b) => { - SignalRListener.SendAxesToClient(a); + SignalRListener.SendThermoAxesPosition(a); + })); + infos.Add(MessageServices.Current.Subscribe(SEND_AXIS_INFO, (a, b) => + { + SignalRListener.SendThermoAxesInfoData(a); })); infos.Add(MessageServices.Current.Subscribe(SEND_ACTIVE_PROGRAM_DATA, (a, b) => { diff --git a/Thermo.Active/Listeners/SignalR/SignalRListener.cs b/Thermo.Active/Listeners/SignalR/SignalRListener.cs index bc4f84f9..99708df3 100644 --- a/Thermo.Active/Listeners/SignalR/SignalRListener.cs +++ b/Thermo.Active/Listeners/SignalR/SignalRListener.cs @@ -9,6 +9,7 @@ using Thermo.Active.Controllers.SignalR; using Thermo.Active.Model.DTOModels; using Thermo.Active.Model.DTOModels.AlarmModels; using Thermo.Active.Model.DTOModels.Scada; +using Thermo.Active.Model.DTOModels.ThAxes; using Thermo.Active.Model.DTOModels.ThModules; using Thermo.Active.Model.DTOModels.ThProd; using Thermo.Active.Model.DTOModels.ThRecipe; @@ -34,16 +35,8 @@ namespace Thermo.Active.Listeners.SignalR } } - public static void SendAxesToClient(object newAxesData) - { - if (!LastAxesPositions.Equals(newAxesData)) - { - var context = GlobalHost.ConnectionManager.GetHubContext(); - LastAxesPositions = newAxesData as DTOAxesModel; - context.Clients.Group("ncData").axesPositions(newAxesData); - } - } + public static void SendPowerOnDataToClient(object powerOnData) { @@ -170,19 +163,6 @@ namespace Thermo.Active.Listeners.SignalR } } - public static void SendAxesNamesData(object axesNames) - { - var context = GlobalHost.ConnectionManager.GetHubContext(); - List newData = axesNames as List; - - // Check if collections are equals - if (newData.Count != LastAxesNamesData.Count || !LastAxesNamesData.All(newData.Contains)) - { - LastAxesNamesData = newData; - // Send data to clients - context.Clients.Group("ncData").axesNames(axesNames); - } - } public static void SendActiveProgramData(object programData) { @@ -481,6 +461,41 @@ namespace Thermo.Active.Listeners.SignalR } + public static void SendAxesNamesData(object axesNames) + { + var context = GlobalHost.ConnectionManager.GetHubContext(); + List newData = axesNames as List; + + // Check if collections are equals + if (newData.Count != LastAxesNamesData.Count || !LastAxesNamesData.All(newData.Contains)) + { + LastAxesNamesData = newData; + // Send data to clients + context.Clients.Group("ncData").axesNames(axesNames); + } + } + public static void SendThermoAxesPosition(object newAxesData) + { + DTOThermoAxesMovModel currAxes = newAxesData as DTOThermoAxesMovModel; + if (!LastAxesPositions.Equals(currAxes)) + { + LastAxesPositions = currAxes; + + var context = GlobalHost.ConnectionManager.GetHubContext(); + context.Clients.Group("ncData").axesPositions(currAxes); + } + } + public static void SendThermoAxesInfoData(object axesInfoData) + { + DTOAxesInfoModel currInfoAxes = axesInfoData as DTOAxesInfoModel; + if (!LastAxesInfoData.Equals(currInfoAxes)) + { + LastAxesInfoData = currInfoAxes; + + var context = GlobalHost.ConnectionManager.GetHubContext(); + context.Clients.Group("ncData").axesInfo(currInfoAxes); + } + } public static void SetGatewayRebootStatus(object status) { @@ -535,6 +550,8 @@ namespace Thermo.Active.Listeners.SignalR group.axesNames(LastAxesNamesData); // Send positions group.axesPositions(LastAxesPositions); + // Send info + group.axesInfo(LastAxesInfoData); // Send active program data group.activeProgramData(LastProgramData); // Send magazine is active data diff --git a/Thermo.Active/Listeners/SignalRStaticObjects.cs b/Thermo.Active/Listeners/SignalRStaticObjects.cs index 3a6eeeaa..23fe865c 100644 --- a/Thermo.Active/Listeners/SignalRStaticObjects.cs +++ b/Thermo.Active/Listeners/SignalRStaticObjects.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using Thermo.Active.Model.DTOModels; using Thermo.Active.Model.DTOModels.AlarmModels; using Thermo.Active.Model.DTOModels.Scada; +using Thermo.Active.Model.DTOModels.ThAxes; using Thermo.Active.Model.DTOModels.ThModules; using Thermo.Active.Model.DTOModels.ThProd; using Thermo.Active.Model.DTOModels.ThRecipe; @@ -22,8 +23,6 @@ namespace Thermo.Active.Listeners public static List LastUserSoftKeysData = new List(); public static List LastNcSoftKeysData = new List(); public static List LastHeadsData = new List(); - public static DTOAxesModel LastAxesPositions = new DTOAxesModel(); - public static List LastAxesNamesData = new List(); public static DTOActiveProgramDataModel LastProgramData = new DTOActiveProgramDataModel(); public static Dictionary LastNcMagazineIsActive = new Dictionary(); public static List LastPartProgramQueue = new List(); @@ -33,7 +32,7 @@ namespace Thermo.Active.Listeners public static List LastM156Data = new List(); public static List LastScadaData = new List(); - // FIXME TODO inserire oggetti corretti per THERMO + // Oggetti specifici per THERMO (1° definizione) public static Dictionary LastRecipeFullData = new Dictionary(); public static Dictionary LastRecipeOverData = new Dictionary(); public static bool? recipeHasChanged = null; @@ -44,6 +43,10 @@ namespace Thermo.Active.Listeners public static ThermoModels.ProdCycleModel LastProdCycleData = new ThermoModels.ProdCycleModel(); public static DTOProdInfo LastProdInfoData = new DTOProdInfo(); public static DTOThermoPanelProd LastProdPanelData = new DTOThermoPanelProd(); + // Oggetti per assi THERMO + public static List LastAxesNamesData = new List(); + public static DTOAxesInfoModel LastAxesInfoData = new DTOAxesInfoModel(); + public static DTOThermoAxesMovModel LastAxesPositions = new DTOThermoAxesMovModel(); public static bool LastIsNcConnected = false; } From 04d94b572ce6c5d2ee83f190878cb2c92fe8e862 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Sun, 20 Sep 2020 12:14:17 +0200 Subject: [PATCH 6/7] Ok signal-r x NOMI ASSI e tipo (da conf) --- Thermo.Active.NC/NcAdapter.cs | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/Thermo.Active.NC/NcAdapter.cs b/Thermo.Active.NC/NcAdapter.cs index 2d453007..a6808709 100644 --- a/Thermo.Active.NC/NcAdapter.cs +++ b/Thermo.Active.NC/NcAdapter.cs @@ -339,30 +339,23 @@ namespace Thermo.Active.NC return libraryError; } - + /// + /// dati assi da CONF + /// + /// + /// public CmsError ReadAxisData(out List axesNames) { + CmsError libraryError = NO_ERROR; axesNames = new List(); - List plcAxes = new List(); - // Read selected process - ushort selectedProcess = 0; - CmsError libraryError = numericalControl.PROC_RSelectedProcess(ref selectedProcess); - if (libraryError.IsError()) - return libraryError; - if (selectedProcess != 0) + axesNames = AxesConfig.Select(x => new DTOAxisNameModel() { - // Read axes names - libraryError = numericalControl.AXES_RAxesNames(selectedProcess, ref plcAxes); - - axesNames = plcAxes.Select(x => new DTOAxisNameModel() - { - Id = x.Id, - Name = x.Name, - IsSelectable = x.IsSelectable, - Type = x.Type.ToString() - }).ToList(); - } + Id = x.Id, + Name = x.Name, + IsSelectable = x.IsSelectable, + Type = x.Type.ToString() + }).ToList(); return libraryError; } From a2c5d327db729f5cf015e66f289e48d4deb45516 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Sun, 20 Sep 2020 12:54:08 +0200 Subject: [PATCH 7/7] inizio aggiunta gestione info assi --- Thermo.Active.Core/ThreadsFunctions.cs | 7 +++---- Thermo.Active.NC/NcAdapter.cs | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/Thermo.Active.Core/ThreadsFunctions.cs b/Thermo.Active.Core/ThreadsFunctions.cs index 5061f5d8..abfe5fe6 100644 --- a/Thermo.Active.Core/ThreadsFunctions.cs +++ b/Thermo.Active.Core/ThreadsFunctions.cs @@ -15,6 +15,7 @@ using Thermo.Active.Database.Controllers; using Thermo.Active.Model.DTOModels; using Thermo.Active.Model.DTOModels.AlarmModels; using Thermo.Active.Model.DTOModels.Scada; +using Thermo.Active.Model.DTOModels.ThAxes; using Thermo.Active.Model.DTOModels.ThModules; using Thermo.Active.Model.DTOModels.ThProd; using Thermo.Active.Model.DTOModels.ThRecipe; @@ -515,7 +516,7 @@ public static class ThreadsFunctions UpdateStat(MethodBase.GetCurrentMethod().Name, sw.ElapsedMilliseconds); // Wait - Thread.Sleep(CalcSleepTime(800, (int)sw.ElapsedMilliseconds)); + Thread.Sleep(CalcSleepTime(1000, (int)sw.ElapsedMilliseconds)); } } catch (ThreadAbortException) @@ -539,11 +540,10 @@ public static class ThreadsFunctions { sw.Restart(); -#if false if (ncAdapter.numericalControl.NC_IsConnected()) { // Get Data from NC - libraryError = ncAdapter.GetAxesPositionsBySelectedProcess(out DTOAxesModel axesPositions); + libraryError = ncAdapter.GetAxesPositions(out DTOThermoAxesMovModel axesPositions); if (libraryError.errorCode != 0) ManageLibraryError(libraryError); else @@ -552,7 +552,6 @@ public static class ThreadsFunctions } else RestoreConnection(); -#endif sw.Stop(); diff --git a/Thermo.Active.NC/NcAdapter.cs b/Thermo.Active.NC/NcAdapter.cs index a6808709..7219d3fd 100644 --- a/Thermo.Active.NC/NcAdapter.cs +++ b/Thermo.Active.NC/NcAdapter.cs @@ -12,6 +12,7 @@ using Thermo.Active.Model.DTOModels; using Thermo.Active.Model.DTOModels.AlarmModels; using Thermo.Active.Model.DTOModels.MaintenanceModels; using Thermo.Active.Model.DTOModels.Scada; +using Thermo.Active.Model.DTOModels.ThAxes; using Thermo.Active.Model.DTOModels.ThModules; using Thermo.Active.Model.DTOModels.ThProd; using Thermo.Active.Model.DTOModels.ThRecipe; @@ -276,6 +277,7 @@ namespace Thermo.Active.NC #region Axes +#if false public CmsError GetAxesPositions(out List axes) { axes = new List(); @@ -337,8 +339,24 @@ namespace Thermo.Active.NC //numericalControl.AXES_RFollowingError(1, ref axes.followingErr); + return libraryError; + } +#endif + 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; } + /// /// dati assi da CONF ///