diff --git a/Libs/CMS_CORE_Library.dll b/Libs/CMS_CORE_Library.dll index 48dde955..63759b8b 100644 Binary files a/Libs/CMS_CORE_Library.dll and b/Libs/CMS_CORE_Library.dll differ diff --git a/Thermo.Active.Model/Constants.cs b/Thermo.Active.Model/Constants.cs index 4c5497f8..5c9c5fd8 100644 --- a/Thermo.Active.Model/Constants.cs +++ b/Thermo.Active.Model/Constants.cs @@ -263,7 +263,12 @@ namespace Thermo.Active.Model public const string SEND_QUEUE_DATA = "SEND_QUEUE_DATA"; public const string SEND_M155_DATA = "SEND_M155_DATA"; public const string SEND_SCADA_DATA = "SEND_SCADA_DATA"; - public const string SEND_RECIPE_STATUS = "SEND_RECIPE_STATUS"; + + // MVVM Messages for Thermo active specs + public const string SEND_THERMO_RECIPE_FULL = "SEND_THERMO_RECIPE_FULL"; + public const string SEND_THERMO_RECIPE_OVERWIEW = "SEND_THERMO_RECIPE_OVERWIEW"; + public const string SEND_THERMO_MODULE_DATA = "SEND_THERMO_MODULE_DATA"; + public const string SEND_THERMO_WARMERS_DATA = "SEND_THERMO_WARMERS_DATA"; public const string BROADCAST_DATA = "BROADCAST_DATA"; diff --git a/Thermo.Active.NC/NcAdapter.cs b/Thermo.Active.NC/NcAdapter.cs index c76c8a2f..7cb5544b 100644 --- a/Thermo.Active.NC/NcAdapter.cs +++ b/Thermo.Active.NC/NcAdapter.cs @@ -4,6 +4,7 @@ using CMS_CORE_Library.Fanuc; using CMS_CORE_Library.Models; using CMS_CORE_Library.Osai; using CMS_CORE_Library.Siemens; +using CMS_CORE_Library.S7Net; using Thermo.Active.Database.Controllers; using Thermo.Active.Model.DatabaseModels; using Thermo.Active.Model.DTOModels; @@ -27,6 +28,11 @@ namespace Thermo.Active.NC { public class NcAdapter : IDisposable { + /// + /// check e usare dati simulati/reali (in fase implementazione) + /// + public bool simData = true; + public Nc numericalControl; public NcAdapter() => @@ -69,6 +75,9 @@ namespace Thermo.Active.NC case NC_VENDOR.OSAI: return new Nc_Osai(NcConfig.NcIpAddress, NcConfig.NcPort, 2000); + + case NC_VENDOR.SIEMENS_S7: + return new Nc_S7Net(NcConfig.NcIpAddress, NcConfig.NcPort, 2000); } return null; @@ -1413,7 +1422,7 @@ namespace Thermo.Active.NC } /// - /// Legge tutti i parametri della ricetta + /// Legge tutti i parametri della ricetta /// /// Oggetto ricetta corrente HMI /// @@ -1426,54 +1435,59 @@ namespace Thermo.Active.NC RPRange currRange = new RPRange(); RPStatus currStatus = new RPStatus(); - // !!!FARE davvero!!! + if (simData) + { + // leggo l'intero array delle DB... QUI FAKE sulle DB configurate... + List recipeConfig = RecipeConfig.Select(x => new DTORecipeConfigModel() + { + Id = x.Id, + Category = x.Category.ToString(), + SubCategory_1 = x.SubCategory_1, + SubCategory_2 = x.SubCategory_2, + Name = x.Name, + Description = x.Description, + Format = x.Format, + Label = $"{x.Category}_{x.SubCategory_1}_{x.SubCategory_2}_{x.Name}".Replace("__", "_").Replace("__", "_").ToLower() + }).ToList(); + + int minVal, maxVal, actVal; + Random rnd = new Random(); + foreach (var item in recipeConfig) + { + // randomizzo valori... + minVal = rnd.Next(0, 10); + maxVal = rnd.Next(100, 200); + actVal = rnd.Next(minVal - 5, maxVal + 5); + currRange = new RPRange() + { + Min = minVal, + Max = maxVal, + }; + currStatus = new RPStatus() + { + Visible = true, + Enabled = true, + HasError = (actVal < minVal || actVal > maxVal) + }; + currParam = new DTORecipeParam() + { + Range = currRange, + Status = currStatus, + UnitMeasure = "", + ValueAct = actVal + }; + currRecipe.Add(item.Label, currParam); + } + } + else + { + // FIXME #if false // gestione errore cmsError = ReadScadaData(schema, out currParam); if (cmsError.IsError()) return cmsError; #endif - - // leggo l'intero array delle DB... QUI FAKE sulle DB configurate... - List recipeConfig = RecipeConfig.Select(x => new DTORecipeConfigModel() - { - Id = x.Id, - Category = x.Category.ToString(), - SubCategory_1 = x.SubCategory_1, - SubCategory_2 = x.SubCategory_2, - Name = x.Name, - Description = x.Description, - Format = x.Format, - Label = $"{x.Category}_{x.SubCategory_1}_{x.SubCategory_2}_{x.Name}".Replace("__", "_").Replace("__", "_").ToLower() - }).ToList(); - - int minVal, maxVal, actVal; - Random rnd = new Random(); - foreach (var item in recipeConfig) - { - // randomizzo valori... - minVal = rnd.Next(0, 10); - maxVal = rnd.Next(100, 200); - actVal = rnd.Next(minVal - 5, maxVal + 5); - currRange = new RPRange() - { - Min = minVal, - Max = maxVal, - }; - currStatus = new RPStatus() - { - Visible = true, - Enabled = true, - HasError = (actVal < minVal || actVal > maxVal) - }; - currParam = new DTORecipeParam() - { - Range = currRange, - Status = currStatus, - UnitMeasure = "", - ValueAct = actVal - }; - currRecipe.Add(item.Label, currParam); } // restituisco cod errore se trovato @@ -1482,7 +1496,7 @@ namespace Thermo.Active.NC /// - /// Legge tutti i parametri della ricetta e calcolo la overview dei vari steps + /// Legge tutti i parametri della ricetta e calcolo la overview dei vari steps /// /// Oggetto overview ricetta corrente HMI /// diff --git a/Thermo.Active/Listeners/ListenersHandler.cs b/Thermo.Active/Listeners/ListenersHandler.cs index 5a440f41..5f39f252 100644 --- a/Thermo.Active/Listeners/ListenersHandler.cs +++ b/Thermo.Active/Listeners/ListenersHandler.cs @@ -90,10 +90,26 @@ namespace Thermo.Active.Listeners infos.Add(MessageServices.Current.Subscribe(SEND_CMSCONNECT_GW_REBOOT_STATUS, (a, b) => { SignalRListener.SetGatewayRebootStatus(a); - })); + })); + + // add specific modules for THERMO + infos.Add(MessageServices.Current.Subscribe(SEND_THERMO_RECIPE_FULL, (a, b) => + { + SignalRListener.SendThermoRecipeFullData(a); + })); + infos.Add(MessageServices.Current.Subscribe(SEND_THERMO_RECIPE_OVERWIEW, (a, b) => + { + SignalRListener.SendThermoRecipeOverviewData(a); + })); + infos.Add(MessageServices.Current.Subscribe(SEND_THERMO_MODULE_DATA, (a, b) => + { + SignalRListener.SendThermoModulesData(a); + })); + infos.Add(MessageServices.Current.Subscribe(SEND_THERMO_WARMERS_DATA, (a, b) => + { + SignalRListener.SendThermoWarmersData(a); + })); - //////////////////////////// Database - ///// erano tooling... // Broadcast infos.Add(MessageServices.Current.Subscribe(BROADCAST_DATA, (a, b) => @@ -103,7 +119,7 @@ namespace Thermo.Active.Listeners SignalRListener.BroadcastData(); })); } - + public static void Stop() { MessageServices.Current.UnSubscribe(infos.ToArray()); diff --git a/Thermo.Active/Listeners/SignalR/SignalRListener.cs b/Thermo.Active/Listeners/SignalR/SignalRListener.cs index f98376b0..0f0b918e 100644 --- a/Thermo.Active/Listeners/SignalR/SignalRListener.cs +++ b/Thermo.Active/Listeners/SignalR/SignalRListener.cs @@ -14,6 +14,7 @@ using System.Threading; using static Thermo.Active.Listeners.SignalRStaticObjects; using static Thermo.Active.Model.Constants; using static Thermo.Active.Config.ServerConfig; +using Thermo.Active.Model.DTOModels.Recipe; namespace Thermo.Active.Listeners.SignalR { @@ -249,6 +250,61 @@ namespace Thermo.Active.Listeners.SignalR } } + public static void SendThermoRecipeFullData(object recipeFull) + { + Dictionary currRecipeFull = recipeFull as Dictionary; + + // FIXME TODO: usare un foreach comparer? + if (!LastRecipeFullData.SequenceEqual(currRecipeFull)) + { + LastRecipeFullData = currRecipeFull; + + var context = GlobalHost.ConnectionManager.GetHubContext(); + context.Clients.Group("ncData").recipeFullData(currRecipeFull); + } + } + + public static void SendThermoRecipeOverviewData(object recipeOver) + { + Dictionary currRecipeOver = recipeOver as Dictionary; + + if (!LastRecipeOverData.SequenceEqual(currRecipeOver)) + { + LastRecipeOverData = currRecipeOver; + + var context = GlobalHost.ConnectionManager.GetHubContext(); + context.Clients.Group("ncData").recipeOverData(currRecipeOver); + } + } + + public static void SendThermoModulesData(object modules) + { + Dictionary currModules = modules as Dictionary; + + // FIXME TODO: usare un foreach comparer? + if (!LastRecipeFullData.SequenceEqual(currModules)) + { + LastRecipeFullData = currModules; + + var context = GlobalHost.ConnectionManager.GetHubContext(); + context.Clients.Group("ncData").recipeModulesData(currModules); + } + } + + public static void SendThermoWarmersData(object warmers) + { + Dictionary currWarmers = warmers as Dictionary; + + // FIXME TODO: usare un foreach comparer? + if (!LastRecipeFullData.SequenceEqual(currWarmers)) + { + LastRecipeFullData = currWarmers; + + var context = GlobalHost.ConnectionManager.GetHubContext(); + context.Clients.Group("ncData").recipeWarmersData(currWarmers); + } + } + public static void SetGatewayRebootStatus(object status) { string msg = status.ToString(); @@ -286,32 +342,40 @@ namespace Thermo.Active.Listeners.SignalR group.expiredMaintenances(LastExpiredMaintenances); // Send nc status - context.Clients.Group("ncData").ncNetworkStatus( + group.ncNetworkStatus( new { connected = LastIsNcConnected }); // Send softkeys Nc - context.Clients.Group("ncData").ncSoftKeys(LastNcSoftKeysData); + group.ncSoftKeys(LastNcSoftKeysData); // Send user softKeys - context.Clients.Group("ncData").userSoftKeys(LastUserSoftKeysData); + group.userSoftKeys(LastUserSoftKeysData); // Send heads data - context.Clients.Group("ncData").headsData(LastHeadsData); + group.headsData(LastHeadsData); // Send axesNames data - context.Clients.Group("ncData").axesNames(LastAxesNamesData); + group.axesNames(LastAxesNamesData); // Send positions - context.Clients.Group("ncData").axesPositions(LastAxesPositions); + group.axesPositions(LastAxesPositions); // Send active program data - context.Clients.Group("ncData").activeProgramData(LastProgramData); + group.activeProgramData(LastProgramData); // Send magazine is active data - context.Clients.Group("ncData").magazineIsActive(LastNcMagazineIsActive); + group.magazineIsActive(LastNcMagazineIsActive); // Send PP Queue - context.Clients.Group("ncData").partProgramQueue(LastPartProgramQueue); + group.partProgramQueue(LastPartProgramQueue); // Send m155 data - context.Clients.Group("ncData").m155Data(LastM155Data); + group.m155Data(LastM155Data); // Send Scada - context.Clients.Group("ncData").scadaData(LastScadaData); + group.scadaData(LastScadaData); + + // Send THERMO Recipe data + group.recipeFullData(LastRecipeFullData); + group.recipeOverData(LastRecipeOverData); + // Send THERMO Modules data + group.recipeModulesData(LastModulesData); + // Send THERMO Warmers data + group.recipeWarmersData(LastWarmersData); Debug.WriteLine(string.Format("{0} {1} Broadcast..completed", DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss"), DateTime.Now.Millisecond)); Monitor.Exit(_broadcastlock); diff --git a/Thermo.Active/Listeners/SignalRStaticObjects.cs b/Thermo.Active/Listeners/SignalRStaticObjects.cs index 9edb263d..34ac9733 100644 --- a/Thermo.Active/Listeners/SignalRStaticObjects.cs +++ b/Thermo.Active/Listeners/SignalRStaticObjects.cs @@ -2,6 +2,7 @@ using Thermo.Active.Model.DTOModels.AlarmModels; using Thermo.Active.Model.DTOModels.Scada; using System.Collections.Generic; +using Thermo.Active.Model.DTOModels.Recipe; namespace Thermo.Active.Listeners { @@ -23,11 +24,15 @@ namespace Thermo.Active.Listeners public static Dictionary LastNcMagazineIsActive = new Dictionary(); public static List LastPartProgramQueue = new List(); public static List LastM155Data = new List(); - public static List LastScadaData = new List(); + public static List LastScadaData = new List(); + + // FIXME TODO inserire oggetti corretti per THERMO + public static Dictionary LastRecipeFullData = new Dictionary(); + public static Dictionary LastRecipeOverData = new Dictionary(); + public static List LastModulesData = new List(); + public static List LastWarmersData = new List(); public static bool LastIsNcConnected = false; - - // aggiugere oggetti nuovi e levare quelli che non servono +... } } \ No newline at end of file