diff --git a/Libs/CMS_CORE_Library.dll b/Libs/CMS_CORE_Library.dll index 45d0b48b..c778d9ea 100644 Binary files a/Libs/CMS_CORE_Library.dll and b/Libs/CMS_CORE_Library.dll differ diff --git a/Step.Config/Config/areasConfig.xml b/Step.Config/Config/areasConfig.xml index d725992b..790f4cb6 100644 --- a/Step.Config/Config/areasConfig.xml +++ b/Step.Config/Config/areasConfig.xml @@ -1,40 +1,86 @@  - - - - true - false - true - - - true - false - true - - - true - true - true - - - false - true - false - - - true - false - true - - - true - false - false - - - true - true - true - - - \ No newline at end of file + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Step.Config/Config/maintenancesConfigValidator.xsd b/Step.Config/Config/maintenancesConfigValidator.xsd index 50ce3478..acd89c2d 100644 --- a/Step.Config/Config/maintenancesConfigValidator.xsd +++ b/Step.Config/Config/maintenancesConfigValidator.xsd @@ -3,6 +3,7 @@ + @@ -25,6 +26,7 @@ + diff --git a/Step.Config/Config/softKeyConfig.xml b/Step.Config/Config/softKeyConfig.xml new file mode 100644 index 00000000..dee64311 --- /dev/null +++ b/Step.Config/Config/softKeyConfig.xml @@ -0,0 +1,57 @@ + + + + true + 1 + 1 + + Test + Ita + + + + true + 1 + + Test + Ita + + + 1 + 1 + + + + false + 2 + + Test + Ita + + + 1 + 1 + + + + true + 2 + + Test + Ita + + + 1 + 1 + + + + true + 1 + 1 + + Test + Ita + + + \ No newline at end of file diff --git a/Step.Config/Config/softKeyConfigValidator.xsd b/Step.Config/Config/softKeyConfigValidator.xsd new file mode 100644 index 00000000..d6caca09 --- /dev/null +++ b/Step.Config/Config/softKeyConfigValidator.xsd @@ -0,0 +1,92 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Step.Config/ServerConfig.cs b/Step.Config/ServerConfig.cs index e7dd5927..d7310217 100644 --- a/Step.Config/ServerConfig.cs +++ b/Step.Config/ServerConfig.cs @@ -19,6 +19,8 @@ namespace Step.Config public static List FunctionsAccessConfig; public static List AllFunctionalityDisabled; + public static List SoftKeysConfig; + public static AreasConfigModel ProductionConfig; public static AreasConfigModel ToolingConfig; public static AreasConfigModel ReportConfig; diff --git a/Step.Config/ServerConfigController.cs b/Step.Config/ServerConfigController.cs index f611f638..88c94071 100644 --- a/Step.Config/ServerConfigController.cs +++ b/Step.Config/ServerConfigController.cs @@ -70,10 +70,37 @@ namespace Step.Config Intervall = TimeSpan.FromMinutes(Convert.ToDouble(x.Element("interval").Value)), Deadline = DateTime.Parse(x.Element("deadline").Value), Type = x.Element("type").Value, - CouterId = Convert.ToInt32(x.Element("counterId").Value) + CouterId = Convert.ToInt32(x.Element("counterId").Value) } ) .ToList(); + + // Get SoftKeys + xmlConfigFile = GetXmlHandlerWithValidator(SOFT_KEY_CONFIG_SCHEMA_PATH, SOFT_KEY_CONFIG_PATH); + int id = 1; + SoftKeysConfig = xmlConfigFile + .Root + .Elements() + .Where(x => Convert.ToBoolean(x.Element("active").Value) == true) + .Select(x => new SoftKeyConfigModel() + { + Id = id++, + PlcId = Convert.ToInt32(x.Element("plcId")?.Value), + IsActive = Convert.ToBoolean(x.Element("active").Value), + Category = Convert.ToInt32(x.Element("category").Value), + LocalizedNames = x.Element("localizedNames").Elements().ToDictionary( // Read localized names and convert into a dictionary + y => y.Attribute("langKey").Value, y => y.Value + ), + + SubKeys = x.Element("plcKeys")?.Elements().Select(y => new SubKeysModel() + { + Id = id++, + PlcId = Convert.ToInt32(y.Attribute("plcId").Value), + Text = y.Value + }).ToList(), + Type = GetSoftKeyType(x.Name.ToString()) + }) + .ToList(); } catch (Exception ex) { @@ -96,6 +123,16 @@ namespace Step.Config return xmlConfigFile; } + private static SOFTKEY_TYPE GetSoftKeyType(string type) + { + switch (type) + { + case "procedure": return SOFTKEY_TYPE.PROCEDURE; + case "group": return SOFTKEY_TYPE.MULTIPLE; + default: return SOFTKEY_TYPE.SOFTKEY; + } + } + private static void SetAreaValueByName(XElement element) { // Choose which area to be set diff --git a/Step.Config/Step.Config.csproj b/Step.Config/Step.Config.csproj index 59b32797..a56b2a3a 100644 --- a/Step.Config/Step.Config.csproj +++ b/Step.Config/Step.Config.csproj @@ -47,6 +47,14 @@ + + PreserveNewest + Designer + + + Designer + Always + PreserveNewest diff --git a/Step.Model/ConfigModels/SoftKeyConfigModel.cs b/Step.Model/ConfigModels/SoftKeyConfigModel.cs new file mode 100644 index 00000000..2b421290 --- /dev/null +++ b/Step.Model/ConfigModels/SoftKeyConfigModel.cs @@ -0,0 +1,23 @@ +using System.Collections.Generic; +using static Step.Utils.Constants; + +namespace Step.Model.ConfigModels +{ + public class SoftKeyConfigModel + { + public int Id { get; set; } + public Dictionary LocalizedNames { get; set; } + public int Category { get; set; } + public bool IsActive { get; set; } + public List SubKeys { get; set; } + public int PlcId { get; set; } + public SOFTKEY_TYPE Type { get; set; } + } + + public class SubKeysModel + { + public int Id; + public int PlcId; + public string Text; + } +} diff --git a/Step.Utils/Constants.cs b/Step.Model/Constants.cs similarity index 91% rename from Step.Utils/Constants.cs rename to Step.Model/Constants.cs index 4d5aaf20..5238ee32 100644 --- a/Step.Utils/Constants.cs +++ b/Step.Model/Constants.cs @@ -20,6 +20,13 @@ namespace Step.Utils FATAL = 4 } + public enum SOFTKEY_TYPE + { + SOFTKEY = 0, + PROCEDURE = 1, + MULTIPLE = 2 + } + public static class NC_VENDOR { public const string DEMO = "DEMO"; @@ -71,6 +78,9 @@ namespace Step.Utils public const string MAINTENANCES_CONFIG_SCHEMA_PATH = CONFIG_DIRECTORY + "maintenancesConfigValidator.xsd"; public const string MAINTENANCES_CONFIG_PATH = CONFIG_DIRECTORY + "maintenancesConfig.xml"; + public const string SOFT_KEY_CONFIG_SCHEMA_PATH = CONFIG_DIRECTORY + "softKeyConfigValidator.xsd"; + public const string SOFT_KEY_CONFIG_PATH = CONFIG_DIRECTORY + "softKeyConfig.xml"; + public static string WEBSITE_DIRECTORY = Path.Combine(BASE_PATH, "..", "wwwroot"); public static string LANGUAGE_PACK_DIRECTORY = BASE_PATH + "\\languages\\"; public static string LANGUAGE_SCHEMA_PATH = BASE_PATH + "\\LanguageValidator.xsd"; @@ -90,6 +100,8 @@ namespace Step.Utils 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"; + public const string SEND_SOFT_KEYS_DATA = "SEND_SOFT_KEYS_DATA"; + public const string BROADCAST_DATA = "BROADCAST_DATA"; // ID prefix diff --git a/Step.Model/DTOModels/DTOProcessDataModel.cs b/Step.Model/DTOModels/DTOProcessDataModel.cs index 2b31b5d5..62ae221c 100644 --- a/Step.Model/DTOModels/DTOProcessDataModel.cs +++ b/Step.Model/DTOModels/DTOProcessDataModel.cs @@ -7,6 +7,7 @@ namespace Step.Model.DTOModels public class DTOProcessDataModel { public bool isRunning; + public bool selectedProcess; public List processes; public DTOProcessDataModel() diff --git a/Step.Model/DTOModels/DTOSoftKeyModel.cs b/Step.Model/DTOModels/DTOSoftKeyModel.cs new file mode 100644 index 00000000..a4dfaf19 --- /dev/null +++ b/Step.Model/DTOModels/DTOSoftKeyModel.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using static Step.Utils.Constants; + +namespace Step.Model.DTOModels +{ + public class DTOSoftKeyConfigModel + { + public int Id { get; set; } + public int Category { get; set; } + public SOFTKEY_TYPE Type { get; set; } + public Dictionary SubKeys { get; set; } + } + + public class DTOSoftKeyModel + { + public int Id { get; set; } + public int Category { get; set; } + public bool Active { get; set; } + public bool Value { get; set; } + } +} diff --git a/Step.Model/Step.Model.csproj b/Step.Model/Step.Model.csproj index 9a49fbfb..498d3feb 100644 --- a/Step.Model/Step.Model.csproj +++ b/Step.Model/Step.Model.csproj @@ -64,6 +64,8 @@ + + @@ -88,6 +90,7 @@ + @@ -118,7 +121,6 @@ - diff --git a/Step.NC/NcHandler.cs b/Step.NC/NcHandler.cs index a83ce0ea..13eb971d 100644 --- a/Step.NC/NcHandler.cs +++ b/Step.NC/NcHandler.cs @@ -339,7 +339,7 @@ namespace Step.NC // List of PLC counters List counters = new List(); - // Populate counters + // Get counters values from PLC CmsError cmsError = numericalControl.PLC_RMachineCounters(ref counters); if (cmsError.IsError()) return cmsError; @@ -443,6 +443,48 @@ namespace Step.NC return cmsError; } + public CmsError GetSoftKeys(out List softKeys) + { + softKeys = new List(); + List plcSoftKeys = new List(); + + // Get softkeys data from PLC + CmsError cmsError = numericalControl.PLC_RSoftKeys(ref plcSoftKeys); + if (cmsError.IsError()) + return cmsError; + + foreach (var softKey in SoftKeysConfig) + { + if(softKey.Type == SOFTKEY_TYPE.MULTIPLE) + { + foreach (var subkey in softKey.SubKeys) + { + var plcSoftKey = plcSoftKeys.Find(x => x.Id == subkey.PlcId); + softKeys.Add(new DTOSoftKeyModel() + { + Id = subkey.Id, + Active = plcSoftKey.Active, + Category = softKey.Category, + Value = plcSoftKey.Value + }); + } + } + else + { + var plcSoftKey = plcSoftKeys.Find(x => x.Id == softKey.PlcId); + softKeys.Add(new DTOSoftKeyModel() + { + Id = softKey.Id, + Active = plcSoftKey.Active, + Category = softKey.Category, + Value = plcSoftKey.Value + }); + } + } + + return cmsError; + } + public CmsError RefreshAllAlarms() { return new CmsError(0, ""); diff --git a/Step.Tasks/ThreadsFunctions.cs b/Step.Tasks/ThreadsFunctions.cs index b2cdcdf5..ce34619a 100644 --- a/Step.Tasks/ThreadsFunctions.cs +++ b/Step.Tasks/ThreadsFunctions.cs @@ -18,7 +18,8 @@ public static class ThreadsFunctions private static long ReadProcPPTimer = 0, ReadProcPPTimes = 0; private static long ReadFunctionTimer = 0, ReadFunctionTimes = 0; private static long ReadMaintenanceTimer = 0, ReadMaintenanceTimes = 0; - + private static long ReadSoftKeysTimer = 0, ReadSoftKeysTimes = 0; + private static Thread ConnThread; #region Nc Threads @@ -242,6 +243,50 @@ public static class ThreadsFunctions } } + public static void ReadSoftKeysData() + { + 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(); + + if (ncHandler.numericalControl.NC_IsConnected()) + { + // Get Data from database and PLC + libraryError = ncHandler.GetSoftKeys(out List softKeys); + if (libraryError.errorCode != 0) + ManageLibraryError(libraryError); + else + // Send through signalR + MessageServices.Current.Publish(SEND_SOFT_KEYS_DATA, null, softKeys); + } + else + TryNcConnection(); + + sw.Stop(); + //Send to the UI the time + ReadSoftKeysTimer += sw.ElapsedMilliseconds; + ReadSoftKeysTimes++; + + // Wait + Thread.Sleep(200); + } + } + catch (ThreadAbortException) + { + ncHandler.Dispose(); + } + } + #endregion Nc Threads #region SupportFunctions @@ -383,7 +428,12 @@ public static class ThreadsFunctions ReadMaintenanceTimer = 0; ReadMaintenanceTimes = 0; } - + if (ThreadsHandler.RunningThreadStatus.ContainsKey("ReadSoftKeysData") && ReadSoftKeysTimes != 0) + { + ThreadsHandler.RunningThreadStatus["ReadSoftKeysData"] = (ReadSoftKeysTimer / ReadSoftKeysTimes) + " mS"; + ReadSoftKeysTimer = 0; + ReadSoftKeysTimes = 0; + } MessageServices.Current.Publish(SEND_THREADS_STATUS, null, ThreadsHandler.RunningThreadStatus); diff --git a/Step.Tasks/ThreadsHandler.cs b/Step.Tasks/ThreadsHandler.cs index 297887d1..d8983aec 100644 --- a/Step.Tasks/ThreadsHandler.cs +++ b/Step.Tasks/ThreadsHandler.cs @@ -8,14 +8,15 @@ namespace Step.Core { public static class ThreadsHandler { - private static List ThreadFunctionsList = new List + private static List ThreadsFunctionsList = new List { ThreadsFunctions.ReadAlarms, ThreadsFunctions.ReadPowerOnData, ThreadsFunctions.StatThread, ThreadsFunctions.ReadProcessesPPStatus, ThreadsFunctions.ReadEnabledFunctionality, - ThreadsFunctions.ReadExpiredMaintenances + ThreadsFunctions.ReadExpiredMaintenances, + ThreadsFunctions.ReadSoftKeysData }; private volatile static List RunningThreadsList = new List(); @@ -32,7 +33,7 @@ namespace Step.Core RunningThreadStatus.Clear(); // For each function run in the list a thread - ThreadFunctionsList.ForEach(threadFunction => + ThreadsFunctionsList.ForEach(threadFunction => { // Run new Thread in the list Thread t = new Thread(() => diff --git a/Step.Utils/Step.Utils.csproj b/Step.Utils/Step.Utils.csproj index d3cebe1b..961b94ce 100644 --- a/Step.Utils/Step.Utils.csproj +++ b/Step.Utils/Step.Utils.csproj @@ -55,7 +55,6 @@ - @@ -88,7 +87,7 @@ - + Designer Always @@ -99,7 +98,7 @@ - {631375dd-06d3-49bb-8130-d9ddb34c429d} + {631375DD-06D3-49BB-8130-D9DDB34C429D} Step.Model diff --git a/Step/Controllers/SignalR/NcHub.cs b/Step/Controllers/SignalR/NcHub.cs index a8e027ff..d6fc1d29 100644 --- a/Step/Controllers/SignalR/NcHub.cs +++ b/Step/Controllers/SignalR/NcHub.cs @@ -1,10 +1,10 @@ using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.AspNet.SignalR; -using Step.Attributes; using Step.NC; using TeamDev.SDK.MVVM; using static Step.Utils.Constants; +using static Step.Config.ServerConfig; namespace Step.Controllers.SignalR { @@ -80,5 +80,31 @@ namespace Step.Controllers.SignalR MessageServices.Current.Publish(SHOW_MSG_UI, null, "Recovery Alarm. ID: " + id); } + + public void UserSoftKeyClicked(int id) + { + foreach (var softKey in SoftKeysConfig) + { + if(softKey.Type == SOFTKEY_TYPE.MULTIPLE) + { + foreach (var subkey in softKey.SubKeys) + { + if(subkey.Id == id) + { + // write + break; + } + } + } + else + { + if(softKey.Id == id) + { + // write + break; + } + } + } + } } } diff --git a/Step/Controllers/WebApi/ConfigurationController.cs b/Step/Controllers/WebApi/ConfigurationController.cs index 9ee6c385..81432aba 100644 --- a/Step/Controllers/WebApi/ConfigurationController.cs +++ b/Step/Controllers/WebApi/ConfigurationController.cs @@ -1,6 +1,9 @@ -using Step.Model.DTOModels; +using Step.Model.ConfigModels; +using Step.Model.DTOModels; +using System.Collections.Generic; using System.Web.Http; using static Step.Config.ServerConfig; +using static Step.Utils.Constants; namespace Step.Controllers.WebApi { @@ -38,5 +41,42 @@ namespace Step.Controllers.WebApi return Ok(clientConfiguration); } + + [Route("softKeys"), HttpGet] + public IHttpActionResult GetSoftKeysConfig() + { + Dictionary> output = new Dictionary>(); + foreach (var softkey in SoftKeysConfig) + { + // Check if category exists + if (!output.ContainsKey(softkey.Category)) + { + // Add category if not exits + output.Add(softkey.Category, new List< DTOSoftKeyConfigModel>()); + } + + // Create subkeys dictionary for group + Dictionary tmpSubKey = new Dictionary(); + if (softkey.Type == SOFTKEY_TYPE.MULTIPLE && softkey.SubKeys != null) + { + tmpSubKey = new Dictionary(); + foreach (var subkey in softkey.SubKeys) + { + tmpSubKey.Add(subkey.Id, subkey.Text); + } + } + // Add to the category the new softkey + output[softkey.Category].Add(new DTOSoftKeyConfigModel() + { + Id = softkey.Id, + Category = softkey.Category, + Type = softkey.Type, + SubKeys = tmpSubKey + }); + + } + + return Ok(output); + } } } \ No newline at end of file diff --git a/Step/Listeners/ListenersHandler.cs b/Step/Listeners/ListenersHandler.cs index bd8bcaf3..c1a7e23a 100644 --- a/Step/Listeners/ListenersHandler.cs +++ b/Step/Listeners/ListenersHandler.cs @@ -47,6 +47,11 @@ namespace Step.Listeners { SignalRListener.SendExpMaintenancesData(a); })); + infos.Add(MessageServices.Current.Subscribe(SEND_SOFT_KEYS_DATA, async (a, b) => + { + SignalRListener.SendSoftKeysData(a); + })); + infos.Add(MessageServices.Current.Subscribe(BROADCAST_DATA, async (a, b) => { diff --git a/Step/Listeners/SignalR/SignalRListener.cs b/Step/Listeners/SignalR/SignalRListener.cs index a3eb7c34..32852b6a 100644 --- a/Step/Listeners/SignalR/SignalRListener.cs +++ b/Step/Listeners/SignalR/SignalRListener.cs @@ -114,6 +114,11 @@ namespace Step.Listeners.SignalR } } + public static void SendSoftKeysData(object softKeys) + { + + } + private volatile static object _broadcastlock = new Object(); public static void BroadcastData() { diff --git a/Step/wwwroot/src/modules/alarms/alarm-item.vue b/Step/wwwroot/src/modules/alarms/alarm-item.vue index 3030ea9b..d0154e59 100644 --- a/Step/wwwroot/src/modules/alarms/alarm-item.vue +++ b/Step/wwwroot/src/modules/alarms/alarm-item.vue @@ -5,7 +5,7 @@
{{source}} {{processid}} - +