diff --git a/Libs/CMS_CORE_Library.dll b/Libs/CMS_CORE_Library.dll index 53f92c11..ff4184ab 100644 Binary files a/Libs/CMS_CORE_Library.dll and b/Libs/CMS_CORE_Library.dll differ diff --git a/Step.Core/ThreadsFunctions.cs b/Step.Core/ThreadsFunctions.cs index 1bc2b278..4979a0ec 100644 --- a/Step.Core/ThreadsFunctions.cs +++ b/Step.Core/ThreadsFunctions.cs @@ -395,6 +395,51 @@ public static class ThreadsFunctions } } + public static void ReadAxesPositionsData() + { + 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 NC + libraryError = ncHandler.GetAxesPositionsBySelectedProcess(out DTOAxesModel axesPositions); + if (libraryError.errorCode != 0) + ManageLibraryError(libraryError); + else + // Send through signalR + MessageServices.Current.Publish(SEND_AXES, null, axesPositions); + } + else + TryNcConnection(); + + sw.Stop(); + + //Update thread timer + ReadAxesTimer += sw.ElapsedMilliseconds; + ReadAxesTimes++; + + // Wait + Thread.Sleep(CalcSleepTime(200, (int)sw.ElapsedMilliseconds)); + } + } + catch (ThreadAbortException) + { + ncHandler.Dispose(); + } + } + public static void ReadMagazinesStatus() { NcHandler ncHandler = new NcHandler(); diff --git a/Step.Core/ThreadsHandler.cs b/Step.Core/ThreadsHandler.cs index e0af5714..109d0516 100644 --- a/Step.Core/ThreadsHandler.cs +++ b/Step.Core/ThreadsHandler.cs @@ -16,11 +16,13 @@ namespace Step.Core ThreadsFunctions.ReadProcessesPPStatus, ThreadsFunctions.ReadEnabledFunctionality, ThreadsFunctions.ReadExpiredMaintenances, - // ThreadsFunctions.ReadNcSoftKeysData, + ThreadsFunctions.ReadAxesPositionsData, ThreadsFunctions.ReadMagazinesStatus, ThreadsFunctions.ReadUserSoftKeysData, ThreadsFunctions.ReadHeadsData, ThreadsFunctions.ReadAxesNamesData + + // ThreadsFunctions.ReadNcSoftKeysData, }; private volatile static List RunningThreadsList = new List(); diff --git a/Step.Model/DTOModels/DTOAxesModel.cs b/Step.Model/DTOModels/DTOAxesModel.cs index 20678057..11d758ad 100644 --- a/Step.Model/DTOModels/DTOAxesModel.cs +++ b/Step.Model/DTOModels/DTOAxesModel.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Linq; namespace Step.Model.DTOModels { @@ -31,7 +32,18 @@ namespace Step.Model.DTOModels if (item == null) return false; - return base.Equals(obj); + if (!interpolated.SequenceEqual(item.interpolated)) + return false; + if (!machine.SequenceEqual(item.machine)) + return false; + if (!programmePos.SequenceEqual(item.programmePos)) + return false; + if (!toGo.SequenceEqual(item.toGo)) + return false; + if (!followingErr.SequenceEqual(item.followingErr)) + return false; + + return true; } public override int GetHashCode() diff --git a/Step.NC/NcHandler.cs b/Step.NC/NcHandler.cs index ca4bae85..26015025 100644 --- a/Step.NC/NcHandler.cs +++ b/Step.NC/NcHandler.cs @@ -233,6 +233,22 @@ namespace Step.NC return cmsError; } + public CmsError GetAxesPositionsBySelectedProcess(out DTOAxesModel axes) + { + axes = new DTOAxesModel(); + + // Get selectedProcess process number + ushort selectedProcess = 0; + CmsError cmsError = numericalControl.PROC_RSelectedProcess(ref selectedProcess); + if (cmsError.IsError()) + return cmsError; + + if(selectedProcess > 0) + cmsError = GetAxesPositionsByProcess(selectedProcess, out axes); + + return cmsError; + } + public CmsError GetAxesPositionsByProcess(ushort processNum, out DTOAxesModel axes) { axes = new DTOAxesModel(); diff --git a/Step/Listeners/ListenersHandler.cs b/Step/Listeners/ListenersHandler.cs index dbf4188e..0cad27ad 100644 --- a/Step/Listeners/ListenersHandler.cs +++ b/Step/Listeners/ListenersHandler.cs @@ -63,6 +63,11 @@ namespace Step.Listeners { SignalRListener.SendAxesNamesData(a); })); + infos.Add(MessageServices.Current.Subscribe(SEND_AXES, async (a, b) => + { + SignalRListener.SendAxesToClient(a); + })); + infos.Add(MessageServices.Current.Subscribe(SEND_MAGAZINES_STATUS, async (a, b) => { SignalRListener.SendMagazinesStatus(a); diff --git a/Step/Listeners/SignalR/SignalRListener.cs b/Step/Listeners/SignalR/SignalRListener.cs index f8dbdcc1..711f9628 100644 --- a/Step/Listeners/SignalR/SignalRListener.cs +++ b/Step/Listeners/SignalR/SignalRListener.cs @@ -21,6 +21,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 DTOAxesModel LastAxesPositions = new DTOAxesModel(); private static List LastAxesNamesData = new List(); private static DTOMagazineActionModel LastMagazineStatus = new DTOMagazineActionModel(); @@ -39,6 +40,17 @@ namespace Step.Listeners.SignalR } } + public static void SendAxesToClient(object newAxesData) + { + if (!LastAxesPositions.Equals(newAxesData)) + { + var context = GlobalHost.ConnectionManager.GetHubContext(); + LastAxesPositions = newAxesData as DTOAxesModel; + + context.Clients.Group("ncData").axesPositions(newAxesData); + } + } + public static void SendPowerOnDataToClient(object powerOnData) { var context = GlobalHost.ConnectionManager.GetHubContext();