diff --git a/Libs/CMS_CORE_Library.dll b/Libs/CMS_CORE_Library.dll index fd5f7352..849aa9d8 100644 Binary files a/Libs/CMS_CORE_Library.dll and b/Libs/CMS_CORE_Library.dll differ diff --git a/Step.Config/Config/serverConfigValidator.xsd b/Step.Config/Config/serverConfigValidator.xsd index c90ea360..fd5c191d 100644 --- a/Step.Config/Config/serverConfigValidator.xsd +++ b/Step.Config/Config/serverConfigValidator.xsd @@ -26,6 +26,8 @@ + + diff --git a/Step.Config/Config/toolManagerConfig.xml b/Step.Config/Config/toolManagerConfig.xml index 0e7ffaf2..55ede02f 100644 --- a/Step.Config/Config/toolManagerConfig.xml +++ b/Step.Config/Config/toolManagerConfig.xml @@ -1,7 +1,7 @@  - true + false false true false diff --git a/Step.Config/ServerConfigController.cs b/Step.Config/ServerConfigController.cs index ef93c97b..d20712f3 100644 --- a/Step.Config/ServerConfigController.cs +++ b/Step.Config/ServerConfigController.cs @@ -243,7 +243,9 @@ namespace Step.Config ServerPort = Convert.ToInt32(x.Element("serverPort").Value), EnableDirectoryBrowsing = Convert.ToBoolean(x.Element("enableDirectoryBrowsing").Value), DatabaseAddress = x.Element("databaseAddress").Value, - AutoOpenCmsClient = Convert.ToBoolean(x.Element("autoOpenCmsClient").Value) + AutoOpenCmsClient = Convert.ToBoolean(x.Element("autoOpenCmsClient").Value), + MTCFolderPath = x.Element("MTCFolderPath").Value, + MTCApplicationName = x.Element("MTCApplicationName").Value }).FirstOrDefault(); } diff --git a/Step.Core/ThreadsFunctions.cs b/Step.Core/ThreadsFunctions.cs index 12f187bc..de1ad091 100644 --- a/Step.Core/ThreadsFunctions.cs +++ b/Step.Core/ThreadsFunctions.cs @@ -6,13 +6,13 @@ using Step.Model.DTOModels.AlarmModels; using Step.Model.DTOModels.Scada; using Step.Model.DTOModels.ToolModels; using Step.NC; -using Step.Utils; -using System; using System.Collections.Generic; using System.Diagnostics; +using System.IO; using System.Linq; using System.Threading; using TeamDev.SDK.MVVM; +using static CMS_CORE_Library.Models.DataStructures; using static Step.Config.ServerConfig; using static Step.Model.Constants; using static Step.Utils.ExceptionManager; @@ -764,9 +764,123 @@ public static class ThreadsFunctions } } + public static void ReadM154Data() + { + NcHandler ncHandler = new NcHandler(); + Stopwatch sw = new Stopwatch(); + + try + { + // Try connection + CmsError libraryError = ncHandler.Connect(); + if (libraryError.errorCode != 0) + ManageLibraryError(libraryError); + + while (true) + { + sw.Restart(); + + // Check if client is connected + if (ncHandler.numericalControl.NC_IsConnected()) + { + libraryError = ncHandler.GetM154Data(out List data, out bool MTCStatus); + if (libraryError.IsError()) + ManageLibraryError(libraryError); + + string MTCProcessName = "PROGRAMPARSER_MTC_ADAPTER"; + string ApplicationPath = ServerStartupConfig.MTCFolderPath + ServerStartupConfig.MTCApplicationName + ".exe"; + if (ServerStartupConfig.MTCFolderPath != "") + { + // Check if process exists + Process[] processes = Process.GetProcessesByName(MTCProcessName); + if (!MTCStatus) + { + if (processes.Count() > 0) + processes[0].Kill(); + } + else + { + // if is already running ignore + if (processes.Count() == 0) + if (File.Exists(ApplicationPath)) + Process.Start(ApplicationPath); + } + + foreach (M154DataModel m154 in data) + { + string stringVal = "Path_" + m154.Process + "_"; + string val = ""; + // Check if command is MTC + if (m154.Parameters[0] == "MTC") + { + // Convert tag string in Pascal Case and add to result string + switch (m154.Parameters[1].ToLower()) + { + case "currprog": + stringVal += "CurrProg"; + break; + + case "partid": + stringVal += "PartId"; + break; + + default: + stringVal += m154.Parameters[1]; + break; + } + // Set value + if (m154.Parameters.Count() > 2) + val = m154.Parameters[2]; + + // Create MTC Directory if not exist + if (!Directory.Exists(ServerStartupConfig.MTCFolderPath)) + Directory.CreateDirectory(ServerStartupConfig.MTCFolderPath); + + string outputFileName = ServerStartupConfig.MTCFolderPath + "CmsGeneralStatus.mtc"; + // Create file if not exits + if (!File.Exists(outputFileName)) + File.Create(outputFileName); + // Read file + List fileLines = File.ReadAllLines(outputFileName).ToList(); + string[] parametersInLine; + bool found = false; + for (int i = 0; i < fileLines.Count(); i++) + { + // Get tag & value from row + parametersInLine = fileLines[i].Split('|'); + if (parametersInLine[0] == stringVal) + { + found = true; + fileLines[i] = stringVal + "|" + val; + } + } + // If tag doesn't exists, append new line + if (!found) + fileLines.Add(stringVal + "|" + val); + + // Write file + File.WriteAllLines(ServerStartupConfig.MTCFolderPath, fileLines.ToArray()); + } + } + } + } + else + RestoreConnection(); + sw.Stop(); + + // Wait + Thread.Sleep(CalcSleepTime(500, (int)sw.ElapsedMilliseconds)); + } + } + catch (ThreadAbortException) + { + ncHandler.Dispose(); + } + } + #endregion Functions - #region SupportFunctions + #region SupportFunctions private static void TryNcConnection() { @@ -812,7 +926,7 @@ public static class ThreadsFunctions } public static void AbortNcConnection() - { + { if (ConnThread != null && ConnThread.IsAlive) ConnThread.Abort(); } @@ -836,12 +950,13 @@ public static class ThreadsFunctions case CMS_ERROR_CODES.SIEMENS_HMI_NOT_RUNNING: Manage(ERROR_LEVEL.FATAL, cmsError.localizationKey); break; + case CMS_ERROR_CODES.INTERNAL_ERROR: Manage(ERROR_LEVEL.FATAL, cmsError.localizationKey); break; - //default: - // Manage(ERROR_LEVEL.WARNING, cmsError.localizationKey); - // break; + //default: + // Manage(ERROR_LEVEL.WARNING, cmsError.localizationKey); + // break; } } diff --git a/Step.Model/ConfigModels/ServerConfigModel.cs b/Step.Model/ConfigModels/ServerConfigModel.cs index 20b825aa..941f6d2a 100644 --- a/Step.Model/ConfigModels/ServerConfigModel.cs +++ b/Step.Model/ConfigModels/ServerConfigModel.cs @@ -15,5 +15,9 @@ namespace Step.Model.ConfigModels public bool EnableDirectoryBrowsing { get; set; } public string DatabaseAddress { get; set; } public bool AutoOpenCmsClient { get; set; } + + public string MTCFolderPath { get; set; } + + public string MTCApplicationName { get; set; } } } \ No newline at end of file diff --git a/Step.NC/NcHandler.cs b/Step.NC/NcHandler.cs index d64e5d42..6905fe5e 100644 --- a/Step.NC/NcHandler.cs +++ b/Step.NC/NcHandler.cs @@ -1382,11 +1382,12 @@ namespace Step.NC return NO_ERROR; } - public CmsError GetM154Data(out List data) + public CmsError GetM154Data(out List data, out bool MTCStatus) { + MTCStatus = false; data = new List(); - return numericalControl.PLC_RM154Data(ref data); + return numericalControl.PLC_RM154Data(ref data, ref MTCStatus); } #endregion Read Data diff --git a/Step/Listeners/SignalR/SignalRListener.cs b/Step/Listeners/SignalR/SignalRListener.cs index 44ed73b6..cfb65ab1 100644 --- a/Step/Listeners/SignalR/SignalRListener.cs +++ b/Step/Listeners/SignalR/SignalRListener.cs @@ -310,6 +310,8 @@ namespace Step.Listeners.SignalR context.Clients.Group("ncData").partProgramQueue(LastPartProgramQueue); // Send m155 data context.Clients.Group("ncData").m155Data(LastM155Data); + // Send Scada + context.Clients.Group("ncData").scadaData(LastScadaData); Debug.WriteLine(string.Format("{0} {1} Broadcast..completed", DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss"), DateTime.Now.Millisecond)); Monitor.Exit(_broadcastlock);