diff --git a/Libs/CMS_CORE_Library.dll b/Libs/CMS_CORE_Library.dll index 86e61d20..53f853fc 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 ac5764e4..e9387132 100644 --- a/Step.Core/ThreadsFunctions.cs +++ b/Step.Core/ThreadsFunctions.cs @@ -641,7 +641,7 @@ public static class ThreadsFunctions if (ncHandler.numericalControl.NC_IsConnected()) { // Read data - libraryError = ncHandler.GetSelectedProcessQueue(out List queue); + libraryError = ncHandler.UpdateAndGetPPQueue(out List queue); if (libraryError.IsError()) ManageLibraryError(libraryError); diff --git a/Step.Model/Constants.cs b/Step.Model/Constants.cs index 618c74b8..578e4f7d 100644 --- a/Step.Model/Constants.cs +++ b/Step.Model/Constants.cs @@ -60,6 +60,14 @@ namespace Step.Model MACHINE_INTERVAL = 1, TIME_INTERVAL = 2 } + + public enum QUEUE_ITEM_STATUS + { + NOT_ACTIVE = 0, + RUNNING = 1, + WAITING_OPERATOR = 2, + FINISHED = 3 + } public static class NC_VENDOR { @@ -192,7 +200,6 @@ namespace Step.Model public const string OPTION_NOT_ACTIVE = "error_option_not_active"; } - // File paths public const string MAINTENANCE_ATTACHMENT_PATH = "C:\\CMS\\STEP\\attachment\\"; public const string TEMP_FILE = @"C:/CMS/STEP/tmp/pp/"; diff --git a/Step.Model/DTOModels/DTOQueueModel.cs b/Step.Model/DTOModels/DTOQueueModel.cs index e6e48d4c..4b0586b3 100644 --- a/Step.Model/DTOModels/DTOQueueModel.cs +++ b/Step.Model/DTOModels/DTOQueueModel.cs @@ -20,7 +20,7 @@ namespace Step.Model.DTOModels public string AbsolutePath { get; set; } - public QUEUE_STATUS Status { get; set; } + public QUEUE_ITEM_STATUS Status { get; set; } public override bool Equals(object obj) { diff --git a/Step.NC/NcHandler.cs b/Step.NC/NcHandler.cs index c8564784..51cb8fd0 100644 --- a/Step.NC/NcHandler.cs +++ b/Step.NC/NcHandler.cs @@ -149,17 +149,14 @@ namespace Step.NC return cmsError; } - public CmsError UploadPartProgram(string localPath, string fileName, out ActiveProgramDataModel programData) + public CmsError UploadPartProgram(string localPath, string fileName, out string newFilePath) { - programData = new ActiveProgramDataModel(); // Upload to NC - string newFilePath = ""; + newFilePath = ""; CmsError cmsError = numericalControl.FILES_UploadPartProgram(localPath, fileName, ref newFilePath); if (cmsError.IsError()) return cmsError; - programData.Path = newFilePath; - // Delete local file File.Delete(localPath + "\\" + fileName); @@ -169,20 +166,56 @@ namespace Step.NC public CmsError UploadPartProgramAndActivate(string localPath, string fileName, out ActiveProgramDataModel programData) { programData = new ActiveProgramDataModel(); + // Upload to NC - string newFilePath = ""; - CmsError cmsError = UploadPartProgram(localPath, fileName, out programData); + CmsError cmsError = UploadPartProgram(localPath, fileName, out string newFilePath); + if (cmsError.IsError()) + return cmsError; // Get selectedProcess id ushort selectedProcess = 0; cmsError = numericalControl.PROC_RSelectedProcess(ref selectedProcess); if (cmsError.IsError()) return cmsError; + // Activate updated program return numericalControl.FILES_WSetActiveProgram(selectedProcess, newFilePath, ref programData); } - public CmsError GetSelectedProcessQueue(out List queueList) + public CmsError UploadPartProgramAddToQueue(string localPath, string fileName, int reps, out DTOQueueModel queueItem) + { + queueItem = new DTOQueueModel(); + // Upload to NC + CmsError cmsError = UploadPartProgram(localPath, fileName, out string newFilePath); + + // Get selectedProcess id + ushort selectedProcess = 0; + cmsError = numericalControl.PROC_RSelectedProcess(ref selectedProcess); + if (cmsError.IsError()) + return cmsError; + + queueItem = new DTOQueueModel() + { + PartProgramName = fileName, + Reps = reps, + RemainingReps = reps, + AbsolutePath = newFilePath, + Status = QUEUE_ITEM_STATUS.NOT_ACTIVE + }; + + // Check if there is already a pp queue + if (!PartProgramQueue.ContainsKey(selectedProcess)) + PartProgramQueue.Add(selectedProcess, new List()); + + queueItem.Id = SupportFunctions.GetNextId(PartProgramQueue[selectedProcess].Select(x => x.Id)); + + // Add new process to + PartProgramQueue[selectedProcess].Add(queueItem); + + return cmsError; + } + + public CmsError UpdateAndGetPPQueue(out List queueList) { queueList = new List(); // Get selectedProcess id @@ -211,9 +244,12 @@ namespace Step.NC { // Set as finished actualItem.RemainingReps = 0; + actualItem.Status = QUEUE_ITEM_STATUS.FINISHED; if (PartProgramQueue[selectedProcess].ElementAtOrDefault(QueueRunningIndex + 1) != null) - // if next exist set next as current pp + // if next part program exists, set next pp as current pp QueueRunningIndex += 1; + + // Change part program } } } @@ -221,8 +257,18 @@ namespace Step.NC // Set status if (PartProgramQueue.ContainsKey(selectedProcess) && PartProgramQueue[selectedProcess].ElementAtOrDefault(QueueRunningIndex) != null) - PartProgramQueue[selectedProcess][QueueRunningIndex].Status = queueData.Status; + { + if (queueData.Status == QUEUE_STATUS.RUNNING || queueData.Status == QUEUE_STATUS.CLOSING) + PartProgramQueue[selectedProcess][QueueRunningIndex].Status = QUEUE_ITEM_STATUS.RUNNING; + if (queueData.Status == QUEUE_STATUS.NOT_ACTIVE) + PartProgramQueue[selectedProcess][QueueRunningIndex].Status = QUEUE_ITEM_STATUS.NOT_ACTIVE; + + if (queueData.Status == QUEUE_STATUS.WAITING_OPERATOR) + PartProgramQueue[selectedProcess][QueueRunningIndex].Status = QUEUE_ITEM_STATUS.WAITING_OPERATOR; + + } + return GetProcessQueue(selectedProcess, out queueList); } @@ -239,39 +285,6 @@ namespace Step.NC return NO_ERROR; } - public CmsError UploadPartProgramAddToQueue(string localPath, string fileName, int reps, out DTOQueueModel queueItem) - { - queueItem = new DTOQueueModel(); - // Upload to NC - CmsError cmsError = UploadPartProgram(localPath, fileName, out ActiveProgramDataModel programData); - - // Get selectedProcess id - ushort selectedProcess = 0; - cmsError = numericalControl.PROC_RSelectedProcess(ref selectedProcess); - if (cmsError.IsError()) - return cmsError; - - queueItem = new DTOQueueModel() - { - PartProgramName = fileName, - Reps = reps, - RemainingReps = reps, - AbsolutePath = programData.Path, - Status = QUEUE_STATUS.NOT_ACTIVE - }; - - // Check if there is already a pp queue - if (!PartProgramQueue.ContainsKey(selectedProcess)) - PartProgramQueue.Add(selectedProcess, new List()); - - queueItem.Id = SupportFunctions.GetNextId(PartProgramQueue[selectedProcess].Select(x => x.Id)); - - // Add new process to - PartProgramQueue[selectedProcess].Add(queueItem); - - return cmsError; - } - public CmsError SwapQueueItems(int processId, int item1Index, int item2Index) { item1Index = item1Index - 1; @@ -340,7 +353,7 @@ namespace Step.NC if (PartProgramQueue[processId].ElementAtOrDefault(itemIndex) == null) return INCORRECT_PARAMETERS_ERROR; // Check if Program is running - if (PartProgramQueue[processId][itemIndex].Status == QUEUE_STATUS.RUNNING) + if (PartProgramQueue[processId][itemIndex].Status == QUEUE_ITEM_STATUS.RUNNING) return INCORRECT_PARAMETERS_ERROR; PartProgramQueue[processId][itemIndex].Reps = reps; @@ -379,6 +392,17 @@ namespace Step.NC return NO_ERROR; } + public CmsError StartWorkingQueue(int processId) + { + + return NO_ERROR; + } + + public CmsError StopWorkingQueue(int processId) + { + return NO_ERROR; + } + #endregion File manager #region Read Data diff --git a/Step/Controllers/WebApi/NcFileController.cs b/Step/Controllers/WebApi/NcFileController.cs index a6f42699..b4243b74 100644 --- a/Step/Controllers/WebApi/NcFileController.cs +++ b/Step/Controllers/WebApi/NcFileController.cs @@ -36,7 +36,7 @@ namespace Step.Controllers.WebApi } [Route("file/info"), HttpGet] - public IHttpActionResult GetFileInfo([FromUri]string filePath) + public IHttpActionResult GetFileInfo([FromUri]string filePath) { using (NcHandler ncHandler = new NcHandler()) { @@ -259,6 +259,32 @@ namespace Step.Controllers.WebApi } } + [Route("queue/start")] + public IHttpActionResult StartWorkingQueue(int processId) + { + using (NcHandler ncHandler = new NcHandler()) + { + CmsError cmsError = ncHandler.StartWorkingQueue(processId); + if (cmsError.IsError()) + return BadRequest(cmsError.localizationKey); + + return Ok(); + } + } + + [Route("queue/stop")] + public IHttpActionResult StopWorkingQueue(int processId) + { + using (NcHandler ncHandler = new NcHandler()) + { + CmsError cmsError = ncHandler.StopWorkingQueue(processId); + if (cmsError.IsError()) + return BadRequest(cmsError.localizationKey); + + return Ok(); + } + } + public class MoveItems { public int OldPosition;