diff --git a/Libs/CMS_CORE_Library.dll b/Libs/CMS_CORE_Library.dll index f9e9f8df..d8a3e04d 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 d2269c3f..9faf1660 100644 --- a/Step.Core/ThreadsFunctions.cs +++ b/Step.Core/ThreadsFunctions.cs @@ -53,7 +53,7 @@ public static class ThreadsFunctions libraryError = ncHandler.ManageWatchdog(); } else - TryNcConnection(); + RestoreConnection(); sw.Stop(); @@ -97,7 +97,7 @@ public static class ThreadsFunctions MessageServices.Current.Publish(SEND_ALARMS, null, alarms); } else - TryNcConnection(); + RestoreConnection(); sw.Stop(); //Update thread timer @@ -140,7 +140,7 @@ public static class ThreadsFunctions MessageServices.Current.Publish(SEND_POWER_ON_DATA, null, powerOnData); } else - TryNcConnection(); + RestoreConnection(); sw.Stop(); // Update thread timer @@ -203,7 +203,7 @@ public static class ThreadsFunctions } } else - TryNcConnection(); + RestoreConnection(); sw.Stop(); @@ -248,7 +248,7 @@ public static class ThreadsFunctions MessageServices.Current.Publish(SEND_FUNCTIONALITY_DATA, null, functionsAccessList); } else - TryNcConnection(); + RestoreConnection(); sw.Stop(); @@ -293,7 +293,7 @@ public static class ThreadsFunctions MessageServices.Current.Publish(SEND_EXPIRED_MAINTENANCES_DATA, null, expiredMaintenances); } else - TryNcConnection(); + RestoreConnection(); sw.Stop(); @@ -338,7 +338,7 @@ public static class ThreadsFunctions MessageServices.Current.Publish(SEND_USER_SOFTKEYS_DATA, null, softKeys); } else - TryNcConnection(); + RestoreConnection(); sw.Stop(); @@ -383,7 +383,7 @@ public static class ThreadsFunctions MessageServices.Current.Publish(SEND_HEADS_DATA, null, heads); } else - TryNcConnection(); + RestoreConnection(); sw.Stop(); @@ -428,7 +428,7 @@ public static class ThreadsFunctions MessageServices.Current.Publish(SEND_AXIS_NAMES_DATA, null, axes); } else - TryNcConnection(); + RestoreConnection(); sw.Stop(); @@ -473,7 +473,7 @@ public static class ThreadsFunctions MessageServices.Current.Publish(SEND_AXES, null, axesPositions); } else - TryNcConnection(); + RestoreConnection(); sw.Stop(); @@ -518,7 +518,7 @@ public static class ThreadsFunctions MessageServices.Current.Publish(SEND_MAGAZINES_STATUS, null, magazineStatus); } else - TryNcConnection(); + RestoreConnection(); sw.Stop(); @@ -564,7 +564,7 @@ public static class ThreadsFunctions MessageServices.Current.Publish(SEND_ACTIVE_PROGRAM_DATA, null, active); } else - TryNcConnection(); + RestoreConnection(); sw.Stop(); @@ -614,7 +614,7 @@ public static class ThreadsFunctions }); } else - TryNcConnection(); + RestoreConnection(); sw.Stop(); //Update thread timer @@ -658,7 +658,7 @@ public static class ThreadsFunctions MessageServices.Current.Publish(NC_MAGAZINE_IS_ACTIVE, null, status); } else - TryNcConnection(); + RestoreConnection(); sw.Stop(); // Wait @@ -702,7 +702,7 @@ public static class ThreadsFunctions MessageServices.Current.Publish(SEND_QUEUE_DATA, null, queue); } else - TryNcConnection(); + RestoreConnection(); sw.Stop(); // Wait @@ -719,7 +719,7 @@ public static class ThreadsFunctions #region SupportFunctions - private static void WillReconnect() + private static void TryNcConnection() { // Stop all the NC threads ThreadsHandler.Stop(); @@ -747,7 +747,7 @@ public static class ThreadsFunctions reconnectionIsRunning = false; } - public static void TryNcConnection() + public static void RestoreConnection() { if (reconnectionIsRunning == false) { // Set thread as running state @@ -755,7 +755,7 @@ public static class ThreadsFunctions // Start reconnection thread ConnThread = new Thread(() => - WillReconnect() + TryNcConnection() ); ConnThread.Start(); @@ -777,7 +777,7 @@ public static class ThreadsFunctions break; case CMS_ERROR_CODES.NOT_CONNECTED: - TryNcConnection(); // If not connected try reconnection + RestoreConnection(); // If not connected try reconnection break; case CMS_ERROR_CODES.PROC_NOT_FOUND: @@ -789,7 +789,7 @@ public static class ThreadsFunctions case CMS_ERROR_CODES.SIEMENS_HMI_NOT_RUNNING: Manage(ERROR_LEVEL.WARNING, cmsError.localizationKey); - TryNcConnection(); // If not connected try reconnection + RestoreConnection(); // If not connected try reconnection break; } } diff --git a/Step.Core/ThreadsHandler.cs b/Step.Core/ThreadsHandler.cs index ccecf853..37c160b6 100644 --- a/Step.Core/ThreadsHandler.cs +++ b/Step.Core/ThreadsHandler.cs @@ -33,7 +33,7 @@ namespace Step.Core public static void Start() { - ThreadsFunctions.TryNcConnection(); + ThreadsFunctions.RestoreConnection(); } public static void StartWorkers() diff --git a/Step.NC/NcHandler.cs b/Step.NC/NcHandler.cs index e1fa7161..2168e46b 100644 --- a/Step.NC/NcHandler.cs +++ b/Step.NC/NcHandler.cs @@ -551,6 +551,100 @@ namespace Step.NC #region Read Data + #region Axes + + public CmsError GetAxesPositions(out List axes) + { + axes = new List(); + + // Get NC max process number + ushort maxProcNumber = 0; + CmsError cmsError = numericalControl.NC_RProcessesNum(ref maxProcNumber); + if (cmsError.errorCode != 0) + return cmsError; + + // For each process + for (ushort i = 1; i <= maxProcNumber; i++) + { + cmsError = GetAxesPositionsByProcess(i, out DTOAxesModel axis); + if (cmsError.errorCode != 0) + return cmsError; + + axes.Add(axis); + } + + 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(); + + CmsError cmsError = numericalControl.AXES_RInterpPosition(processNum, ref axes.interpolated); + if (cmsError.errorCode != 0) + return cmsError; + + cmsError = numericalControl.AXES_RMachinePosition(processNum, ref axes.machine); + if (cmsError.errorCode != 0) + return cmsError; + + cmsError = numericalControl.AXES_RProgrPosition(processNum, ref axes.programmePos); + if (cmsError.errorCode != 0) + return cmsError; + + cmsError = numericalControl.AXES_RDistanceToGo(processNum, ref axes.toGo); + if (cmsError.errorCode != 0) + return cmsError; + + //numericalControl.AXES_RFollowingError(1, ref axes.followingErr); + + 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; + + if (selectedProcess != 0) + { + // Read axes names + cmsError = numericalControl.AXES_RAxesNames(selectedProcess, ref plcAxes); + + axesNames = plcAxes.Select(x => new DTOAxisNameModel() + { + Id = x.Id, + Name = x.Name, + IsSelectable = x.IsSelectable + }).ToList(); + } + + return cmsError; + } + + #endregion + public CmsError ManageWatchdog() { return numericalControl.PLC_RWManageWatchdog(); @@ -699,71 +793,7 @@ namespace Step.NC return cmsError; } - - public CmsError GetAxesPositions(out List axes) - { - axes = new List(); - - // Get NC max process number - ushort maxProcNumber = 0; - CmsError cmsError = numericalControl.NC_RProcessesNum(ref maxProcNumber); - if (cmsError.errorCode != 0) - return cmsError; - - // For each process - for (ushort i = 1; i <= maxProcNumber; i++) - { - cmsError = GetAxesPositionsByProcess(i, out DTOAxesModel axis); - if (cmsError.errorCode != 0) - return cmsError; - - axes.Add(axis); - } - - 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(); - - CmsError cmsError = numericalControl.AXES_RInterpPosition(processNum, ref axes.interpolated); - if (cmsError.errorCode != 0) - return cmsError; - - cmsError = numericalControl.AXES_RMachinePosition(processNum, ref axes.machine); - if (cmsError.errorCode != 0) - return cmsError; - - cmsError = numericalControl.AXES_RProgrPosition(processNum, ref axes.programmePos); - if (cmsError.errorCode != 0) - return cmsError; - - cmsError = numericalControl.AXES_RDistanceToGo(processNum, ref axes.toGo); - if (cmsError.errorCode != 0) - return cmsError; - - //numericalControl.AXES_RFollowingError(1, ref axes.followingErr); - - return cmsError; - } - + public CmsError GetPowerOnData(out DTOPowerOnDataModel resultPowerOnData) { resultPowerOnData = new DTOPowerOnDataModel(); @@ -1301,33 +1331,109 @@ namespace Step.NC return cmsError; } - - public CmsError ReadAxisData(out List axesNames) + + public CmsError GetM155Data(out List data) { - axesNames = new List(); - List plcAxes = new List(); - // Read selected process - ushort selectedProcess = 0; - CmsError cmsError = numericalControl.PROC_RSelectedProcess(ref selectedProcess); + data = new List(); + List ncData = new List(); + CmsError cmsError = numericalControl.PLC_ROperatorInputIsNeeded(ref ncData); if (cmsError.IsError()) return cmsError; - if (selectedProcess != 0) + data = ncData.Select(x => new DTOM155InputModel() { - // Read axes names - cmsError = numericalControl.AXES_RAxesNames(selectedProcess, ref plcAxes); + Buttons = x.Buttons, + IsNeeded = x.IsNeeded, + Message = x.Message, + Process = x.Process, + Type = x.Type.ToString() + }).ToList(); - axesNames = plcAxes.Select(x => new DTOAxisNameModel() - { - Id = x.Id, - Name = x.Name, - IsSelectable = x.IsSelectable - }).ToList(); - } + return NO_ERROR; + } + + #endregion Read Data + + #region Write data + + public CmsError PutNcSoftKeyClick(uint id) + { + // Write Nc softkey press to plc + CmsError cmsError = numericalControl.PLC_WNcSoftKey(id); return cmsError; } + public CmsError PutUserSoftKeyClick(uint id) + { + // Write user softkey press to plc + return numericalControl.PLC_WUserSoftKey(id); + } + + public CmsError RefreshAlarm(uint id) + { + // Write in memory the request to refresh the alarm + return numericalControl.PLC_WRefreshMessage(id); + } + + public CmsError RestoreAlarm(uint id) + { + // Write in memory the request to restore the alarm + return numericalControl.PLC_WRestoreMessage(id); + } + + public CmsError RefreshAllAlarms() + { + return numericalControl.PLC_WRefreshAllMessages(); + } + + public CmsError PutSelectProcess(ushort procNumber) + { + 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; + if (action == "plus") + sign = HEAD_OVERRIDE_SIGN.PLUS; + + CmsError cmsError = numericalControl.PLC_WHeadOverride(id, sign); + return cmsError; + } + + public CmsError PutPowerOnData(uint id) + { + // Set to true power on data by id + return numericalControl.PLC_WPowerOnData(id, true); + } + + public CmsError SetActiveLanguage(CultureInfo language) + { + // Set to true power on data by id + return numericalControl.NC_WLanguage(language); + } + + public CmsError SetActiveScreen(short screen) + { + // Set to true power on data by id + return numericalControl.NC_SetScreenVisible((Nc.SCREEN_PAGE)screen); + } + + public CmsError WriteM155Data(int process, double responseValue) + { + return numericalControl.PLC_WOperatorInputResponse(process, responseValue); + } + + #endregion Write data + + #region Siemens Tools + public CmsError GetToolTableConfiguration(out ToolTableConfiguration config) { config = new ToolTableConfiguration(); @@ -1442,108 +1548,6 @@ namespace Step.NC return cmsError; } - public CmsError GetM155Data(out List data) - { - data = new List(); - List ncData = new List(); - CmsError cmsError = numericalControl.PLC_ROperatorInputIsNeeded(ref ncData); - if (cmsError.IsError()) - return cmsError; - - data = ncData.Select(x => new DTOM155InputModel() - { - Buttons = x.Buttons, - IsNeeded = x.IsNeeded, - Message = x.Message, - Process = x.Process, - Type = x.Type.ToString() - }).ToList(); - - return NO_ERROR; - } - - #endregion Read Data - - #region Write data - - public CmsError PutNcSoftKeyClick(uint id) - { - // Write Nc softkey press to plc - CmsError cmsError = numericalControl.PLC_WNcSoftKey(id); - - return cmsError; - } - - public CmsError PutUserSoftKeyClick(uint id) - { - // Write user softkey press to plc - return numericalControl.PLC_WUserSoftKey(id); - } - - public CmsError RefreshAlarm(uint id) - { - // Write in memory the request to refresh the alarm - return numericalControl.PLC_WRefreshMessage(id); - } - - public CmsError RestoreAlarm(uint id) - { - // Write in memory the request to restore the alarm - return numericalControl.PLC_WRestoreMessage(id); - } - - public CmsError RefreshAllAlarms() - { - return numericalControl.PLC_WRefreshAllMessages(); - } - - public CmsError PutSelectProcess(ushort procNumber) - { - 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; - if (action == "plus") - sign = HEAD_OVERRIDE_SIGN.PLUS; - - CmsError cmsError = numericalControl.PLC_WHeadOverride(id, sign); - return cmsError; - } - - public CmsError PutPowerOnData(uint id) - { - // Set to true power on data by id - return numericalControl.PLC_WPowerOnData(id, true); - } - - public CmsError SetActiveLanguage(CultureInfo language) - { - // Set to true power on data by id - return numericalControl.NC_WLanguage(language); - } - - public CmsError SetActiveScreen(short screen) - { - // Set to true power on data by id - return numericalControl.NC_SetScreenVisible((Nc.SCREEN_PAGE)screen); - } - - public CmsError WriteM155Data(int process, double responseValue) - { - return numericalControl.PLC_WOperatorInputResponse(process, responseValue); - } - - #endregion Write data - - #region Siemens Tools - public CmsError AddTool(ref SiemensToolModel tool) { return numericalControl.TOOLS_WAddTool(ref tool); @@ -1650,7 +1654,6 @@ namespace Step.NC #endregion Siemens Tools // OSAI FANUC - #region Osai/Fanuc Tools public CmsError GetToolsData(out List dtoTools) diff --git a/Step/Controllers/WebApi/NcToolManagerController.cs b/Step/Controllers/WebApi/NcToolManagerController.cs index 3ebb1871..f9a99f55 100644 --- a/Step/Controllers/WebApi/NcToolManagerController.cs +++ b/Step/Controllers/WebApi/NcToolManagerController.cs @@ -4,8 +4,10 @@ using Step.Model.DatabaseModels; using Step.Model.DTOModels.ToolModels; using Step.NC; using Step.Utils; +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; +using System.Diagnostics; using System.Linq; using System.Web.Http; using static Step.Config.ServerConfig; @@ -721,7 +723,10 @@ namespace Step.Controllers.WebApi { ncHandler.Connect(); + Stopwatch st = new Stopwatch(); + st.Restart(); CmsError cmsError = ncHandler.StopEditTooling(magazineId); + Console.WriteLine("TOOL TABLE WRITE TIME "+ st.ElapsedMilliseconds); if (cmsError.IsError()) return BadRequest(cmsError.localizationKey); diff --git a/Step/Listeners/Database/SignalRDatabaseHandler.cs b/Step/Listeners/Database/SignalRDatabaseHandler.cs index e59d61ef..07b8efbb 100644 --- a/Step/Listeners/Database/SignalRDatabaseHandler.cs +++ b/Step/Listeners/Database/SignalRDatabaseHandler.cs @@ -167,19 +167,23 @@ namespace Step.Listeners.Database using (SessionsController sessionsController = new SessionsController()) { // Loop through users active sessions - foreach (var session in sessionsController.FindMachineUserSession()) + List sessions = sessionsController.FindMachineUserSession(); + + // Foreach active sessions + foreach (var session in sessions) { // Loop through alarms foreach (var alarm in alarmNewOccurrences) { loggedUsers.Add(new AlarmUserModel() - { + { UserId = session.UserId, AlarmOccurrenceId = alarm.AlarmOccurrenceId }); } } } + // Check if there are logged users if (loggedUsers.Count() > 0) alarmController.InsertNewAlarmUser(loggedUsers);