diff --git a/CMS_CORE_Library/Siemens/Nc_Siemens.cs b/CMS_CORE_Library/Siemens/Nc_Siemens.cs index a4a7791..3978521 100644 --- a/CMS_CORE_Library/Siemens/Nc_Siemens.cs +++ b/CMS_CORE_Library/Siemens/Nc_Siemens.cs @@ -4460,6 +4460,8 @@ namespace CMS_CORE_Library.Siemens public override CmsError TOOLS_WLoadToolInMagazine(int magazineId, NewToolInMagazineModel newMagazineTool, ref MountedToolModel newMountedTool) { + int ackValue = -1; + ReadOkActionValue(out ackValue); // Check if magazine is occupied if (MagazineAction.Action != MAGAZINE_ACTIONS.READY) return MAGAZINE_BUSY_ERROR; @@ -4631,6 +4633,10 @@ namespace CMS_CORE_Library.Siemens if (cmsError.IsError()) return cmsError; + cmsError = CheckDimensionConsistency(ackValue); + if (cmsError.IsError()) + return cmsError; + // Mount temporarily till the Siemens notification arrives MoveToolInMagazineList(newMagazineTool.ToolId, magazineId, newMagazineTool.PositionId); @@ -4646,6 +4652,8 @@ namespace CMS_CORE_Library.Siemens return NO_ERROR; } + #region CONSISTENCY CHECKS + private CmsError CheckToolTableConsistency() { Thread.Sleep(100); @@ -4670,6 +4678,63 @@ namespace CMS_CORE_Library.Siemens return NO_ERROR; } + private CmsError ReadOkActionValue(out int value) + { + value = -1; + try + { + DataSvc dataSvc = new DataSvc(); + //Read Machine status + Item itemToRead = new Item("/Channel/State/aTcAckC[u1, 1]"); + dataSvc.Read(itemToRead); + value = Convert.ToInt32(itemToRead.Value); + } + catch (Exception ex) + { + return ManageException(ex); + } + if(value == -1) + { + return SIEMENS_TOOL_TABLE_ERROR; + } + return NO_ERROR; + } + + private CmsError CheckDimensionConsistency(int oldValue ) + { + bool check = true; + int attempt = 0; + int actualValue = -1; + try + { + while (check) + { + ReadOkActionValue(out actualValue); + if(actualValue > oldValue) + { + return NO_ERROR; + } + else + { + Thread.Sleep(500); + if (attempt == 9) + { + check = false; + } + attempt++; + } + + } + } + catch(Exception ex) + { + return ManageException(ex); + } + return SIEMENS_TOOL_TABLE_ERROR; + } + + #endregion + public override CmsError TOOLS_WUnloadToolFromMagazine(int magazineId, int positionId) { if (MagazineAction.Action != MAGAZINE_ACTIONS.READY)