From 254898cfa241a9f7a8bc529a60bc3c85ba4812d5 Mon Sep 17 00:00:00 2001 From: Lucio Maranta Date: Tue, 5 Mar 2019 16:19:12 +0000 Subject: [PATCH] --- CMS_CORE_Library/Siemens/Nc_Siemens.cs | 78 ++++++++++++++++---------- CMS_CORE_Library/ToolConfigurations.cs | 6 +- 2 files changed, 50 insertions(+), 34 deletions(-) diff --git a/CMS_CORE_Library/Siemens/Nc_Siemens.cs b/CMS_CORE_Library/Siemens/Nc_Siemens.cs index 1d8e5b5..5ca2b20 100644 --- a/CMS_CORE_Library/Siemens/Nc_Siemens.cs +++ b/CMS_CORE_Library/Siemens/Nc_Siemens.cs @@ -129,10 +129,10 @@ namespace CMS_CORE_Library.Siemens private static DataSvc SelectedProcessSvc; private static ushort SelectedProcess = 0; - private static Hashtable MachineAxesPosition = new Hashtable(); - private static Hashtable ToGoAxesPosition = new Hashtable(); - private static Hashtable InterpAxesPosition = new Hashtable(); - private static Hashtable ProgrammedAxisPosition = new Hashtable(); + private static Dictionary MachineAxesPosition = new Dictionary(); + private static Dictionary ToGoAxesPosition = new Dictionary(); + private static Dictionary InterpAxesPosition = new Dictionary(); + private static Dictionary ProgrammedAxisPosition = new Dictionary(); /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -1773,11 +1773,11 @@ namespace CMS_CORE_Library.Siemens axes = new Dictionary(); // Cycle between axes // The dictionary is written asynchronously so i have to create a copy of the dictionary with .ToList() to avoid exceptions - foreach (DictionaryEntry axis in InterpAxesPosition) + // axes = InterpAxesPosition.ToDictionary(x => x.Key, x => x.Value); This code throws exceptions + foreach (var axis in InterpAxesPosition.ToList()) { - axes.Add(axis.Key.ToString(), Convert.ToDouble(axis.Value)); + axes.Add(axis.Key, axis.Value); } - // axes = InterpAxesPosition.ToDictionary(x => x.Key, x => x.Value); This throws exceptions } catch (Exception ex) { @@ -1795,11 +1795,10 @@ namespace CMS_CORE_Library.Siemens // Cycle between axes // The dictionary is written asynchronously so i have to create a copy of the dictionary with .ToList() to avoid exceptions - foreach (DictionaryEntry axis in MachineAxesPosition) + foreach (var axis in MachineAxesPosition.ToList()) { - axes.Add(axis.Key.ToString(), Convert.ToDouble(axis.Value)); + axes.Add(axis.Key, axis.Value); } - // axes = MachineAxesPosition.ToDictionary(x => x.Key, x => x.Value); } catch (Exception ex) { @@ -1817,11 +1816,10 @@ namespace CMS_CORE_Library.Siemens // Cycle between axes // The dictionary is written asynchronously so i have to create a copy of the dictionary with .ToList() to avoid exceptions - foreach (DictionaryEntry axis in ProgrammedAxisPosition) + foreach (var axis in ProgrammedAxisPosition.ToList()) { - axes.Add(axis.Key.ToString(), Convert.ToDouble(axis.Value)); + axes.Add(axis.Key, axis.Value); } - // axes = ProgrammedAxisPosition.ToDictionary(x => x.Key, x => x.Value); } catch (Exception ex) { @@ -1839,11 +1837,10 @@ namespace CMS_CORE_Library.Siemens // Cycle between axes // The dictionary is written asynchronously so i have to create a copy of the dictionary with .ToList() to avoid exceptions - foreach (DictionaryEntry axis in InterpAxesPosition) + foreach (var axis in InterpAxesPosition.ToList()) { - axes.Add(axis.Key.ToString(), Convert.ToDouble(axis.Value)); + axes.Add(axis.Key, axis.Value); } - // axes = MachineAxesPosition.ToDictionary(x => x.Key, x => x.Value); } catch (Exception ex) { @@ -1861,11 +1858,10 @@ namespace CMS_CORE_Library.Siemens // Cycle between axes // The dictionary is written asynchronously so i have to create a copy of the dictionary with .ToList() to avoid exceptions - foreach (DictionaryEntry axis in ToGoAxesPosition) + foreach (var axis in ToGoAxesPosition.ToList()) { - axes.Add(axis.Key.ToString(), Convert.ToDouble(axis.Value)); + axes.Add(axis.Key, axis.Value); } - // axes = ToGoAxesPosition.ToDictionary(x => x.Key, x => x.Value); } catch (Exception ex) { @@ -5587,34 +5583,54 @@ namespace CMS_CORE_Library.Siemens } } - private void MountToolToMagazineList(int toolId, int magazineId, int positionId) + private void MountToolToMagazineList(int toolId, int magazineId, int positionId) { - // Remove tool from list - MagazineMountedTools.RemoveAll(mountTool => PositionContainsTool(mountTool, toolId)); // If load magazine != 0, add new tool if (magazineId != 0 && positionId != 0) { - // Find if position exist - MountedToolModel mounted = MagazineMountedTools - .Where(x => x.MagazineId == magazineId && x.PositionId == positionId) - .FirstOrDefault(); - if (mounted != null) - return; - // Find tool by id var tool = GetToolOrMultitool(toolId); if (tool != null) { - if(magazineId == 9998) + if (magazineId == 9998) { - // Set magazine position as occupied + // Get old tool position + MountedToolModel toolMounted = MagazineMountedTools + .Where(x => x.ToolId == toolId) + .FirstOrDefault(); + + if(toolMounted != null) + { + // Set magazine position as occupied + var position = MagazinePositionsData.Where(x => + x.MagazineId == toolMounted.MagazineId + && x.PositionId == toolMounted.PositionId) + .FirstOrDefault(); + + if (position != null) + position.Occupied = true; + } } else { // Free a position + var position = MagazinePositionsData.Where(x => x.MagazineId == magazineId && x.PositionId == positionId).FirstOrDefault(); + if(position != null) + position.Occupied = false; } + // Remove tool from list + MagazineMountedTools.RemoveAll(mountTool => PositionContainsTool(mountTool, toolId)); + + // Find if position exist + MountedToolModel mounted = MagazineMountedTools + .Where(x => x.MagazineId == magazineId && x.PositionId == positionId) + .FirstOrDefault(); + + if (mounted != null) + return; + // Add tool to list MagazineMountedTools.Add(new MountedToolModel() { diff --git a/CMS_CORE_Library/ToolConfigurations.cs b/CMS_CORE_Library/ToolConfigurations.cs index 631c8f9..0e985f4 100644 --- a/CMS_CORE_Library/ToolConfigurations.cs +++ b/CMS_CORE_Library/ToolConfigurations.cs @@ -277,9 +277,9 @@ namespace CMS_CORE_Library FamilyReadOnlyConfiguration = new List() { new FieldsConfiguration{ Name = "name", Type = "string", SelectValues = null, Category = "family", SubCategory = "general", ReadOnly = true, MinValue = 0, MaxValue = 0}, - new FieldsConfiguration{ Name = "toolType", Type = "select", SelectValues = toolTypeCodeList, Category = "family", SubCategory = "general", ReadOnly = true, MinValue = 0, MaxValue = byte.MaxValue}, - new FieldsConfiguration{ Name = "leftSize", Type = "int", SelectValues = null, Category = "family", SubCategory = "general", ReadOnly = true, MinValue = 0, MaxValue = byte.MaxValue}, - new FieldsConfiguration{ Name = "rightSize", Type = "int", SelectValues = null, Category = "family", SubCategory = "general", ReadOnly = true, MinValue = 0, MaxValue = byte.MaxValue}, + new FieldsConfiguration{ Name = "toolType", Type = "select", SelectValues = toolTypeCodeList, Category = "family", SubCategory = "general", ReadOnly = true, MinValue = 0, MaxValue = byte.MaxValue}, + new FieldsConfiguration{ Name = "leftSize", Type = "int", SelectValues = null, Category = "family", SubCategory = "general", ReadOnly = true, MinValue = 1, MaxValue = byte.MaxValue}, + new FieldsConfiguration{ Name = "rightSize", Type = "int", SelectValues = null, Category = "family", SubCategory = "general", ReadOnly = true, MinValue = 1, MaxValue = byte.MaxValue}, new FieldsConfiguration{ Name = "tcpTable", Type = "int", SelectValues = null, Category = "family", SubCategory = "tcp", ReadOnly = true, MinValue = 0, MaxValue = byte.MaxValue}, new FieldsConfiguration{ Name = "gamma", Type = "int", SelectValues = null, Category = "family", SubCategory = "gamma", ReadOnly = true, MinValue = 0, MaxValue = byte.MaxValue}, new FieldsConfiguration{ Name = "rotationType", Type = "int", SelectValues = null, Category = "family", SubCategory = "general", ReadOnly = true, MinValue = 0, MaxValue = byte.MaxValue},