From af198e61430fce8bc11bc9457f51eed7b536e9ac Mon Sep 17 00:00:00 2001 From: Lucio Maranta Date: Mon, 3 Dec 2018 16:44:52 +0000 Subject: [PATCH] --- CMS_CORE_Library/Fanuc/Nc_Fanuc.cs | 2 +- CMS_CORE_Library/Models/DataStructures.cs | 10 +- CMS_CORE_Library/Siemens/Nc_Siemens.cs | 206 +++++----------------- 3 files changed, 46 insertions(+), 172 deletions(-) diff --git a/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs b/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs index bc2bd3a..be33463 100644 --- a/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs +++ b/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs @@ -3063,7 +3063,7 @@ namespace CMS_CORE_Library.Fanuc public override CmsError TOOLS_RMagazineStatus(ref Dictionary magazineStatus) { - //Check if the NC is Connected + // Check if the NC is Connected CmsError cmsError = CheckConnection(); if (cmsError.IsError()) return cmsError; diff --git a/CMS_CORE_Library/Models/DataStructures.cs b/CMS_CORE_Library/Models/DataStructures.cs index ce323a3..a33c032 100644 --- a/CMS_CORE_Library/Models/DataStructures.cs +++ b/CMS_CORE_Library/Models/DataStructures.cs @@ -275,11 +275,11 @@ namespace CMS_CORE_Library.Models public enum MAGAZINE_ACTIONS { - NONE = 0, - LOADING = 1, - UNLOADING = 2, - TRANSFER = 4, - GENERIC = 5 + NOT_READY = 0, + READY = 1, + LOADING = 2, + UNLOADING = 3, + EXCHANGE = 5 } public enum SIEMENS_MAGAZINE_TYPE diff --git a/CMS_CORE_Library/Siemens/Nc_Siemens.cs b/CMS_CORE_Library/Siemens/Nc_Siemens.cs index 4d14573..80efb36 100644 --- a/CMS_CORE_Library/Siemens/Nc_Siemens.cs +++ b/CMS_CORE_Library/Siemens/Nc_Siemens.cs @@ -111,7 +111,7 @@ namespace CMS_CORE_Library.Siemens public static uint multitoolsNumber = 0; - public const string BASE_FILE_PATH = "//NC/"; + public const string BASE_FILE_PATH = "//NC/MPF.DIR/"; public const string NC_FILE_PATH = "MPF.DIR"; /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -174,7 +174,7 @@ namespace CMS_CORE_Library.Siemens return NO_ERROR; } - //Disconnect Method + // Disconnect Method public override CmsError NC_Disconnect() { //Set Connected to FALSE and close the session @@ -288,7 +288,7 @@ namespace CMS_CORE_Library.Siemens CultureInfo cultureInfo = CultureInfo.CreateSpecificCulture(language); - //Setup the path of NC alarms translations file + // Setup the path of NC alarms translations file filePath = PLC_MESSAGES_FILE_PATH + "cmsalarm_" + cultureInfo.ThreeLetterWindowsLanguageName.ToUpper() + ".ts"; if (!File.Exists(filePath)) return INCORRECT_LANGUAGE_ERROR; @@ -3100,7 +3100,7 @@ namespace CMS_CORE_Library.Siemens public override CmsError TOOLS_WLoadToolInMagazine(int magazineId, NewToolInMagazineModel newMagazineTool) { // Check if magazine is occupied - if (MagazineAction.Action != MAGAZINE_ACTIONS.NONE) + if (MagazineAction.Action != MAGAZINE_ACTIONS.NOT_READY) return MAGAZINE_BUSY_ERROR; // Get mag config @@ -3208,7 +3208,7 @@ namespace CMS_CORE_Library.Siemens public override CmsError TOOLS_WUnloadToolFromMagazine(int magazineId, int positionId) { - if (MagazineAction.Action != MAGAZINE_ACTIONS.NONE) + if (MagazineAction.Action != MAGAZINE_ACTIONS.NOT_READY) return MAGAZINE_BUSY_ERROR; // Get mag config @@ -3917,162 +3917,34 @@ namespace CMS_CORE_Library.Siemens private void MagazineAction_OnChange(Guid guid, Item item, DataSvcStatus status) { - if (int.TryParse(item.Value.ToString(), out int action)) - switch (action) - { - case 1: - { - MagazineAction = new MagazineActionModel() - { - Action = MAGAZINE_ACTIONS.NONE, - OriginMagazine = 0, - OriginPosition = 0, - DestinationMagazine = 0, - DestinationPosition = 0, - Tool = null - }; - } - break; + List shorts = new List(); + CmsError cmsError = MEM_RWByteList(R, 0, MAGAZINE_ACTION.MemType, MAGAZINE_ACTION.Address, MAGAZINE_ACTION.SubAddress + 1, 10, ref shorts); + // TODO MANAGE ERROR - case 0: - case 4: - { - MagazineAction = new MagazineActionModel() - { - Action = MAGAZINE_ACTIONS.GENERIC, - OriginMagazine = 0, - OriginPosition = 0, - DestinationMagazine = 0, - DestinationPosition = 0, - Tool = null - }; - } - break; - - case 2: - case 3: - { - string prefix = "DB"; - - if (Convert.ToInt32(item.Value) == 2) - prefix += "71."; - else - prefix += "72."; - - // Read action - DataSvc dataSvc = new DataSvc(); - Item readedItem = new Item(prefix + "DBB4"); - dataSvc.Read(readedItem); - - // Get action value - MAGAZINE_ACTIONS magAction = Convert.ToInt32(readedItem.Value) > (int)MAGAZINE_ACTIONS.GENERIC ? MAGAZINE_ACTIONS.GENERIC : (MAGAZINE_ACTIONS)Convert.ToInt32(readedItem.Value); - - int sourceMagIndex = 0, destinationMagIndex = 0; - int sourcePosIndex = 1, destinationPosIndex = 0; - int toolId = 0; - - if (prefix.Contains("72")) - { - bool firstBit = GetBitValue(Convert.ToInt32(readedItem.Value), 2); - bool secondBit = GetBitValue(Convert.ToInt32(readedItem.Value), 3); - bool unloadBit = GetBitValue(Convert.ToInt32(readedItem.Value), 4); - - if (unloadBit) - magAction = MAGAZINE_ACTIONS.UNLOADING; - else if (firstBit || secondBit) - magAction = MAGAZINE_ACTIONS.LOADING; - else - magAction = MAGAZINE_ACTIONS.GENERIC; - - // Read tool id - dataSvc = new DataSvc(); - readedItem = new Item(prefix + "DBW44"); - dataSvc.Read(readedItem); - toolId = Convert.ToInt32(readedItem.Value); - - // Set destination indexes - destinationMagIndex = 2; - destinationPosIndex = 3; - } - else - { - // Read tool id - dataSvc = new DataSvc(); - readedItem = new Item("/Channel/State/aTcTno"); - dataSvc.Read(readedItem); - - toolId = Convert.ToInt32(readedItem.Value); - - if (magAction == MAGAZINE_ACTIONS.UNLOADING) - { - // Set source indexes - sourceMagIndex = 2; - sourcePosIndex = 3; - - // Set destination indexes - destinationMagIndex = 0; - destinationPosIndex = 1; - } - else - { - // Set destination indexes - destinationMagIndex = 4; - destinationPosIndex = 5; - } - } - - // Read position and tool data - List magazineValue = new List() - { - new Item(prefix + "DBW20"), // Intermediate mag Id - new Item(prefix + "DBW22"), // intermediate pos Id - - new Item(prefix + "DBW24"), // Unload mag Id - new Item(prefix + "DBW26"), // Unload pos Id - - new Item(prefix + "DBW28"), // Load mag Id - new Item(prefix + "DBW30") // Load pos Id - }; - - // Read - dataSvc.Read(magazineValue.ToArray()); - - //// Find tool data into tools list - //MagazineActionToolModel tool = null; - //if (toolId != 0) - //{ - // tool = ToolTableData.Where(x => x.Id == toolId)?.Select(x => new MagazineActionToolModel - // { - // Id = x.Id, - // Name = x.FamilyName, - // ToolType = x.ToolType, - // IsMultitool = false - // }).FirstOrDefault(); - - // // If not found in the tools list, check in the multitools list - // if (tool == null) - // tool = MultitoolsData.Where(x => x.Id == toolId)?.Select(x => new MagazineActionToolModel - // { - // Id = x.Id, - // Name = x.Name, - // ToolType = 0, - // IsMultitool = true - // }).FirstOrDefault(); - //} - - // Populate static value - MagazineAction = new MagazineActionModel() - { - Action = magAction, - OriginMagazine = Convert.ToInt32(magazineValue[sourceMagIndex].Value), - OriginPosition = Convert.ToInt32(magazineValue[sourcePosIndex].Value), - DestinationMagazine = Convert.ToInt32(magazineValue[destinationMagIndex].Value), - DestinationPosition = Convert.ToInt32(magazineValue[destinationPosIndex].Value), - Tool = null // tool ?? new MagazineActionToolModel() - }; - } - break; - } + // find tool + ushort toolId = BitConverter.ToUInt16(new byte[2] { shorts[0], shorts[1]} , 0); + MagazineActionToolModel tool = null; + if (toolId != 0) + tool = ToolTableData + .Where(x => x.Id == toolId) + .Select(x => new MagazineActionToolModel() + { + Id = x.Id, + IsMultitool = false, + Name = x.FamilyName, + ToolType = x.ToolType + }).FirstOrDefault(); + // TODO ADD SECOND TOOL + // Populate model with new data + MagazineAction = new MagazineActionModel() + { + Action = (MAGAZINE_ACTIONS)item.Value, + Tool = tool, + OriginMagazine = shorts[4], + OriginPosition = BitConverter.ToUInt16(new byte[2] { shorts[5], shorts[6] }, 0), + DestinationMagazine = shorts[7], + DestinationPosition = BitConverter.ToUInt16(new byte[2] { shorts[8], shorts[9] }, 0) + }; } private void PopulateToolsTableFromFileStrings(string[] toolsStrings) @@ -4089,9 +3961,9 @@ namespace CMS_CORE_Library.Siemens for (int i = 0; i < toolsStrings.Count(); i++) { string actualString = toolsStrings[i]; // Get actual string data - + GetIdsFromSiemensToolString(actualString, out int firstId, out int secondId); // find ids from current string - + if (firstId != 0) { // If tool is changed, change current index tool @@ -4306,7 +4178,7 @@ namespace CMS_CORE_Library.Siemens { ToolTableData[toolIndex] .EdgesData[edgeIndex] - .ResidualLife = Convert.ToInt32(actualString.Split('=').LastOrDefault()); + .ResidualLife = Convert.ToDouble(actualString.Split('=').LastOrDefault()); } } break; @@ -4318,7 +4190,7 @@ namespace CMS_CORE_Library.Siemens { ToolTableData[toolIndex] .EdgesData[edgeIndex] - .NominalLife = Convert.ToInt32(actualString.Split('=').LastOrDefault()); + .NominalLife = Convert.ToDouble(actualString.Split('=').LastOrDefault()); } } break; @@ -4330,7 +4202,7 @@ namespace CMS_CORE_Library.Siemens { ToolTableData[toolIndex] .EdgesData[edgeIndex] - .PreAlmLife = Convert.ToInt32(actualString.Split('=').LastOrDefault()); + .PreAlmLife = Convert.ToDouble(actualString.Split('=').LastOrDefault()); } } break; @@ -4354,7 +4226,7 @@ namespace CMS_CORE_Library.Siemens { ToolTableData[toolIndex] .EdgesData[edgeIndex] - .NominalLife = Convert.ToInt32(actualString.Split('=').LastOrDefault()); + .NominalLife = Convert.ToDouble(actualString.Split('=').LastOrDefault()); } } break; @@ -5356,5 +5228,7 @@ namespace CMS_CORE_Library.Siemens internal static MEMORY_CELL AXES_BUTTON_VISIBLE = new MEMORY_CELL(MEMORY_TYPE.Siemens_DB, TABLE, 3044, 16); + + internal static MEMORY_CELL MAGAZINE_ACTION = new MEMORY_CELL(MEMORY_TYPE.Siemens_DB, TABLE, 3060, 16); } } \ No newline at end of file