diff --git a/CMS_CORE_Library/Demo/Nc_Demo.cs b/CMS_CORE_Library/Demo/Nc_Demo.cs index e81a804..9e82d71 100644 --- a/CMS_CORE_Library/Demo/Nc_Demo.cs +++ b/CMS_CORE_Library/Demo/Nc_Demo.cs @@ -16,6 +16,7 @@ using static CMS_CORE.Demo.MEMORY_ADDRESS; using static CMS_CORE.Nc; using static CMS_CORE_Library.DataStructures; using static CMS_CORE_Library.ToolConfigurations; +using static CMS_CORE.Utils.Nc_Utils; namespace CMS_CORE.Demo { @@ -2725,6 +2726,29 @@ namespace CMS_CORE.Demo return NO_ERROR; } + public override CmsError TOOLS_RMagazineStatus(ref Dictionary magazineStatus) + { + //Check if the NC is Connected + CmsError cmsError = CheckConnection(); + if (cmsError.IsError()) + return cmsError; + + // Read tool manager status + int status = 0; + cmsError = MEM_RWInteger(R, 0, MAGAZINES_ENABLED_CMD.MemType, MAGAZINES_ENABLED_CMD.Address, ref status); + if (cmsError.IsError()) + return cmsError; + + bool[] bits = IntToBool(status); + + for (int i = 0; i < bits.Length; i++) + { + magazineStatus.Add(i + 1, bits[i]); + } + + return NO_ERROR; + } + #endregion Nc Tool Manager /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -2853,6 +2877,8 @@ namespace CMS_CORE.Demo internal static MEMORY_CELL HEADS_ACK = new MEMORY_CELL(MEMORY_TYPE.Demo, 429, 4); internal static MEMORY_CELL HEADS_STROBE_INCREMENT = new MEMORY_CELL(MEMORY_TYPE.Demo, 432, 4); internal static MEMORY_CELL HEADS_STROBE_DECREMENT = new MEMORY_CELL(MEMORY_TYPE.Demo, 436, 4); + + internal static MEMORY_CELL MAGAZINES_ENABLED_CMD = new MEMORY_CELL(MEMORY_TYPE.Demo, 440, 4); } #endregion Memory addresses diff --git a/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs b/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs index b236a74..b57ce92 100644 --- a/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs +++ b/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs @@ -1902,6 +1902,11 @@ namespace CMS_CORE.Fanuc return NO_ERROR; } + public override CmsError TOOLS_RMagazineStatus(ref Dictionary magazineStatus) + { + return NO_ERROR; + } + #endregion Nc Tool Manager /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/CMS_CORE_Library/Nc.cs b/CMS_CORE_Library/Nc.cs index d61ca95..bf7b3d4 100644 --- a/CMS_CORE_Library/Nc.cs +++ b/CMS_CORE_Library/Nc.cs @@ -1683,6 +1683,8 @@ namespace CMS_CORE public abstract CmsError TOOLS_RStoredData(); + public abstract CmsError TOOLS_RMagazineStatus(ref Dictionary magazineStatus); + #endregion Nc Tool Manager /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/CMS_CORE_Library/Osai/Nc_Osai.cs b/CMS_CORE_Library/Osai/Nc_Osai.cs index e519389..b97eae7 100644 --- a/CMS_CORE_Library/Osai/Nc_Osai.cs +++ b/CMS_CORE_Library/Osai/Nc_Osai.cs @@ -443,7 +443,7 @@ namespace CMS_CORE.Osai if (cmsError.IsError()) return cmsError; // Convert integer array into bit array - bool[] statusBits = new BitArray(readValues.ToArray()).Cast().ToArray(); + bool[] statusBits = IntToBool(readValues.ToArray()); for (int i = 0; i < ALARMS_STATUS.Size * 8; i++) { @@ -523,7 +523,7 @@ namespace CMS_CORE.Osai bool[] bits = new bool[32]; // Convert int into to true/false array - bits = new BitArray(new int[] { readValue }).Cast().ToArray(); + bits = IntToBool(readValue); // Create adn set pre power on object PrePowerOnModel prePowerOn = new PrePowerOnModel() { @@ -575,7 +575,8 @@ namespace CMS_CORE.Osai functions = new List(); // Convert int into to true/false array - bool[] bits = new BitArray(readValues.ToArray()).Cast().ToArray(); + bool[] bits = IntToBool(readValues.ToArray()); + // Convert array into structured data for (int i = 0; i < bits.Count(); i++) { @@ -656,7 +657,7 @@ namespace CMS_CORE.Osai if (cmsError.IsError()) return cmsError; - bool[] bits = new BitArray(readValue.ToArray()).Cast().ToArray(); + bool[] bits = IntToBool(readValue.ToArray()); // Convert array into structured data for (ushort i = 0; i < bits.Count() / 2; i++) @@ -2553,7 +2554,7 @@ namespace CMS_CORE.Osai bool[] bits = new bool[16]; // Convert int into to true/false array - bits = new BitArray(new int[] { status }).Cast().ToArray(); + bits = IntToBool(status); // 1 = Non-editable tables, 2 = reading in progess if (bits[1] || bits[2]) return MAGAZINE_BUSY_ERROR; @@ -2590,6 +2591,29 @@ namespace CMS_CORE.Osai return NO_ERROR; } + public override CmsError TOOLS_RMagazineStatus(ref Dictionary magazineStatus) + { + //Check if the NC is Connected + CmsError cmsError = CheckConnection(); + if (cmsError.IsError()) + return cmsError; + + // Read tool manager status + int status = 0; + cmsError = MEM_RWInteger(R, 0, MAGAZINES_ENABLED_CMD.MemType, MAGAZINES_ENABLED_CMD.Address, ref status); + if (cmsError.IsError()) + return cmsError; + + bool[] bits = IntToBool(status); + + for(int i = 0; i < bits.Length; i++) + { + magazineStatus.Add(i + 1, bits[i]); + } + + return NO_ERROR; + } + public override CmsError TOOLS_WStartEditTooling(int magazineId) { //Check if the NC is Connected @@ -2865,7 +2889,7 @@ namespace CMS_CORE.Osai return cmsError; // Convert int into to true/false array - bool[] bits = new BitArray(readInt.ToArray()).Cast().ToArray(); + bool[] bits = IntToBool(readInt.ToArray()); ushort toolId = 0; byte status = 0; uint life = 0; diff --git a/CMS_CORE_Library/Siemens/Nc_Siemens.cs b/CMS_CORE_Library/Siemens/Nc_Siemens.cs index 28c9c0e..0026773 100644 --- a/CMS_CORE_Library/Siemens/Nc_Siemens.cs +++ b/CMS_CORE_Library/Siemens/Nc_Siemens.cs @@ -521,7 +521,7 @@ namespace CMS_CORE.Siemens if (cmsError.IsError()) return cmsError; // Convert integer array into bit array - bool[] statusBits = new BitArray(readValues.ToArray()).Cast().ToArray(); + bool[] statusBits = IntToBool(readValues.ToArray()); for (int i = 0; i < ALARMS_STATUS.Size * 8; i++) { @@ -609,7 +609,7 @@ namespace CMS_CORE.Siemens bool[] bits = new bool[32]; // Convert int into to true/false array - bits = new BitArray(new int[] { readValue }).Cast().ToArray(); + bits = IntToBool(readValue); // Create adn set pre power on object PrePowerOnModel prePowerOn = new PrePowerOnModel() { @@ -662,7 +662,7 @@ namespace CMS_CORE.Siemens functions = new List(); // Convert int into to true/false array - bool[] bits = new BitArray(readValues.ToArray()).Cast().ToArray(); + bool[] bits = IntToBool(readValues.ToArray()); // Convert array into structured data for (int i = 0; i < bits.Count(); i++) { @@ -727,7 +727,7 @@ namespace CMS_CORE.Siemens private CmsError PLC_RSoftKeys(MEMORY_CELL softKeyStatusMemory, MEMORY_CELL softKeysClickableMemory, ref List softKeys) { softKeys = new List(); - List readValue = new List(); + List readValues = new List(); int memorySizeToRead = (softKeyStatusMemory.Size + softKeysClickableMemory.Size); // Offset between status and clickable data @@ -739,12 +739,12 @@ namespace CMS_CORE.Siemens softKeyStatusMemory.Address, softKeyStatusMemory.SubAddress, memorySizeToRead / 4, - ref readValue); + ref readValues); if (cmsError.IsError()) return cmsError; - bool[] bits = new BitArray(readValue.ToArray()).Cast().ToArray(); + bool[] bits = IntToBool(readValues.ToArray()); // Convert array into structured data for (ushort i = 0; i < bits.Count() / 2; i++) @@ -1931,15 +1931,7 @@ namespace CMS_CORE.Siemens { return NO_ERROR; } - - private string FormatPath(ref string path) - { - path = path.TrimStart('\\'); - path = path.TrimEnd('\\'); - - return path.Replace('\\', '/'); - } - + public override CmsError FILES_RActiveProgramData(int processId, ref ActiveProgramDataModel data) { try @@ -1979,18 +1971,7 @@ namespace CMS_CORE.Siemens return NO_ERROR; } - - private IEnumerable GetLinesFromString(string text) - { - string line; - using (StringReader reader = new StringReader(text)) - { - while ((line = reader.ReadLine()) != null) - { - yield return line; - } - } - } + public override CmsError FILES_UploadPartProgram(string localPath, string name, ref string newFilePath) { // Open file @@ -2110,6 +2091,26 @@ namespace CMS_CORE.Siemens return NO_ERROR; } + + private IEnumerable GetLinesFromString(string text) + { + string line; + using (StringReader reader = new StringReader(text)) + { + while ((line = reader.ReadLine()) != null) + { + yield return line; + } + } + } + + private string FormatPath(ref string path) + { + path = path.TrimStart('\\'); + path = path.TrimEnd('\\'); + + return path.Replace('\\', '/'); + } #endregion File Management @@ -3197,6 +3198,11 @@ namespace CMS_CORE.Siemens return FUNCTION_NOT_ALLOWED_ERROR; } + public override CmsError TOOLS_RMagazineStatus(ref Dictionary magazineStatus) + { + return FUNCTION_NOT_ALLOWED_ERROR; + } + #endregion Nc Tool Manager /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/CMS_CORE_Library/Utils/Nc_Utils.cs b/CMS_CORE_Library/Utils/Nc_Utils.cs index 38e4a90..00f692b 100644 --- a/CMS_CORE_Library/Utils/Nc_Utils.cs +++ b/CMS_CORE_Library/Utils/Nc_Utils.cs @@ -1,6 +1,8 @@ using System; +using System.Collections; using System.Collections.Generic; using System.IO; +using System.Linq; using static CMS_CORE_Library.DataStructures; namespace CMS_CORE.Utils @@ -195,5 +197,17 @@ namespace CMS_CORE.Utils } } } + + public static bool[] IntToBool(int val) + { + return IntToBool(new int[] { val }); + } + + public static bool[] IntToBool(int[] val) + { + return new BitArray(val.ToArray()) + .Cast() + .ToArray(); + } } } \ No newline at end of file