diff --git a/Libs/CMS_CORE_Library.dll b/Libs/CMS_CORE_Library.dll index 06754a05..0ecc73ec 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 bbae70cc..214086c3 100644 --- a/Step.Core/ThreadsFunctions.cs +++ b/Step.Core/ThreadsFunctions.cs @@ -1,5 +1,6 @@ using Step.Core; using Step.Model.DTOModels; +using Step.Model.DTOModels.ToolModels; using Step.NC; using System.Collections.Generic; using System.Diagnostics; @@ -24,7 +25,7 @@ public static class ThreadsFunctions private static Thread ConnThread; - #region Nc Threads + #region Nc functions threads public static void ReadAlarms() { @@ -394,7 +395,51 @@ public static class ThreadsFunctions } } - #endregion Nc Threads + public static void ReadMagazinesStatus() + { + 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.GetMagazineStatus(out DTOMagazineActionModel magazineStatus); + if (libraryError.errorCode != 0) + ManageLibraryError(libraryError); + else + // Send through signalR + MessageServices.Current.Publish(SEND_MAGAZINES_STATUS, null, magazineStatus); + } + else + TryNcConnection(); + + sw.Stop(); + + //Update thread timer + ReadAxesNamesTimer += sw.ElapsedMilliseconds; + ReadAxesNamesTimes++; + + // Wait + Thread.Sleep(CalcSleepTime(200, (int)sw.ElapsedMilliseconds)); + } + } + catch (ThreadAbortException) + { + ncHandler.Dispose(); + } + } + #endregion Nc threads #region SupportFunctions @@ -582,7 +627,7 @@ public static class ThreadsFunctions { int sleep = 0; // Check if the execution time is greater than the half of the max sleep time - if ( maxSleep - execTime < maxSleep / 2 ) + if (maxSleep - execTime < maxSleep / 2) { sleep = maxSleep; } @@ -593,51 +638,6 @@ public static class ThreadsFunctions return sleep; } + #endregion SupportFunctions -} - - -//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); - -// 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(); - -// sw.Stop(); - -// // Update thread timer -// ReadUserSoftKeysTimer += sw.ElapsedMilliseconds; -// ReadUserSoftKeysTimes++; - -// // Wait -// Thread.Sleep(200); -// } -// } -// catch (ThreadAbortException) -// { -// ncHandler.Dispose(); -// } -//} \ No newline at end of file +} \ No newline at end of file diff --git a/Step.Core/ThreadsHandler.cs b/Step.Core/ThreadsHandler.cs index 1b6a5307..e0af5714 100644 --- a/Step.Core/ThreadsHandler.cs +++ b/Step.Core/ThreadsHandler.cs @@ -17,6 +17,7 @@ namespace Step.Core ThreadsFunctions.ReadEnabledFunctionality, ThreadsFunctions.ReadExpiredMaintenances, // ThreadsFunctions.ReadNcSoftKeysData, + ThreadsFunctions.ReadMagazinesStatus, ThreadsFunctions.ReadUserSoftKeysData, ThreadsFunctions.ReadHeadsData, ThreadsFunctions.ReadAxesNamesData diff --git a/Step.Model/Constants.cs b/Step.Model/Constants.cs index 358e35fa..bc060ecc 100644 --- a/Step.Model/Constants.cs +++ b/Step.Model/Constants.cs @@ -124,6 +124,7 @@ namespace Step.Model 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 SEND_MAGAZINES_STATUS = "SEND_MAGAZINES_STATUS"; public const string BROADCAST_DATA = "BROADCAST_DATA"; diff --git a/Step.Model/Step.Model.csproj b/Step.Model/Step.Model.csproj index 0dafe074..30ff70fa 100644 --- a/Step.Model/Step.Model.csproj +++ b/Step.Model/Step.Model.csproj @@ -101,6 +101,7 @@ + diff --git a/Step.NC/NcHandler.cs b/Step.NC/NcHandler.cs index bdbab2d7..61cf5017 100644 --- a/Step.NC/NcHandler.cs +++ b/Step.NC/NcHandler.cs @@ -6,6 +6,7 @@ using CMS_CORE.Siemens; using Step.Database.Controllers; using Step.Model.DatabaseModels; using Step.Model.DTOModels; +using Step.Model.DTOModels.ToolModels; using System; using System.Collections.Generic; using System.Globalization; @@ -674,6 +675,22 @@ namespace Step.NC magazinesPositions = new List(); return numericalControl.TOOLS_RMagazinePositions(ref magazinesPositions); } + + public CmsError GetMagazineStatus(out DTOMagazineActionModel magazineStatus) + { + // Set up models + magazineStatus= new DTOMagazineActionModel(); + MagazineActionModel libModel = new MagazineActionModel(); + // Read status from NC + CmsError cmsError = numericalControl.TOOLS_GetMagazinesStatus(ref libModel); + if (cmsError.IsError()) + return cmsError; + + magazineStatus = (DTOMagazineActionModel)libModel; + + return cmsError; + } + #endregion Read Data #region Write data diff --git a/Step/Listeners/ListenersHandler.cs b/Step/Listeners/ListenersHandler.cs index 0db77af7..dbf4188e 100644 --- a/Step/Listeners/ListenersHandler.cs +++ b/Step/Listeners/ListenersHandler.cs @@ -63,6 +63,10 @@ namespace Step.Listeners { SignalRListener.SendAxesNamesData(a); })); + infos.Add(MessageServices.Current.Subscribe(SEND_MAGAZINES_STATUS, async (a, b) => + { + SignalRListener.SendMagazinesStatus(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 cd4a3d4c..f8dbdcc1 100644 --- a/Step/Listeners/SignalR/SignalRListener.cs +++ b/Step/Listeners/SignalR/SignalRListener.cs @@ -2,6 +2,7 @@ using Step.Config; using Step.Controllers.SignalR; using Step.Model.DTOModels; +using Step.Model.DTOModels.ToolModels; using System; using System.Collections.Generic; using System.Diagnostics; @@ -21,6 +22,7 @@ namespace Step.Listeners.SignalR private static List LastNcSoftKeysData = new List(); private static List LastHeadsData = new List(); private static List LastAxesNamesData = new List(); + private static DTOMagazineActionModel LastMagazineStatus = new DTOMagazineActionModel(); private static bool LastIsNcConnected = false; @@ -176,6 +178,17 @@ namespace Step.Listeners.SignalR } } + public static void SendMagazinesStatus(object magazinesStatus) + { + var context = GlobalHost.ConnectionManager.GetHubContext(); + if (!LastMagazineStatus.Equals(magazinesStatus)) + { + LastMagazineStatus = magazinesStatus as DTOMagazineActionModel; + + context.Clients.Group("ncData").magazinesStatus(magazinesStatus); + } + } + private volatile static object _broadcastlock = new Object(); public static void BroadcastData() @@ -210,12 +223,14 @@ namespace Step.Listeners.SignalR // Send softkeys Nc context.Clients.Group("ncData").ncSoftKeys(LastNcSoftKeysData); - // Send user softKeys + // Send user softKeys context.Clients.Group("ncData").userSoftKeys(LastUserSoftKeysData); // Send heads data context.Clients.Group("ncData").headsData(LastHeadsData); // Send axesNames data context.Clients.Group("ncData").axesNames(LastAxesNamesData); + // Send magazine status + context.Clients.Group("ncData").magazinesStatus(LastMagazineStatus); Debug.WriteLine(string.Format("{0} {1} Broadcast..completed", DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss"), DateTime.Now.Millisecond)); Monitor.Exit(_broadcastlock);