diff --git a/Thermo.Active.Config/ServerConfig.cs b/Thermo.Active.Config/ServerConfig.cs index 06cc5210..21598824 100644 --- a/Thermo.Active.Config/ServerConfig.cs +++ b/Thermo.Active.Config/ServerConfig.cs @@ -66,6 +66,8 @@ namespace Thermo.Active.Config public static List RiskBoardConfig; public static List AxesConfig; public static Dictionary CMSConnectEntry; + public static string CMSConnectDataModel; + } diff --git a/Thermo.Active.Config/ServerConfigController.cs b/Thermo.Active.Config/ServerConfigController.cs index 87671519..2580263f 100644 --- a/Thermo.Active.Config/ServerConfigController.cs +++ b/Thermo.Active.Config/ServerConfigController.cs @@ -297,6 +297,7 @@ namespace Thermo.Active.Config XElement el = xmlConfigFile.Descendants("Machine").First(); CMSConnectEntry = new Dictionary(); ElaborateDataModel(el,el.Name.LocalName, ref CMSConnectEntry); + CMSConnectDataModel = File.ReadAllText(CONNECT_DATAMODEL_CONFIG_PATH); } private static void ElaborateDataModel(XElement el, string Parent, ref Dictionary Paths) diff --git a/Thermo.Active.Core/ThreadsFunctions.cs b/Thermo.Active.Core/ThreadsFunctions.cs index 77fc6604..71aaf5e0 100644 --- a/Thermo.Active.Core/ThreadsFunctions.cs +++ b/Thermo.Active.Core/ThreadsFunctions.cs @@ -1140,8 +1140,12 @@ public static class ThreadsFunctions NcAdapter ncAdapter = new NcAdapter(); try { + + //Write all the datamodel + if (!RedisController.WriteDatamodel(CMSConnectDataModel)) + ManageError(ERROR_LEVEL.FATAL, CMS_CONNECT_SETUP_ALARM_MESSAGE); - //Write all the default Entry + //Write all the default entries if (!RedisController.WriteDefaultEntry(CMSConnectEntry)) ManageError(ERROR_LEVEL.FATAL, CMS_CONNECT_SETUP_ALARM_MESSAGE); diff --git a/Thermo.Active.Core/ThreadsHandler.cs b/Thermo.Active.Core/ThreadsHandler.cs index 3449fe8e..92c4e8b1 100644 --- a/Thermo.Active.Core/ThreadsHandler.cs +++ b/Thermo.Active.Core/ThreadsHandler.cs @@ -38,7 +38,6 @@ namespace Thermo.Active.Core ThreadsFunctions.ReadM154Data // levare? }; - private static Action ThreadSetupCmsConnect = ThreadsFunctions.SetupCmsConnect; private volatile static List RunningThreadsList = new List(); public static Thread StartClient; @@ -48,13 +47,6 @@ namespace Thermo.Active.Core public static void Start() { ThreadsFunctions.RestoreConnection(); - - if (Config.ServerConfig.ServerStartupConfig.CmsConnectReady) - { - Thread t = new Thread(() => ThreadSetupCmsConnect()); - t.Start(); - Thread.Sleep(30); - } } public static void StartWorkers() diff --git a/Thermo.Active.Database/Controllers/RedisController.cs b/Thermo.Active.Database/Controllers/RedisController.cs index 73668e09..7f60e7de 100644 --- a/Thermo.Active.Database/Controllers/RedisController.cs +++ b/Thermo.Active.Database/Controllers/RedisController.cs @@ -22,7 +22,8 @@ namespace Thermo.Active.Database.Controllers private const string alarmsPath = "Machine:Plc:Condition"; private const string processStatusPath = "Machine:Cnc:CncProcesses:%NN%:Status"; private const string processModePath = "Machine:Cnc:CncProcesses:%NN%:Mode"; - + private const string datamodelPath = "TODO"; + public static void WriteProductionNotification(uint ProductionProcess, string Notification) { string redisHash = redUtil.man.redHash(redisNotificationAddress).Replace("%NN%", ProductionProcess.ToString("00")); @@ -58,8 +59,13 @@ namespace Thermo.Active.Database.Controllers string redisHash = redUtil.man.redHash(redisAlmEn); return redUtil.man.redSaveHashDict(redisHash, alarms); } - + + public static bool WriteDatamodel(string datamodel) + { + string redisHash = redUtil.man.redHash(datamodelPath); + return redUtil.man.setRSV(redisHash, datamodel.ToString()); + } public static bool WriteDefaultEntry(Dictionary entries) { foreach (KeyValuePair entry in entries) diff --git a/Thermo.Active.NC/NcFileAdapter.cs b/Thermo.Active.NC/NcFileAdapter.cs index 228b80f4..4dcab151 100644 --- a/Thermo.Active.NC/NcFileAdapter.cs +++ b/Thermo.Active.NC/NcFileAdapter.cs @@ -772,6 +772,11 @@ namespace Thermo.Active.NC Directory.CreateDirectory(dir); } File.WriteAllText(LIVE_RECIPE_PATH, rawData); + + if (Config.ServerConfig.ServerStartupConfig.CmsConnectReady) + { + RedisController.WriteProductionName(1, RecipeLiveData.RecipeName); + } answ = true; } catch diff --git a/Thermo.Active/Listeners/SignalR/SignalRListener.cs b/Thermo.Active/Listeners/SignalR/SignalRListener.cs index 757bad54..3a2925f0 100644 --- a/Thermo.Active/Listeners/SignalR/SignalRListener.cs +++ b/Thermo.Active/Listeners/SignalR/SignalRListener.cs @@ -307,10 +307,6 @@ namespace Thermo.Active.Listeners.SignalR var context = GlobalHost.ConnectionManager.GetHubContext(); context.Clients.Group("ncData").recipeChangedData(currMessage); - if (Config.ServerConfig.ServerStartupConfig.CmsConnectReady) - { - RedisController.WriteProductionName(1,currMessage.recipeName); - } } } diff --git a/Thermo.Active/program.cs b/Thermo.Active/program.cs index ecb0b188..051604a4 100644 --- a/Thermo.Active/program.cs +++ b/Thermo.Active/program.cs @@ -84,6 +84,11 @@ namespace Thermo.Active if (!string.IsNullOrWhiteSpace(ServerStartupConfig.ServerAddress.ToString())) opt.Urls.Add("http://" + ServerStartupConfig.ServerAddress.ToString() + ":" + ServerStartupConfig.ServerPort.ToString()); + if (Config.ServerConfig.ServerStartupConfig.CmsConnectReady) + { + ThreadsFunctions.SetupCmsConnect(); + } + // read and save last CURRENT RECIPE data... NcFileAdapter.ReadLastRecipe(); RecipeController.WriteCurrentRecipeToPlc();