diff --git a/CMS_CORE_Application/Form1.cs b/CMS_CORE_Application/Form1.cs index 612f623..fdf950b 100644 --- a/CMS_CORE_Application/Form1.cs +++ b/CMS_CORE_Application/Form1.cs @@ -133,6 +133,11 @@ namespace CMS_CORE_Application //AssistedToolingModel ass = new AssistedToolingModel(); //cmsError = N.PLC_RAssistedToolingData(ref ass); N.TOOLS_WStartEditData(); + + List tools = new List(); + List families = new List(); ; + List shanks = new List(); + N.TOOLS_RStoredData(ref tools, ref families, ref shanks); cmsError = N.PROC_RSelectedProcessData(1, ref selected); ProcessDataModel procData = new ProcessDataModel(); diff --git a/CMS_CORE_Library/Demo/Nc_Demo.cs b/CMS_CORE_Library/Demo/Nc_Demo.cs index 13c6e62..4bec865 100644 --- a/CMS_CORE_Library/Demo/Nc_Demo.cs +++ b/CMS_CORE_Library/Demo/Nc_Demo.cs @@ -3224,7 +3224,7 @@ namespace CMS_CORE_Library.Demo } } - public override CmsError TOOLS_RStoredData() + public override CmsError TOOLS_RStoredData(ref List tools, ref List families, ref List shanks) { return NO_ERROR; } diff --git a/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs b/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs index 8b49510..287f885 100644 --- a/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs +++ b/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs @@ -547,40 +547,6 @@ namespace CMS_CORE_Library.Fanuc } return NO_ERROR; - - ////Check if the NC is Connected - //CmsError cmsError = CheckConnection(); - //if (cmsError.IsError()) - // return cmsError; - - //Focas1.OPMSG3 Messg = new Focas1.OPMSG3(); - //short nReturn = 0; - //short count = FANUC_MAXMSGPMC; - - ////Execute the method - //nReturn = Focas1.cnc_rdopmsg3(nLibHandle[0], -1, ref count, Messg); - - ////Throw Exception if there's an error - //if (nReturn != 0) - // return GetNcError(nReturn); - - //// Add Alarm in List - //alarms.Clear(); - - //if (count >= 1 && Messg.msg1.datano >= 0) - // AddPlcAlarmsToList((ushort)Messg.msg1.datano, false, false, new List() { 1 }, alarms); - - //if (count >= 2 && Messg.msg2.datano >= 0) - // AddPlcAlarmsToList((ushort)Messg.msg2.datano, false, false, new List() { 1 }, alarms); - - //if (count >= 3 && Messg.msg3.datano >= 0) - // AddPlcAlarmsToList((ushort)Messg.msg3.datano, false, false, new List() { 1 }, alarms); - - //if (count >= 4 && Messg.msg4.datano >= 0) - // AddPlcAlarmsToList((ushort)Messg.msg4.datano, false, false, new List() { 1 }, alarms); - - //if (count >= 5 && Messg.msg5.datano >= 0) - // AddPlcAlarmsToList((ushort)Messg.msg5.datano, false, false, new List() { 1 }, alarms); } public override CmsError PLC_WRefreshMessage(uint id) @@ -1702,12 +1668,28 @@ namespace CMS_CORE_Library.Fanuc ReadMacroValue(processId, 4111, false, ref macroVal); offsetId = (short)macroVal; } + + // Read operator's message #3006 & #3017 + Focas1.OPMSG3 Messg = new Focas1.OPMSG3(); + short count = FANUC_MAXMSGPMC; + + // Execute the method + nReturn = Focas1.cnc_rdopmsg3(nLibHandle[0], -1, ref count, Messg); + + // Check return value + if (nReturn != 0) + return GetNcError(nReturn); + + string msg = ""; + // Check if message exist & if is an operator type (type == 4) + if (count >= 5 && Messg.msg5.datano >= 0 && Messg.msg5.type == 4) + msg = Messg.msg5.data; processData = new SelectedProcessData() { ActiveOffsetId = offsetId, Origin = origin, - ProcessMessage = "" + ProcessMessage = msg }; return NO_ERROR; @@ -3750,11 +3732,88 @@ namespace CMS_CORE_Library.Fanuc return NO_ERROR; } - public override CmsError TOOLS_RStoredData() + public override CmsError TOOLS_RStoredData(ref List tools, ref List families, ref List shanks) { + List readInt = new List(); + CmsError cmsError = MEM_RWIntegerList(R, 0, FAMILY_TABLE_INDEX.MemType, FAMILY_TABLE_INDEX.Address, FAMILY_TABLE_INDEX.Size/4, ref readInt); + if (cmsError.IsError()) + return cmsError; + + // Test + FromMemoryToModels(readInt, out families); + return NO_ERROR; } + private void FromMemoryToModels(List ints, out List models) + { + models = new List(); + + PropertyInfo[] properties = typeof(T).GetProperties(); + List byteValues = IntsToBytes(ints); + + // Index of the + int objOffset = 0; + + int propertyIndex = 0; + // Start from the begin of the table + for (int memoryIndex = 0; memoryIndex < byteValues.Count();) + { + // Get the size of the property + int size = Marshal.SizeOf(properties[propertyIndex].PropertyType); + + // Choose action based on the size + switch (size) + { + case 1: + { + properties[propertyIndex].SetValue(models[objOffset], byteValues[memoryIndex]); + } + break; + + case 2: + { + short u = BitConverter.ToInt16(new byte[2] { byteValues[memoryIndex], byteValues[memoryIndex + 1] }, 0); + // If is in the ID's memory range + if (memoryIndex < TOOL_OFFSET) + // Create TMP item with generic type declaration + models.Add((T)Activator.CreateInstance(typeof(T))); + + properties[propertyIndex].SetValue(models[objOffset], u); + + memoryIndex += 2; + } + break; + + case 4: + { + int i = BitConverter.ToInt32(new byte[4] { byteValues[memoryIndex], byteValues[memoryIndex + 1], byteValues[memoryIndex + 2], byteValues[memoryIndex + 3], }, 0); + properties[propertyIndex].SetValue(models[objOffset], i); + + memoryIndex += 4; + } + break; + + default: + break; + } + + // Check if there is another object + if (objOffset + 1 >= models.Count()) + { + objOffset = 0; + // check if there is another property + if (propertyIndex + 1 >= properties.Count()) + // if not, i wrote all the object's properties so exit from loop + propertyIndex = byteValues.Count(); + else + propertyIndex += 1; + } + else + objOffset++; + } + } + public override CmsError TOOLS_RMagazineBlock(ref List ids) { ids = new List(); diff --git a/CMS_CORE_Library/Models/DataStructures.cs b/CMS_CORE_Library/Models/DataStructures.cs index a3fa470..deb2d9e 100644 --- a/CMS_CORE_Library/Models/DataStructures.cs +++ b/CMS_CORE_Library/Models/DataStructures.cs @@ -84,7 +84,8 @@ namespace CMS_CORE_Library.Models READY = 1, LOADING = 2, UNLOADING = 3, - EXCHANGE = 5 + EXCHANGE = 5, + START_NEEDED = 7 } public enum SIEMENS_MAGAZINE_TYPE diff --git a/CMS_CORE_Library/Nc.cs b/CMS_CORE_Library/Nc.cs index a058084..4336dee 100644 --- a/CMS_CORE_Library/Nc.cs +++ b/CMS_CORE_Library/Nc.cs @@ -1696,7 +1696,7 @@ namespace CMS_CORE_Library public abstract CmsError TOOLS_RUpdatedToolsData(ref Dictionary updatedStatus, ref Dictionary updatedLives); - public abstract CmsError TOOLS_RStoredData(); + public abstract CmsError TOOLS_RStoredData(ref List tools, ref List families, ref List shanks); public abstract CmsError TOOLS_RMagazineBlock(ref List ids); diff --git a/CMS_CORE_Library/Osai/Nc_Osai.cs b/CMS_CORE_Library/Osai/Nc_Osai.cs index b27b62f..91e6082 100644 --- a/CMS_CORE_Library/Osai/Nc_Osai.cs +++ b/CMS_CORE_Library/Osai/Nc_Osai.cs @@ -53,7 +53,7 @@ namespace CMS_CORE_Library.Osai private static List EXT_IMG = new List() { "PNG", "JPG", "JPEG" }; private const uint MAX_ROWS_FILE_PREVIEW = 10; // massimo 10 righe - private const string TOOL_MANAGER_BACKUP_DIRECTORY_PATH = @"C:\CMS\Active\TMP\"; + private const string TOOL_MANAGER_BACKUP_DIRECTORY_PATH = @"\\"; private const string FAMILIES_FILE_NAME = @"Families"; private const string FAM_SIZE_FILE_NAME = @"Fam_Sizes"; @@ -3699,7 +3699,7 @@ namespace CMS_CORE_Library.Osai return NO_ERROR; } - public override CmsError TOOLS_RStoredData() + public override CmsError TOOLS_RStoredData(ref List tools, ref List families, ref List shanks) { CmsError cmsError = CreateBackup(); if (cmsError.IsError()) @@ -3708,12 +3708,12 @@ namespace CMS_CORE_Library.Osai string backupFilePath = TOOL_MANAGER_BACKUP_DIRECTORY_PATH + "{0}.csv"; if (File.Exists(string.Format(backupFilePath, FAMILIES_FILE_NAME))) { - List families = File.ReadAllLines(string.Format(backupFilePath, FAMILIES_FILE_NAME)) // Read file + families = File.ReadAllLines(string.Format(backupFilePath, FAMILIES_FILE_NAME)) // Read file .Where(x => x != string.Empty) .Select(x => x.Split(';')) // Split line - .Select(x => new NcFamilyFileModel // Setup new model for each line + .Select(x => new NcFamilyModel // Setup new model for each line { - Id = int.Parse(x[0]), + FamilyId = ushort.Parse(x[0]), ToolType = byte.Parse(x[1]), TcpTable = byte.Parse(x[2]), Gamma = byte.Parse(x[3]), @@ -3747,7 +3747,7 @@ namespace CMS_CORE_Library.Osai if (File.Exists(string.Format(backupFilePath, TOOLS_FILE_NAME))) { - List tools = File.ReadAllLines(string.Format(backupFilePath, TOOLS_FILE_NAME)) + tools = File.ReadAllLines(string.Format(backupFilePath, TOOLS_FILE_NAME)) .Where(x => x != string.Empty) .Select(x => x.Split(';')) .Select(x => new NcToolModel @@ -3767,7 +3767,7 @@ namespace CMS_CORE_Library.Osai if (File.Exists(string.Format(backupFilePath, SHANKS_FILE_NAME))) { - List shanks = File.ReadAllLines(string.Format(backupFilePath, SHANKS_FILE_NAME)) + shanks = File.ReadAllLines(string.Format(backupFilePath, SHANKS_FILE_NAME)) .Where(x => x != string.Empty) .Select(x => x.Split(';')) .Select(x => new NcShankModel @@ -3780,19 +3780,19 @@ namespace CMS_CORE_Library.Osai }).ToList(); } - if (File.Exists(string.Format(backupFilePath, MAG_POSITION_FILE_NAME))) - { - List positions = File.ReadAllLines(string.Format(backupFilePath, MAG_POSITION_FILE_NAME)) - .Where(x => x != string.Empty) - .Select(x => x.Split(';')) - .Select(x => new NcMagazinePositionModel - { - MagazineId = byte.Parse(x[0]), - PositionId = byte.Parse(x[1]), - Type = byte.Parse(x[2]), - // Disabled = byte.Parse(x[3]) > 0 ? (byte)1 : (byte)0 - }).ToList(); - } + //if (File.Exists(string.Format(backupFilePath, MAG_POSITION_FILE_NAME))) + //{ + // List positions = File.ReadAllLines(string.Format(backupFilePath, MAG_POSITION_FILE_NAME)) + // .Where(x => x != string.Empty) + // .Select(x => x.Split(';')) + // .Select(x => new NcMagazinePositionModel + // { + // MagazineId = byte.Parse(x[0]), + // PositionId = byte.Parse(x[1]), + // Type = byte.Parse(x[2]), + // // Disabled = byte.Parse(x[3]) > 0 ? (byte)1 : (byte)0 + // }).ToList(); + //} return NO_ERROR; } diff --git a/CMS_CORE_Library/Siemens/Nc_Siemens.cs b/CMS_CORE_Library/Siemens/Nc_Siemens.cs index e72641f..c2362f5 100644 --- a/CMS_CORE_Library/Siemens/Nc_Siemens.cs +++ b/CMS_CORE_Library/Siemens/Nc_Siemens.cs @@ -4274,7 +4274,7 @@ namespace CMS_CORE_Library.Siemens return FUNCTION_NOT_ALLOWED_ERROR; } - public override CmsError TOOLS_RStoredData() + public override CmsError TOOLS_RStoredData(ref List tools, ref List families, ref List shanks) { return FUNCTION_NOT_ALLOWED_ERROR; } diff --git a/CMS_CORE_Library/Utils/Nc_Utils.cs b/CMS_CORE_Library/Utils/Nc_Utils.cs index b2ac2e2..16e2d22 100644 --- a/CMS_CORE_Library/Utils/Nc_Utils.cs +++ b/CMS_CORE_Library/Utils/Nc_Utils.cs @@ -187,7 +187,7 @@ namespace CMS_CORE_Library.Utils .ToArray(); } - // Convert a byte into an array of bools + // Convert a generic number into an array of byte internal static byte[] NumberToByte(object val) { return BitConverter.GetBytes(Convert.ToInt32(val)); diff --git a/CMS_CORE_Nc_Demo_Application/Nc_Demo_Application/Constants.cs b/CMS_CORE_Nc_Demo_Application/Nc_Demo_Application/Constants.cs index 27c2c5f..d2652c4 100644 --- a/CMS_CORE_Nc_Demo_Application/Nc_Demo_Application/Constants.cs +++ b/CMS_CORE_Nc_Demo_Application/Nc_Demo_Application/Constants.cs @@ -70,11 +70,13 @@ namespace Nc_Demo_Application public enum MAGAZINE_ACTIONS { - NONE = 0, - LOADING = 1, - UNLOADING = 2, + NOT_READY = 0, + NONE = 1, + LOADING = 2, + UNLOADING = 3, TRANSFER = 4, - GENERIC = 5 + GENERIC = 5, + START_NEEDED = 7 }