diff --git a/Libs/CMS_CORE_Library.dll b/Libs/CMS_CORE_Library.dll index 3ee70c99..bff844fc 100644 Binary files a/Libs/CMS_CORE_Library.dll and b/Libs/CMS_CORE_Library.dll differ diff --git a/Step.Model/Constants.cs b/Step.Model/Constants.cs index a2e7cbe7..7d7855b5 100644 --- a/Step.Model/Constants.cs +++ b/Step.Model/Constants.cs @@ -123,6 +123,7 @@ namespace Step.Model public const string SEND_USER_SOFTKEYS_DATA = "SEND_USER_SOFTKEYS_DATA"; public const string SEND_NC_SOFTKEYS_DATA = "SEND_NC_SOFTKEYS_DATA"; public const string SEND_HEADS_DATA = "SEND_HEADS_DATA"; + public const string SEND_AXIS_NAMES_DATA = "SEND_AXIS_NAMES_DATA"; public const string BROADCAST_DATA = "BROADCAST_DATA"; diff --git a/Step.Model/DTOModels/DTOAxisNameModel.cs b/Step.Model/DTOModels/DTOAxisNameModel.cs new file mode 100644 index 00000000..4df395f4 --- /dev/null +++ b/Step.Model/DTOModels/DTOAxisNameModel.cs @@ -0,0 +1,29 @@ +using static CMS_CORE_Library.DataStructures; + +namespace Step.Model.DTOModels +{ + public class DTOAxisNameModel : AxisModel + { + public override bool Equals(object obj) + { + var item = obj as DTOAxisNameModel; + + // Object is not a DTOAxisNameModel instance + if (item == null) + return false; + + if (item.Id != Id) + return false; + + if (item.Name != Name) + return false; + + return true; + } + + public override int GetHashCode() + { + return base.GetHashCode(); + } + } +} diff --git a/Step.Model/DTOModels/DTOProcessDataModel.cs b/Step.Model/DTOModels/DTOProcessDataModel.cs index 83e00793..c968e7d1 100644 --- a/Step.Model/DTOModels/DTOProcessDataModel.cs +++ b/Step.Model/DTOModels/DTOProcessDataModel.cs @@ -8,6 +8,7 @@ namespace Step.Model.DTOModels { public bool isRunning; public ushort selectedProcess; + public byte selectedAxis; public List processes; public DTOProcessDataModel() diff --git a/Step.Model/Step.Model.csproj b/Step.Model/Step.Model.csproj index 08cdf7a6..1512a2d1 100644 --- a/Step.Model/Step.Model.csproj +++ b/Step.Model/Step.Model.csproj @@ -82,6 +82,7 @@ + diff --git a/Step.NC/NcHandler.cs b/Step.NC/NcHandler.cs index 30a9aeb5..a3e2eae9 100644 --- a/Step.NC/NcHandler.cs +++ b/Step.NC/NcHandler.cs @@ -9,7 +9,7 @@ using Step.Model.DTOModels; using System; using System.Collections.Generic; using System.Globalization; -using static CMS_CORE.Nc; +using System.Linq; using static CMS_CORE_Library.DataStructures; using static Step.Config.ServerConfig; using static Step.Model.Constants; @@ -304,6 +304,10 @@ namespace Step.NC // Read selected process cmsError = numericalControl.PROC_RSelectedProcess(ref processesData.selectedProcess); + if (cmsError.IsError()) + return cmsError; + // Read selected axes + cmsError = numericalControl.AXES_RSelectedAxis(ref processesData.selectedAxis); return cmsError; } @@ -487,6 +491,7 @@ namespace Step.NC return cmsError; } + public CmsError GetNcSoftKeys(out List ncSoftKeys) { ncSoftKeys = new List(); @@ -501,8 +506,8 @@ namespace Step.NC { // Find the plc matching data var plcSoftKey = plcSoftKeys.Find(x => x.Id == softKey.Id); - - // Create and add Nc softkey model + + // Create and add Nc softkey model ncSoftKeys.Add(new DTONcSoftKeyModel() { Id = softKey.Id, @@ -527,7 +532,7 @@ namespace Step.NC if (cmsError.IsError()) return cmsError; - foreach(var head in plcHeads) + foreach (var head in plcHeads) { // Get current head config var configuredHead = HeadsConfig.Find(x => x.Id == head.Id); @@ -551,6 +556,7 @@ namespace Step.NC }); } break; + case HEAD_TYPE.AWJ: { heads.Add(new DTOAbrasiveWaterJet() @@ -568,6 +574,7 @@ namespace Step.NC }); } break; + case HEAD_TYPE.WJ: { heads.Add(new DTOHeadModel() @@ -588,6 +595,27 @@ namespace Step.NC return cmsError; } + public CmsError ReadAxisData(out List axesNames) + { + axesNames = new List(); + List plcAxes = new List(); + // Read selected process + ushort selectedProcess = 0; + CmsError cmsError = numericalControl.PROC_RSelectedProcess(ref selectedProcess); + if (cmsError.IsError()) + return cmsError; + // Read axes names + cmsError = numericalControl.AXES_RAxesNames(selectedProcess, ref plcAxes); + + axesNames = plcAxes.Select(x => new DTOAxisNameModel() + { + Id = x.Id, + Name = x.Name + }).ToList(); + + return cmsError; + } + #endregion Read Data #region Write data @@ -613,6 +641,11 @@ namespace Step.NC return numericalControl.PROC_WSelectProcess(procNumber); } + public CmsError PutSelectAxis(byte axisId) + { + return numericalControl.AXES_WSelectAxis(axisId); + } + public CmsError PutOverride(uint id, string action) { HEAD_OVERRIDE_SIGN sign = HEAD_OVERRIDE_SIGN.MINUS; diff --git a/Step.Tasks/ThreadsFunctions.cs b/Step.Tasks/ThreadsFunctions.cs index 58be7a3e..25315f77 100644 --- a/Step.Tasks/ThreadsFunctions.cs +++ b/Step.Tasks/ThreadsFunctions.cs @@ -19,7 +19,8 @@ public static class ThreadsFunctions private static long ReadFunctionTimer = 0, ReadFunctionTimes = 0; private static long ReadMaintenanceTimer = 0, ReadMaintenanceTimes = 0; private static long ReadUserSoftKeysTimer = 0, ReadUserSoftKeysTimes = 0; - private static long ReadNcSoftKeysTimer = 0, ReadNcSoftKeysTimes = 0; + private static long ReadAxesNamesTimer = 0, ReadAxesNamesTimes = 0; + private static long ReadHeadsTimer = 0, ReadHeadsTimes = 0; private static Thread ConnThread; @@ -135,8 +136,19 @@ public static class ThreadsFunctions if (libraryError.errorCode != 0) ManageLibraryError(libraryError); else - // Send through signalR - MessageServices.Current.Publish(SEND_PROCESSES_DATA, null, processesPPData); + { + // Get softkey data from config and PLC + libraryError = ncHandler.GetNcSoftKeys(out List ncSoftKeys); + if (libraryError.errorCode != 0) + ManageLibraryError(libraryError); + else + { + // Send processes through signalR + MessageServices.Current.Publish(SEND_PROCESSES_DATA, null, processesPPData); + // Send ncSoftKeys through signalR + MessageServices.Current.Publish(SEND_NC_SOFTKEYS_DATA, null, ncSoftKeys); + } + } } else TryNcConnection(); @@ -292,50 +304,50 @@ public static class ThreadsFunctions } } - public static void ReadNcSoftKeysData() - { - NcHandler ncHandler = new NcHandler(); - Stopwatch sw = new Stopwatch(); + //public static void ReadNcSoftKeysData() + //{ + // NcHandler ncHandler = new NcHandler(); + // Stopwatch sw = new Stopwatch(); - try - { - // Try connection - CmsError libraryError = ncHandler.Connect(); - if (libraryError.errorCode != 0) - ManageLibraryError(libraryError); + // try + // { + // // Try connection + // CmsError libraryError = ncHandler.Connect(); + // if (libraryError.errorCode != 0) + // ManageLibraryError(libraryError); - while (true) - { - sw.Restart(); + // while (true) + // { + // sw.Restart(); - if (ncHandler.numericalControl.NC_IsConnected()) - { - // Get softkey data from config and PLC - libraryError = ncHandler.GetNcSoftKeys(out List ncSoftKeys); - if (libraryError.errorCode != 0) - ManageLibraryError(libraryError); - else - // Send through signalR - MessageServices.Current.Publish(SEND_NC_SOFTKEYS_DATA, null, ncSoftKeys); - } - else - TryNcConnection(); + // if (ncHandler.numericalControl.NC_IsConnected()) + // { + // // Get softkey data from config and PLC + // libraryError = ncHandler.GetNcSoftKeys(out List ncSoftKeys); + // if (libraryError.errorCode != 0) + // ManageLibraryError(libraryError); + // else + // // Send through signalR + // MessageServices.Current.Publish(SEND_NC_SOFTKEYS_DATA, null, ncSoftKeys); + // } + // else + // TryNcConnection(); - sw.Stop(); + // sw.Stop(); - // Update thread timer - ReadUserSoftKeysTimer += sw.ElapsedMilliseconds; - ReadUserSoftKeysTimes++; + // // Update thread timer + // ReadUserSoftKeysTimer += sw.ElapsedMilliseconds; + // ReadUserSoftKeysTimes++; - // Wait - Thread.Sleep(200); - } - } - catch (ThreadAbortException) - { - ncHandler.Dispose(); - } - } + // // Wait + // Thread.Sleep(200); + // } + // } + // catch (ThreadAbortException) + // { + // ncHandler.Dispose(); + // } + //} public static void ReadHeadsData() { @@ -367,10 +379,10 @@ public static class ThreadsFunctions TryNcConnection(); sw.Stop(); - + //Update thread timer - ReadNcSoftKeysTimer += sw.ElapsedMilliseconds; - ReadNcSoftKeysTimes++; + ReadHeadsTimer += sw.ElapsedMilliseconds; + ReadHeadsTimes++; // Wait Thread.Sleep(500); @@ -382,6 +394,51 @@ public static class ThreadsFunctions } } + public static void ReadAxesNamesData() + { + 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 config and PLC + libraryError = ncHandler.ReadAxisData(out List axes); + if (libraryError.errorCode != 0) + ManageLibraryError(libraryError); + else + // Send through signalR + MessageServices.Current.Publish(SEND_AXIS_NAMES_DATA, null, axes); + } + else + TryNcConnection(); + + sw.Stop(); + + //Update thread timer + ReadAxesNamesTimer += sw.ElapsedMilliseconds; + ReadAxesNamesTimes++; + + // Wait + Thread.Sleep(800); + } + } + catch (ThreadAbortException) + { + ncHandler.Dispose(); + } + } + #endregion Nc Threads #region SupportFunctions @@ -529,12 +586,24 @@ public static class ThreadsFunctions ReadUserSoftKeysTimer = 0; ReadUserSoftKeysTimes = 0; } - if (ThreadsHandler.RunningThreadStatus.ContainsKey("ReadNcSoftKeysData") && ReadNcSoftKeysTimes != 0) + if (ThreadsHandler.RunningThreadStatus.ContainsKey("ReadHeadsData") && ReadHeadsTimes != 0) { - ThreadsHandler.RunningThreadStatus["ReadNcSoftKeysData"] = (ReadNcSoftKeysTimer / ReadNcSoftKeysTimes) + " mS"; - ReadNcSoftKeysTimer = 0; - ReadNcSoftKeysTimes = 0; + ThreadsHandler.RunningThreadStatus["ReadHeadsData"] = (ReadHeadsTimer / ReadHeadsTimes) + " mS"; + ReadHeadsTimer = 0; + ReadHeadsTimes = 0; } + if (ThreadsHandler.RunningThreadStatus.ContainsKey("ReadAxesNamesData") && ReadAxesNamesTimer != 0) + { + ThreadsHandler.RunningThreadStatus["ReadAxesNamesData"] = (ReadAxesNamesTimer / ReadAxesNamesTimes) + " mS"; + ReadAxesNamesTimer = 0; + ReadAxesNamesTimes = 0; + } + //if (ThreadsHandler.RunningThreadStatus.ContainsKey("ReadNcSoftKeysData") && ReadNcSoftKeysTimes != 0) + //{ + // ThreadsHandler.RunningThreadStatus["ReadNcSoftKeysData"] = (ReadNcSoftKeysTimer / ReadNcSoftKeysTimes) + " mS"; + // ReadNcSoftKeysTimer = 0; + // ReadNcSoftKeysTimes = 0; + //} MessageServices.Current.Publish(SEND_THREADS_STATUS, null, ThreadsHandler.RunningThreadStatus); @@ -554,6 +623,10 @@ public static class ThreadsFunctions ReadFunctionTimes = 0; ReadMaintenanceTimer = 0; ReadMaintenanceTimes = 0; + ReadHeadsTimer = 0; + ReadHeadsTimes = 0; + ReadAxesNamesTimer = 0; + ReadAxesNamesTimes = 0; } #endregion SupportFunctions diff --git a/Step.Tasks/ThreadsHandler.cs b/Step.Tasks/ThreadsHandler.cs index 74d4c5a0..1b6a5307 100644 --- a/Step.Tasks/ThreadsHandler.cs +++ b/Step.Tasks/ThreadsHandler.cs @@ -16,9 +16,10 @@ namespace Step.Core ThreadsFunctions.ReadProcessesPPStatus, ThreadsFunctions.ReadEnabledFunctionality, ThreadsFunctions.ReadExpiredMaintenances, - ThreadsFunctions.ReadNcSoftKeysData, + // ThreadsFunctions.ReadNcSoftKeysData, ThreadsFunctions.ReadUserSoftKeysData, - ThreadsFunctions.ReadHeadsData + ThreadsFunctions.ReadHeadsData, + ThreadsFunctions.ReadAxesNamesData }; private volatile static List RunningThreadsList = new List(); diff --git a/Step/Controllers/SignalR/NcHub.cs b/Step/Controllers/SignalR/NcHub.cs index 4a2d9af6..9635a98e 100644 --- a/Step/Controllers/SignalR/NcHub.cs +++ b/Step/Controllers/SignalR/NcHub.cs @@ -142,23 +142,39 @@ namespace Step.Controllers.SignalR { using (NcHandler ncHandler = new NcHandler()) { + // Connect the NC CmsError libraryError = ncHandler.Connect(); - + // Put value into memory libraryError = ncHandler.PutSelectProcess(procNumber); if (libraryError.IsError()) throw new HubException(libraryError.message); } } + public void SelectAxis(byte axisId) + { + using (NcHandler ncHandler = new NcHandler()) + { + // Connect the Nc + CmsError libraryError = ncHandler.Connect(); + // Put value into memory + libraryError = ncHandler.PutSelectAxis(axisId); + if (libraryError.IsError()) + throw new HubException(libraryError.message); + } + } + public void AddOverride(uint id) { using (NcHandler ncHandler = new NcHandler()) { + // Connect the Nc CmsError libraryError = ncHandler.Connect(); + + // Put value into memory + libraryError = ncHandler.PutOverride(id, "plus"); if (libraryError.IsError()) throw new HubException(libraryError.message); - - libraryError = ncHandler.PutOverride(id, "plus"); } } @@ -166,11 +182,13 @@ namespace Step.Controllers.SignalR { using (NcHandler ncHandler = new NcHandler()) { + // Connect the Nc CmsError libraryError = ncHandler.Connect(); + + // Put value into memory + libraryError = ncHandler.PutOverride(id, "minus"); if (libraryError.IsError()) throw new HubException(libraryError.message); - - libraryError = ncHandler.PutOverride(id, "minus"); } } } diff --git a/Step/Listeners/ListenersHandler.cs b/Step/Listeners/ListenersHandler.cs index bbb86207..0db77af7 100644 --- a/Step/Listeners/ListenersHandler.cs +++ b/Step/Listeners/ListenersHandler.cs @@ -59,6 +59,10 @@ namespace Step.Listeners { SignalRListener.SendHeadsData(a); })); + infos.Add(MessageServices.Current.Subscribe(SEND_AXIS_NAMES_DATA, async (a, b) => + { + SignalRListener.SendAxesNamesData(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 92d7eb54..5dff0b5a 100644 --- a/Step/Listeners/SignalR/SignalRListener.cs +++ b/Step/Listeners/SignalR/SignalRListener.cs @@ -20,6 +20,7 @@ namespace Step.Listeners.SignalR private static List LastUserSoftKeysData = new List(); private static List LastNcSoftKeysData = new List(); private static List LastHeadsData = new List(); + private static List LastAxesNamesData = new List(); private static bool LastIsNcConnected = false; @@ -157,7 +158,21 @@ namespace Step.Listeners.SignalR { LastHeadsData = newData; // Send data to clients - context.Clients.Group("ncData").heads(heads); + context.Clients.Group("ncData").headsData(heads); + } + } + + public static void SendAxesNamesData(object axesNames) + { + var context = GlobalHost.ConnectionManager.GetHubContext(); + List newData = axesNames as List; + + // Check if collections are equals + if (newData.Count != LastAxesNamesData.Count || !LastAxesNamesData.All(newData.Contains)) + { + LastAxesNamesData = newData; + // Send data to clients + context.Clients.Group("ncData").axesNames(axesNames); } } @@ -192,12 +207,15 @@ namespace Step.Listeners.SignalR { connected = LastIsNcConnected }); - // Send softkeys - context.Clients.Group("ncData").ncSoftKeys(LastNcSoftKeysData); + // Send softkeys Nc + context.Clients.Group("ncData").ncSoftKeys(LastNcSoftKeysData); + // Send user softKeys context.Clients.Group("ncData").userSoftKeys(LastUserSoftKeysData); // Send heads data context.Clients.Group("ncData").heads(LastHeadsData); + // Send axesNames data + context.Clients.Group("ncData").axesNames(LastAxesNamesData); Debug.WriteLine(string.Format("{0} {1} Broadcast..completed", DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss"), DateTime.Now.Millisecond)); Monitor.Exit(_broadcastlock);