diff --git a/CMS_CORE_Library/Demo/Nc_Demo.cs b/CMS_CORE_Library/Demo/Nc_Demo.cs index 5770c7f..475c721 100644 --- a/CMS_CORE_Library/Demo/Nc_Demo.cs +++ b/CMS_CORE_Library/Demo/Nc_Demo.cs @@ -3565,7 +3565,7 @@ namespace CMS_CORE_Library.Demo return NO_ERROR; } - public override CmsError TOOLS_RUpdatedToolsData(ref Dictionary updatedStatus, ref Dictionary updatedLives) + public override CmsError TOOLS_RUpdatedToolsData(ref Dictionary updatedStatus, ref Dictionary updatedLives, ref Dictionary updatedPresetting, ref Dictionary updatedDressing) { return NO_ERROR; } diff --git a/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs b/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs index 439d355..a989beb 100644 --- a/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs +++ b/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs @@ -4201,7 +4201,7 @@ namespace CMS_CORE_Library.Fanuc return NO_ERROR; } - public override CmsError TOOLS_RUpdatedToolsData(ref Dictionary updatedStatus, ref Dictionary updatedLives) + public override CmsError TOOLS_RUpdatedToolsData(ref Dictionary updatedStatus, ref Dictionary updatedLives, ref Dictionary updatedPresetting, ref Dictionary updatedDressing) { // Check if the NC is Connected CmsError cmsError = CheckConnection(); @@ -4210,6 +4210,8 @@ namespace CMS_CORE_Library.Fanuc updatedStatus = new Dictionary(); updatedLives = new Dictionary(); + updatedPresetting = new Dictionary(); + updatedDressing = new Dictionary(); // Read 20 bit of status, read 20 bit of tool life List readInt = new List(); diff --git a/CMS_CORE_Library/Nc.cs b/CMS_CORE_Library/Nc.cs index 5579a5e..0ec7c00 100644 --- a/CMS_CORE_Library/Nc.cs +++ b/CMS_CORE_Library/Nc.cs @@ -1872,7 +1872,7 @@ namespace CMS_CORE_Library public abstract CmsError TOOLS_RMagazineConfig(ref List config); - public abstract CmsError TOOLS_RUpdatedToolsData(ref Dictionary updatedStatus, ref Dictionary updatedLives); + public abstract CmsError TOOLS_RUpdatedToolsData(ref Dictionary updatedStatus, ref Dictionary updatedLives, ref Dictionary updatedPresetting, ref Dictionary updatedDressing); public abstract CmsError TOOLS_RStoredData(ref List tools, ref List families, ref List shanks); diff --git a/CMS_CORE_Library/NcThermo.cs b/CMS_CORE_Library/NcThermo.cs index ddf6b18..616dbd7 100644 --- a/CMS_CORE_Library/NcThermo.cs +++ b/CMS_CORE_Library/NcThermo.cs @@ -1846,7 +1846,7 @@ namespace CMS_CORE_Library public abstract CmsError TOOLS_RMagazineConfig(ref List config); - public abstract CmsError TOOLS_RUpdatedToolsData(ref Dictionary updatedStatus, ref Dictionary updatedLives); + public abstract CmsError TOOLS_RUpdatedToolsData(ref Dictionary updatedStatus, ref Dictionary updatedLives, ref Dictionary updatedPresetting, ref Dictionary updatedDressing); public abstract CmsError TOOLS_RStoredData(ref List tools, ref List families, ref List shanks); diff --git a/CMS_CORE_Library/Osai/Nc_Osai.cs b/CMS_CORE_Library/Osai/Nc_Osai.cs index a795f87..75a1dcd 100644 --- a/CMS_CORE_Library/Osai/Nc_Osai.cs +++ b/CMS_CORE_Library/Osai/Nc_Osai.cs @@ -4123,8 +4123,8 @@ namespace CMS_CORE_Library.Osai return NO_ERROR; } - public override CmsError TOOLS_RUpdatedToolsData(ref Dictionary updatedStatus, ref Dictionary updatedLives) - { + public override CmsError TOOLS_RUpdatedToolsData(ref Dictionary updatedStatus, ref Dictionary updatedLives, ref Dictionary updatedPresetting, ref Dictionary updatedDressing) + { // Check if the NC is Connected CmsError cmsError = CheckConnection(); if (cmsError.IsError()) @@ -4132,6 +4132,8 @@ namespace CMS_CORE_Library.Osai updatedStatus = new Dictionary(); updatedLives = new Dictionary(); + updatedPresetting = new Dictionary(); + updatedDressing = new Dictionary(); // Read 20 bit of status, read 20 bit of tool life List readInt = new List(); @@ -4204,6 +4206,82 @@ namespace CMS_CORE_Library.Osai } } + + // Read 20 bit of status, read 20 bit of tool life + readInt = new List(); + cmsError = MEM_RWIntegerList(R, 0, TOOL_DRESSING_UPDATED_CMD.MemType, TOOL_DRESSING_UPDATED_CMD.Address, 3, ref readInt); + if (cmsError.IsError()) + return cmsError; + + // Convert int into to true/false array + bits = IntToBits(readInt.ToArray()); + toolId = 0; + ushort presetting = 0; + ushort dressing = 0; + + strobeByteIndex = 0; + ackByteIndex = 0; + + for (int i = 0; i < bits.Length; i++) + { + if ((i < 32 || i > 63) && bits[i]) + { + int bitIndex = i; + if (i >= 64) // 32 status bit and 32 lives bit + bitIndex -= 64; + + // First tool id + actual head index + int headIndex = (HEADS_DATA.Address + 2) + (bitIndex * 6); + cmsError = MEM_RWWord(R, 0, HEADS_DATA.MemType, headIndex, ref toolId); + if (i < 32) + { + // Read new status value + int dressingIndex = TOOL_DRESSING_UPDATED_DATA.Address + (bitIndex); // Index = starting address + (headIndex * 2) -> because Osai uses 16bit format + cmsError = MEM_RWWord(R, 0, TOOL_DRESSING_UPDATED_DATA.MemType, dressingIndex, ref dressing); + if (cmsError.IsError()) + return cmsError; + + // Insert into the list + if (!updatedDressing.ContainsKey(toolId)) + // Insert into the new lives list + updatedDressing.Add(toolId, dressing); + + + // Setup ack/strobe indexes + // if i > 15 then index = next word + strobeByteIndex = i > 15 ? TOOL_DRESSING_UPDATED_CMD.Address + 1 : TOOL_DRESSING_UPDATED_CMD.Address; + ackByteIndex = i > 15 ? TOOL_DRESSING_UPDATED_ACK.Address + 1 : TOOL_DRESSING_UPDATED_ACK.Address; + } + else + { + // Read new life value + int presettingIndex = TOOL_PRESETTING_UPDATED_DATA.Address + (bitIndex); // Index = starting address + (headIndex * 2) -> because Osai uses 16bit format + cmsError = MEM_RWWord(R, 0, TOOL_PRESETTING_UPDATED_DATA.MemType, presettingIndex, ref presetting); + if (cmsError.IsError()) + return cmsError; + + // TODO CHECK + if (!updatedPresetting.ContainsKey(toolId)) + // Insert into the new lives list + updatedPresetting.Add(toolId, presetting); + + // Setup ack/strobe indexes + // if i > (64) + 15 then index = next word + strobeByteIndex = i > 79 ? TOOL_PRESETTING_UPDATED_CMD.Address + 1 : TOOL_PRESETTING_UPDATED_CMD.Address; + ackByteIndex = i > 79 ? TOOL_PRESETTING_UPDATED_ACK.Address + 1 : TOOL_PRESETTING_UPDATED_ACK.Address; + } + + + // Manage ack and strobe + bitIndex = bitIndex % 16; + cmsError = PLC_ManageActiveAck(strobeByteIndex, bitIndex, ackByteIndex, bitIndex, MEMORY_TYPE.Osai_MW); + if (cmsError.IsError()) + return cmsError; + + } + } + + return NO_ERROR; } @@ -5192,6 +5270,15 @@ namespace CMS_CORE_Library.Osai internal static MEMORY_CELL TOOL_STATUS_UPDATED_DATA = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 4416, 10); internal static MEMORY_CELL TOOL_LIFE_UPDATED_DATA = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 4428, 40); + + internal static MEMORY_CELL TOOL_DRESSING_UPDATED_CMD = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 4534, 2); + internal static MEMORY_CELL TOOL_DRESSING_UPDATED_ACK = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 4542, 2); + internal static MEMORY_CELL TOOL_DRESSING_UPDATED_DATA = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 4550, 20); + + internal static MEMORY_CELL TOOL_PRESETTING_UPDATED_CMD = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 4538, 2); + internal static MEMORY_CELL TOOL_PRESETTING_UPDATED_ACK = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 4546, 2); + internal static MEMORY_CELL TOOL_PRESETTING_UPDATED_DATA = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 4572, 20); + internal static MEMORY_CELL MAGAZINE_TYPES = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 4470, 4); internal static MEMORY_CELL MAGAZINE_POSITIONS_NUMBER = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 4482, 4); diff --git a/CMS_CORE_Library/S7Net/Nc_S7Net.cs b/CMS_CORE_Library/S7Net/Nc_S7Net.cs index 8b3fa38..1050442 100644 --- a/CMS_CORE_Library/S7Net/Nc_S7Net.cs +++ b/CMS_CORE_Library/S7Net/Nc_S7Net.cs @@ -4828,7 +4828,7 @@ namespace CMS_CORE_Library.S7Net return FUNCTION_NOT_ALLOWED_ERROR; } - public override CmsError TOOLS_RUpdatedToolsData(ref Dictionary updatedStatus, ref Dictionary updatedLives) + public override CmsError TOOLS_RUpdatedToolsData(ref Dictionary updatedStatus, ref Dictionary updatedLives, ref Dictionary updatedPresetting, ref Dictionary updatedDressing) { return FUNCTION_NOT_ALLOWED_ERROR; } diff --git a/CMS_CORE_Library/Siemens/Nc_Siemens.cs b/CMS_CORE_Library/Siemens/Nc_Siemens.cs index 16e69e8..5100064 100644 --- a/CMS_CORE_Library/Siemens/Nc_Siemens.cs +++ b/CMS_CORE_Library/Siemens/Nc_Siemens.cs @@ -5194,7 +5194,7 @@ namespace CMS_CORE_Library.Siemens return FUNCTION_NOT_ALLOWED_ERROR; } - public override CmsError TOOLS_RUpdatedToolsData(ref Dictionary updatedStatus, ref Dictionary updatedLives) + public override CmsError TOOLS_RUpdatedToolsData(ref Dictionary updatedStatus, ref Dictionary updatedLives, ref Dictionary updatedPresetting, ref Dictionary updatedDressing) { return FUNCTION_NOT_ALLOWED_ERROR; }