diff --git a/Libs/CMS_CORE_Library.dll b/Libs/CMS_CORE_Library.dll index c778d9ea..9ce6e716 100644 Binary files a/Libs/CMS_CORE_Library.dll and b/Libs/CMS_CORE_Library.dll differ diff --git a/Step.Config/Config/softKeyConfig.xml b/Step.Config/Config/softKeyConfig.xml index dee64311..86df8f62 100644 --- a/Step.Config/Config/softKeyConfig.xml +++ b/Step.Config/Config/softKeyConfig.xml @@ -3,6 +3,7 @@ true 1 + false 1 Test @@ -12,6 +13,7 @@ true 1 + false Test Ita @@ -24,6 +26,7 @@ false 2 + false Test Ita @@ -36,6 +39,7 @@ true 2 + false Test Ita @@ -48,6 +52,7 @@ true 1 + true 1 Test diff --git a/Step.Config/Config/softKeyConfigValidator.xsd b/Step.Config/Config/softKeyConfigValidator.xsd index d6caca09..a50175d1 100644 --- a/Step.Config/Config/softKeyConfigValidator.xsd +++ b/Step.Config/Config/softKeyConfigValidator.xsd @@ -30,6 +30,7 @@ + @@ -61,6 +62,7 @@ + @@ -78,6 +80,7 @@ + diff --git a/Step.Config/ServerConfigController.cs b/Step.Config/ServerConfigController.cs index 88c94071..508f2aae 100644 --- a/Step.Config/ServerConfigController.cs +++ b/Step.Config/ServerConfigController.cs @@ -78,6 +78,7 @@ namespace Step.Config // Get SoftKeys xmlConfigFile = GetXmlHandlerWithValidator(SOFT_KEY_CONFIG_SCHEMA_PATH, SOFT_KEY_CONFIG_PATH); int id = 1; + SoftKeysConfig = xmlConfigFile .Root .Elements() @@ -92,13 +93,14 @@ namespace Step.Config y => y.Attribute("langKey").Value, y => y.Value ), - SubKeys = x.Element("plcKeys")?.Elements().Select(y => new SubKeysModel() + SubKeys = x.Element("plcKeys")?.Elements().Select(y => new SubKeysModel() // Populate subkeys if exist { Id = id++, PlcId = Convert.ToInt32(y.Attribute("plcId").Value), Text = y.Value }).ToList(), - Type = GetSoftKeyType(x.Name.ToString()) + Type = GetSoftKeyType(x.Name.ToString()), + OperatorConfirmationNeeded = Convert.ToBoolean(x.Element("operatorConfirmationNeeded").Value) }) .ToList(); } @@ -128,7 +130,7 @@ namespace Step.Config switch (type) { case "procedure": return SOFTKEY_TYPE.PROCEDURE; - case "group": return SOFTKEY_TYPE.MULTIPLE; + case "group": return SOFTKEY_TYPE.GROUP; default: return SOFTKEY_TYPE.SOFTKEY; } } diff --git a/Step.Model/ConfigModels/SoftKeyConfigModel.cs b/Step.Model/ConfigModels/SoftKeyConfigModel.cs index 2b421290..54a5bf6a 100644 --- a/Step.Model/ConfigModels/SoftKeyConfigModel.cs +++ b/Step.Model/ConfigModels/SoftKeyConfigModel.cs @@ -9,6 +9,7 @@ namespace Step.Model.ConfigModels public Dictionary LocalizedNames { get; set; } public int Category { get; set; } public bool IsActive { get; set; } + public bool OperatorConfirmationNeeded { get; set; } public List SubKeys { get; set; } public int PlcId { get; set; } public SOFTKEY_TYPE Type { get; set; } diff --git a/Step.Model/Constants.cs b/Step.Model/Constants.cs index 5238ee32..574966db 100644 --- a/Step.Model/Constants.cs +++ b/Step.Model/Constants.cs @@ -24,7 +24,7 @@ namespace Step.Utils { SOFTKEY = 0, PROCEDURE = 1, - MULTIPLE = 2 + GROUP = 2 } public static class NC_VENDOR diff --git a/Step.Model/DTOModels/DTOSoftKeyModel.cs b/Step.Model/DTOModels/DTOSoftKeyModel.cs index a4dfaf19..c2e3072e 100644 --- a/Step.Model/DTOModels/DTOSoftKeyModel.cs +++ b/Step.Model/DTOModels/DTOSoftKeyModel.cs @@ -11,6 +11,7 @@ namespace Step.Model.DTOModels { public int Id { get; set; } public int Category { get; set; } + public bool OperatorConfirmationNeeded { get; set; } public SOFTKEY_TYPE Type { get; set; } public Dictionary SubKeys { get; set; } } @@ -21,5 +22,24 @@ namespace Step.Model.DTOModels public int Category { get; set; } public bool Active { get; set; } public bool Value { get; set; } + + public override bool Equals(object obj) + { + var item = obj as DTOSoftKeyModel; + + if (Id != item.Id) + return false; + if (Active != item.Active) + return false; + if (Value != item.Value) + return false; + + return true; + } + + public override int GetHashCode() + { + return base.GetHashCode(); + } } } diff --git a/Step.NC/NcHandler.cs b/Step.NC/NcHandler.cs index 13eb971d..8b348e15 100644 --- a/Step.NC/NcHandler.cs +++ b/Step.NC/NcHandler.cs @@ -455,11 +455,15 @@ namespace Step.NC foreach (var softKey in SoftKeysConfig) { - if(softKey.Type == SOFTKEY_TYPE.MULTIPLE) + // Check type of the selected softkey + if(softKey.Type == SOFTKEY_TYPE.GROUP) { + // Foreach subkey create a softkey foreach (var subkey in softKey.SubKeys) { + // Find plc value var plcSoftKey = plcSoftKeys.Find(x => x.Id == subkey.PlcId); + // Set data softKeys.Add(new DTOSoftKeyModel() { Id = subkey.Id, @@ -470,7 +474,8 @@ namespace Step.NC } } else - { + { + // Find plc value var plcSoftKey = plcSoftKeys.Find(x => x.Id == softKey.PlcId); softKeys.Add(new DTOSoftKeyModel() { @@ -485,6 +490,14 @@ namespace Step.NC return cmsError; } + public CmsError PutSoftKeyValue(uint id) + { + // Write softkey pression to plc + CmsError cmsError = numericalControl.PLC_WSoftKey(id); + + return cmsError; + } + public CmsError RefreshAllAlarms() { return new CmsError(0, ""); diff --git a/Step.Tasks/ThreadsFunctions.cs b/Step.Tasks/ThreadsFunctions.cs index ce34619a..0e8e9c54 100644 --- a/Step.Tasks/ThreadsFunctions.cs +++ b/Step.Tasks/ThreadsFunctions.cs @@ -261,7 +261,7 @@ public static class ThreadsFunctions if (ncHandler.numericalControl.NC_IsConnected()) { - // Get Data from database and PLC + // Get Data from config and PLC libraryError = ncHandler.GetSoftKeys(out List softKeys); if (libraryError.errorCode != 0) ManageLibraryError(libraryError); diff --git a/Step/Controllers/SignalR/NcHub.cs b/Step/Controllers/SignalR/NcHub.cs index d6fc1d29..f68fdb6c 100644 --- a/Step/Controllers/SignalR/NcHub.cs +++ b/Step/Controllers/SignalR/NcHub.cs @@ -83,25 +83,33 @@ namespace Step.Controllers.SignalR public void UserSoftKeyClicked(int id) { - foreach (var softKey in SoftKeysConfig) + using (NcHandler ncHandler = new NcHandler()) { - if(softKey.Type == SOFTKEY_TYPE.MULTIPLE) + ncHandler.Connect(); + foreach (var softKey in SoftKeysConfig) { - foreach (var subkey in softKey.SubKeys) + // Check softKey type + if (softKey.Type == SOFTKEY_TYPE.GROUP) { - if(subkey.Id == id) + // Find in the subkeys + foreach (var subkey in softKey.SubKeys) { - // write - break; + if (subkey.Id == id) + { + // Write click button + ncHandler.PutSoftKeyValue((uint)softKey.PlcId); + break; + } } } - } - else - { - if(softKey.Id == id) + else { - // write - break; + if (softKey.Id == id) + { + // Write click button + ncHandler.PutSoftKeyValue((uint)softKey.PlcId); + break; + } } } } diff --git a/Step/Controllers/WebApi/ConfigurationController.cs b/Step/Controllers/WebApi/ConfigurationController.cs index 81432aba..fdeffa2a 100644 --- a/Step/Controllers/WebApi/ConfigurationController.cs +++ b/Step/Controllers/WebApi/ConfigurationController.cs @@ -57,7 +57,7 @@ namespace Step.Controllers.WebApi // Create subkeys dictionary for group Dictionary tmpSubKey = new Dictionary(); - if (softkey.Type == SOFTKEY_TYPE.MULTIPLE && softkey.SubKeys != null) + if (softkey.Type == SOFTKEY_TYPE.GROUP && softkey.SubKeys != null) { tmpSubKey = new Dictionary(); foreach (var subkey in softkey.SubKeys) @@ -70,6 +70,7 @@ namespace Step.Controllers.WebApi { Id = softkey.Id, Category = softkey.Category, + OperatorConfirmationNeeded = softkey.OperatorConfirmationNeeded, Type = softkey.Type, SubKeys = tmpSubKey }); diff --git a/Step/Listeners/SignalR/SignalRListener.cs b/Step/Listeners/SignalR/SignalRListener.cs index 32852b6a..01506873 100644 --- a/Step/Listeners/SignalR/SignalRListener.cs +++ b/Step/Listeners/SignalR/SignalRListener.cs @@ -17,6 +17,8 @@ namespace Step.Listeners.SignalR private static List LastExpiredMaintenances = new List(); private static DTOPowerOnDataModel LastPowerOnData = new DTOPowerOnDataModel(); private static DTOProcessDataModel LastProcessesData = new DTOProcessDataModel(); + private static List LastSoftKeysData = new List(); + private static bool LastIsNcConnected = false; public static void SendAlarmsToClient(DTOAlarmsModel newAlarmsData) @@ -116,7 +118,15 @@ namespace Step.Listeners.SignalR public static void SendSoftKeysData(object softKeys) { + var context = GlobalHost.ConnectionManager.GetHubContext(); + List newData = softKeys as List; + if (newData.Count != LastSoftKeysData.Count || !LastSoftKeysData.All(newData.Contains)) + { + LastSoftKeysData = newData; + // Send data to clients + context.Clients.Group("ncData").softKeys(softKeys); + } } private volatile static object _broadcastlock = new Object();