From beec03905d424b7a2f142ddd7a5e8d9aed5bf383 Mon Sep 17 00:00:00 2001 From: Lucio Maranta Date: Wed, 16 May 2018 16:01:15 +0000 Subject: [PATCH] Added siemens functions: Update magazine Available tools Max value in config --- CMS_CORE_Application/Form1.cs | 307 +++++++++++------------ CMS_CORE_Library/DataStructures.cs | 22 +- CMS_CORE_Library/Demo/ILibraryService.cs | 4 +- CMS_CORE_Library/Demo/Nc_Demo.cs | 39 ++- CMS_CORE_Library/Fanuc/Nc_Fanuc.cs | 14 +- CMS_CORE_Library/Nc.cs | 10 +- CMS_CORE_Library/Osai/Nc_Osai.cs | 13 +- CMS_CORE_Library/Siemens/Nc_Siemens.cs | 228 +++++++++++++---- CMS_CORE_Library/ToolConfigurations.cs | 7 +- 9 files changed, 407 insertions(+), 237 deletions(-) diff --git a/CMS_CORE_Application/Form1.cs b/CMS_CORE_Application/Form1.cs index c192cfb..44969f9 100644 --- a/CMS_CORE_Application/Form1.cs +++ b/CMS_CORE_Application/Form1.cs @@ -81,8 +81,8 @@ namespace CMS_CORE_Application List dataTable = new List(); List shanks = new List(); List famiies = new List(); - List positions = new List(); - List magazine = new List(); + List positions = new List(); + List magazine = new List(); List multiTools = new List(); List tools = new List(); SiemensToolModel newTool = new SiemensToolModel() @@ -147,162 +147,159 @@ namespace CMS_CORE_Application cmsError = N.NC_RModelName(ref ModelName); bool error = false; string serial = ""; - try - { - while (true) + while (true) + { + sw.Restart(); + cmsError = N.PROC_RMode(1, ref mode); + if (cmsError.IsError()) { - sw.Restart(); - cmsError = N.PROC_RMode(1, ref mode); - if (cmsError.IsError()) - { - error = true; - SetError(Lines, cmsError); - } - cmsError = N.PROC_RStatus(1, ref status); - if (cmsError.IsError()) - { - error = true; - SetError(Lines, cmsError); - } - cmsError = N.PROC_RActiveAlarms(1, ref procAlarms); - if (cmsError.IsError()) - { - error = true; - SetError(Lines, cmsError); - } - cmsError = N.NC_RActiveAlarms(ref ncAlarms); - if (cmsError.IsError()) - { - error = true; - SetError(Lines, cmsError); - } - - cmsError = N.PLC_RActiveMessages(ref Msg); - if (cmsError.IsError()) - { - error = true; - SetError(Lines, cmsError); - } - - cmsError = N.NC_RDateTime(ref NcTime); - if (cmsError.IsError()) - { - error = true; - SetError(Lines, cmsError); - } - - cmsError = N.NC_RSerialNumber(ref serial); - if (cmsError.IsError()) - { - error = true; - SetError(Lines, cmsError); - } - - if (cmsError.IsError()) - { - error = true; - SetError(Lines, cmsError); - } - - N.PLC_RPowerOnData(ref powerOn); - if (cmsError.IsError()) - { - error = true; - SetError(Lines, cmsError); - } - // cmsError = N.TOOLS_WAddShank(ref newShank); - // cmsError = N.TOOLS_WDeleteShank(4); - //cmsError = N.TOOLS_WUpdateEdge(1, ref newEdge); - - //cmsError = N.TOOLS_RConfiguration(ref toolsConfig); - //cmsError = N.PLC_WRefreshAllMessages(); - //cmsError = N.PLC_RHeadsData(headsTest, 1); - - //cmsError = N.TOOLS_WAddEdge(6, ref newEdge); - - - //cmsError = N.TOOLS_RToolsData(ref dataTable); - //cmsError = N.TOOLS_RShanksData(ref shanks); - //cmsError = N.TOOLS_RFamilyData(ref famiies); - //cmsError = N.TOOLS_RMagazinePositions(ref positions); - //cmsError = N.TOOLS_WAddTool(ref newTool); - - //ShankModel shank = new ShankModel(); - //cmsError = N.TOOLS_WAddShank(ref shank); - //FamilyModel family = new FamilyModel - //{ - // Name = "Da demo" - //}; - //cmsError = N.TOOLS_WDeleteTool(11); - //// cmsError = N.TOOLS_WAddFamily(ref family); - //cmsError = N.TOOLS_RConfiguration(ref toolsConfig); - //cmsError = N.TOOLS_WUpdateTool(newTool); - //cmsError = N.TOOLS_RMagazineTools(1, ref magazine); - //cmsError = N.TOOLS_RAvailableTools(ref multiTools, ref tools); - //cmsError = N.TOOLS_WUpdateMagazineTools(1, newMagazine); - // N.PLC_WPowerOnData(6, true); - //N.PLC_RFunctionAccess(ref functionality); - - //N.PLC_RAxesResetData(ref axesReset); - //cmsError = N.PLC_RUserSoftKeys(ref keys); - //cmsError = N.PLC_RNcSoftKeys(ref keys); - - //N.PROC_RSelectedProcess(ref procnum); - //cmsError = N.PLC_WNcSoftKey(1); - //// cmsError = N.PLC_WUserSoftKey(1); - - //N.PROC_RStatusAndData(1, ref processData); - //sw.Restart(); - //cmsError = N.AXES_RAxesNames(1, ref axesNames); - ////cmsError = N.AXES_WSelectAxis(2); - ////N.PROC_WSelectProcess(4); - //cmsError = N.AXES_RSelectedAxis(ref axisId); - ////cmsError = N.PLC_WRefreshAllMessages(); - //cmsError = N.PLC_WHeadOverride(1, HEAD_OVERRIDE_SIGN.MINUS); - - //Dictionary messages = new Dictionary(); - //cmsError = N.NC_GetTranslatedPlcMessages("it", ref messages); - //MessageBox.Show(messages.Count.ToString() + " " + messages.FirstOrDefault()); - ////cmsError = N.PROC_RSelectedProcess(ref procnum); - - sw.Stop(); - if (!this.IsDisposed && this.InvokeRequired) - { - this.Invoke((ThreadStart)delegate () - { - TXTPath1.Text = mode.ToString(); - TXTStat1.Text = status.ToString(); - TXTNProcess.Text = procnum.ToString(); - TXTName.Text = ModelName; - TXTMachNum.Text = MachNumber; - TXTSft.Text = SFTVersion; - TXTTime.Text = sw.ElapsedMilliseconds.ToString() + " mS"; - TXTAlm.Text = String.Join(Environment.NewLine, procAlarms.Select(x => x.Message)); - TXTAlmNc.Text = String.Join(Environment.NewLine, ncAlarms.Select(x => x.Message)); - TXTMsg.Text = String.Join(Environment.NewLine, Msg.Select(x => x.Id)); - TXTPPName.Text = PPName; - TXTNow.Text = NcTime.ToString(); - - if (error == false) - Error.Text = ""; - - TXTPPLines.Text = String.Join(Environment.NewLine, Lines); - Connect.Enabled = false; - Disconnect.Enabled = true; - }); - } - error = false; - - if ((200 - (int)sw.ElapsedMilliseconds) < 0) - Debug.WriteLine("Ritardo " + sw.ElapsedMilliseconds); - - Thread.Sleep(200); + error = true; + SetError(Lines, cmsError); } - } - catch (Exception ex) - { - MessageBox.Show(ex.Message); + cmsError = N.PROC_RStatus(1, ref status); + if (cmsError.IsError()) + { + error = true; + SetError(Lines, cmsError); + } + cmsError = N.PROC_RActiveAlarms(1, ref procAlarms); + if (cmsError.IsError()) + { + error = true; + SetError(Lines, cmsError); + } + cmsError = N.NC_RActiveAlarms(ref ncAlarms); + if (cmsError.IsError()) + { + error = true; + SetError(Lines, cmsError); + } + + cmsError = N.PLC_RActiveMessages(ref Msg); + if (cmsError.IsError()) + { + error = true; + SetError(Lines, cmsError); + } + + cmsError = N.NC_RDateTime(ref NcTime); + if (cmsError.IsError()) + { + error = true; + SetError(Lines, cmsError); + } + + cmsError = N.NC_RSerialNumber(ref serial); + if (cmsError.IsError()) + { + error = true; + SetError(Lines, cmsError); + } + + if (cmsError.IsError()) + { + error = true; + SetError(Lines, cmsError); + } + + N.PLC_RPowerOnData(ref powerOn); + if (cmsError.IsError()) + { + error = true; + SetError(Lines, cmsError); + } + // cmsError = N.TOOLS_WAddShank(ref newShank); + // cmsError = N.TOOLS_WDeleteShank(4); + //cmsError = N.TOOLS_WUpdateEdge(1, ref newEdge); + List a = null; + List b = null; + cmsError = N.TOOLS_RAvailableTools(ref a, ref b); + cmsError = N.TOOLS_RConfiguration(ref toolsConfig); + + cmsError = N.TOOLS_WUnloadToolInMagazine(1, 1); + // cmsError = N.TOOLS_WLoadToolInMagazine(1, new NewToolInMagazineModel() { PositionId = 2, ToolId = 19 }); + //cmsError = N.PLC_WRefreshAllMessages(); + //cmsError = N.PLC_RHeadsData(headsTest, 1); + + // cmsError = N.TOOLS_WAddEdge(24, ref newEdge); + + //cmsError = N.TOOLS_RToolsData(ref dataTable); + //cmsError = N.TOOLS_RShanksData(ref shanks); + //cmsError = N.TOOLS_RFamilyData(ref famiies); + //cmsError = N.TOOLS_RMagazinePositions(ref positions); + //cmsError = N.TOOLS_WAddTool(ref newTool); + + //ShankModel shank = new ShankModel(); + //cmsError = N.TOOLS_WAddShank(ref shank); + //FamilyModel family = new FamilyModel + //{ + // Name = "Da demo" + //}; + //cmsError = N.TOOLS_WDeleteTool(11); + //// cmsError = N.TOOLS_WAddFamily(ref family); + //cmsError = N.TOOLS_RConfiguration(ref toolsConfig); + //cmsError = N.TOOLS_WUpdateTool(newTool); + //cmsError = N.TOOLS_RMagazineTools(1, ref magazine); + //cmsError = N.TOOLS_RAvailableTools(ref multiTools, ref tools); + //cmsError = N.TOOLS_WUpdateMagazineTools(1, newMagazine); + // N.PLC_WPowerOnData(6, true); + //N.PLC_RFunctionAccess(ref functionality); + + //N.PLC_RAxesResetData(ref axesReset); + //cmsError = N.PLC_RUserSoftKeys(ref keys); + //cmsError = N.PLC_RNcSoftKeys(ref keys); + + //N.PROC_RSelectedProcess(ref procnum); + //cmsError = N.PLC_WNcSoftKey(1); + //// cmsError = N.PLC_WUserSoftKey(1); + + //N.PROC_RStatusAndData(1, ref processData); + //sw.Restart(); + //cmsError = N.AXES_RAxesNames(1, ref axesNames); + ////cmsError = N.AXES_WSelectAxis(2); + ////N.PROC_WSelectProcess(4); + //cmsError = N.AXES_RSelectedAxis(ref axisId); + ////cmsError = N.PLC_WRefreshAllMessages(); + //cmsError = N.PLC_WHeadOverride(1, HEAD_OVERRIDE_SIGN.MINUS); + + //Dictionary messages = new Dictionary(); + //cmsError = N.NC_GetTranslatedPlcMessages("it", ref messages); + //MessageBox.Show(messages.Count.ToString() + " " + messages.FirstOrDefault()); + ////cmsError = N.PROC_RSelectedProcess(ref procnum); + + sw.Stop(); + if (!this.IsDisposed && this.InvokeRequired) + { + this.Invoke((ThreadStart)delegate () + { + TXTPath1.Text = mode.ToString(); + TXTStat1.Text = status.ToString(); + TXTNProcess.Text = procnum.ToString(); + TXTName.Text = ModelName; + TXTMachNum.Text = MachNumber; + TXTSft.Text = SFTVersion; + TXTTime.Text = sw.ElapsedMilliseconds.ToString() + " mS"; + TXTAlm.Text = String.Join(Environment.NewLine, procAlarms.Select(x => x.Message)); + TXTAlmNc.Text = String.Join(Environment.NewLine, ncAlarms.Select(x => x.Message)); + TXTMsg.Text = String.Join(Environment.NewLine, Msg.Select(x => x.Id)); + TXTPPName.Text = PPName; + TXTNow.Text = NcTime.ToString(); + + if (error == false) + Error.Text = ""; + + TXTPPLines.Text = String.Join(Environment.NewLine, Lines); + Connect.Enabled = false; + Disconnect.Enabled = true; + }); + } + error = false; + + if ((200 - (int)sw.ElapsedMilliseconds) < 0) + Debug.WriteLine("Ritardo " + sw.ElapsedMilliseconds); + + Thread.Sleep(200); } } diff --git a/CMS_CORE_Library/DataStructures.cs b/CMS_CORE_Library/DataStructures.cs index f4440f5..026d310 100644 --- a/CMS_CORE_Library/DataStructures.cs +++ b/CMS_CORE_Library/DataStructures.cs @@ -485,6 +485,7 @@ namespace CMS_CORE_Library public int LeftSize; public int RightSize; public int MagazinePositionType; + public int MaxChilds; public List ChildsTools; public ShankModel() @@ -520,11 +521,12 @@ namespace CMS_CORE_Library public int ToolType; } - public class PositionsModel + public class PositionModel { - public int Id; + public int PositionId; public int MagazineId; public int Type; + public bool Disabled; } public class EdgeConfigModel @@ -534,19 +536,13 @@ namespace CMS_CORE_Library public int Number; } - public class MagazineAndToolModel - { - public int PositionId; - public int MagazineId; - public int Type; - } - public class PositionWithMultiToolModel : MagazineAndToolModel + public class PositionWithMultiToolModel : PositionModel { public MountedMultiToolModel ChildShank; } - public class PositionWithToolModel : MagazineAndToolModel + public class PositionWithToolModel : PositionModel { public MountedToolModel ChildTool; } @@ -607,6 +603,12 @@ namespace CMS_CORE_Library public class ToolTableConfiguration { + public int MaxTools; + public int MaxEdgesPerTools; + public int MaxToolsPerFamily; + public int MaxMultitools; + public int MaxToolsPerMultitools; + public List Magazines; public List ToolsConfiguration; public FamiliesConfiguration FamiliesConfiguration; diff --git a/CMS_CORE_Library/Demo/ILibraryService.cs b/CMS_CORE_Library/Demo/ILibraryService.cs index 8b288ee..916a162 100644 --- a/CMS_CORE_Library/Demo/ILibraryService.cs +++ b/CMS_CORE_Library/Demo/ILibraryService.cs @@ -210,10 +210,10 @@ namespace Nc_Demo_Application.Server.Service void DeleteShank(string id); [WebGet(UriTemplate = "tool_table/positions", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)] - void GetPositions(out List positionsData); + void GetPositions(out List positionsData); [WebInvoke(Method = "PUT", UriTemplate = "tool_table/position", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)] - void PutPosition(ref PositionsModel position); + void PutPosition(ref PositionModel position); [WebGet(UriTemplate = "tool_table/magazine/{magazineId}", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)] void GetMagazinePositionsWithTools(string magazineId, out List positionsData); diff --git a/CMS_CORE_Library/Demo/Nc_Demo.cs b/CMS_CORE_Library/Demo/Nc_Demo.cs index fc566b9..d924ad3 100644 --- a/CMS_CORE_Library/Demo/Nc_Demo.cs +++ b/CMS_CORE_Library/Demo/Nc_Demo.cs @@ -2137,14 +2137,14 @@ namespace CMS_CORE.Demo } } - public override CmsError TOOLS_RMagazinePositions(ref List positions) + public override CmsError TOOLS_RMagazinePositions(ref List positions) { // Check if the NC Demo is Connected CmsError cmsError = CheckConnection(); if (cmsError.IsError()) return cmsError; - positions = new List(); + positions = new List(); try { // Get position data from demo @@ -2158,7 +2158,7 @@ namespace CMS_CORE.Demo } } - public override CmsError TOOLS_WUpdatePositions(PositionsModel position) + public override CmsError TOOLS_WUpdatePosition(PositionModel position) { // Check if the NC Demo is Connected CmsError cmsError = CheckConnection(); @@ -2178,7 +2178,7 @@ namespace CMS_CORE.Demo } } - public override CmsError TOOLS_RMagazineTools(int magazineId, ref List magazinePos) + public override CmsError TOOLS_RMagazineTools(int magazineId, ref List magazinePos) { // Check if the NC Demo is Connected CmsError cmsError = CheckConnection(); @@ -2187,7 +2187,7 @@ namespace CMS_CORE.Demo try { - magazinePos = new List(); + magazinePos = new List(); // Get tools equipped in the magazine serverService.GetMagazinePositionsWithTools(magazineId.ToString(), out List demoMagazinePositions); @@ -2288,7 +2288,7 @@ namespace CMS_CORE.Demo } } - public override CmsError TOOLS_WUpdateMagazineTools(int magazine, List newMagazine) + public override CmsError TOOLS_WLoadToolInMagazine(int magazine, NewToolInMagazineModel newMagazineTool) { // Check if the NC Demo is Connected CmsError cmsError = CheckConnection(); @@ -2297,7 +2297,7 @@ namespace CMS_CORE.Demo try { - serverService.UpdateMagazine(magazine.ToString(), newMagazine); + serverService.UpdateMagazine(magazine.ToString(), new List { newMagazineTool }); return NO_ERROR; } @@ -2307,6 +2307,31 @@ namespace CMS_CORE.Demo } } + public override CmsError TOOLS_WUnloadToolInMagazine(int magazineId, int positionId) + { + // Check if the NC Demo is Connected + CmsError cmsError = CheckConnection(); + if (cmsError.IsError()) + return cmsError; + + try + { + serverService.UpdateMagazine(magazineId.ToString(), new List { + new NewToolInMagazineModel + { + PositionId = positionId, + ToolId = 0 + } + }); + + return NO_ERROR; + } + catch (Exception ex) + { + return ManageException(ex); + } + } + #endregion ToolTable /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs b/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs index 72881ce..84a8e58 100644 --- a/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs +++ b/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs @@ -1685,7 +1685,7 @@ namespace CMS_CORE.Fanuc return NO_ERROR; } - public override CmsError TOOLS_RMagazinePositions(ref List positions) + public override CmsError TOOLS_RMagazinePositions(ref List positions) { return NO_ERROR; } @@ -1710,7 +1710,7 @@ namespace CMS_CORE.Fanuc return NO_ERROR; } - public override CmsError TOOLS_WUpdatePositions(PositionsModel position) + public override CmsError TOOLS_WUpdatePosition(PositionModel position) { return NO_ERROR; } @@ -1755,7 +1755,7 @@ namespace CMS_CORE.Fanuc return NO_ERROR; } - public override CmsError TOOLS_RMagazineTools(int magazineId, ref List magazinePos) + public override CmsError TOOLS_RMagazineTools(int magazineId, ref List magazinePos) { return NO_ERROR; } @@ -1765,10 +1765,16 @@ namespace CMS_CORE.Fanuc return NO_ERROR; } - public override CmsError TOOLS_WUpdateMagazineTools(int magazine, List newMagazine) + public override CmsError TOOLS_WLoadToolInMagazine(int magazine, NewToolInMagazineModel newMagazineTool) { return NO_ERROR; } + + public override CmsError TOOLS_WUnloadToolInMagazine(int magazineId, int positionId) + { + return NO_ERROR; + } + #endregion Tools Management /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/CMS_CORE_Library/Nc.cs b/CMS_CORE_Library/Nc.cs index 17a10e5..1e13f7f 100644 --- a/CMS_CORE_Library/Nc.cs +++ b/CMS_CORE_Library/Nc.cs @@ -1306,7 +1306,7 @@ namespace CMS_CORE public abstract CmsError TOOLS_RFamilyData(ref List families); - public abstract CmsError TOOLS_RMagazinePositions(ref List positions); + public abstract CmsError TOOLS_RMagazinePositions(ref List positions); public abstract CmsError TOOLS_WAddTool(ref SiemensToolModel tool); @@ -1316,7 +1316,7 @@ namespace CMS_CORE public abstract CmsError TOOLS_WUpdateFamilyData(string oldName, string newName); - public abstract CmsError TOOLS_WUpdatePositions(PositionsModel position); + public abstract CmsError TOOLS_WUpdatePosition(PositionModel position); public abstract CmsError TOOLS_WUpdateTool(SiemensToolModel tool); @@ -1334,11 +1334,13 @@ namespace CMS_CORE public abstract CmsError TOOLS_WUpdateShank(ref ShankModel shank); - public abstract CmsError TOOLS_RMagazineTools(int magazineId, ref List magazinePos); + public abstract CmsError TOOLS_RMagazineTools(int magazineId, ref List magazinePos); public abstract CmsError TOOLS_RAvailableTools(ref List multiTools, ref List tools); - public abstract CmsError TOOLS_WUpdateMagazineTools(int magazine, List newMagazine); + public abstract CmsError TOOLS_WLoadToolInMagazine(int magazine, NewToolInMagazineModel newMagazineTool); + + public abstract CmsError TOOLS_WUnloadToolInMagazine(int magazineId, int positionId); #endregion Tool Table diff --git a/CMS_CORE_Library/Osai/Nc_Osai.cs b/CMS_CORE_Library/Osai/Nc_Osai.cs index 85bde7c..a4b0708 100644 --- a/CMS_CORE_Library/Osai/Nc_Osai.cs +++ b/CMS_CORE_Library/Osai/Nc_Osai.cs @@ -2055,7 +2055,7 @@ namespace CMS_CORE.Osai return NO_ERROR; } - public override CmsError TOOLS_RMagazinePositions(ref List positions) + public override CmsError TOOLS_RMagazinePositions(ref List positions) { return NO_ERROR; } @@ -2080,7 +2080,7 @@ namespace CMS_CORE.Osai return NO_ERROR; } - public override CmsError TOOLS_WUpdatePositions(PositionsModel position) + public override CmsError TOOLS_WUpdatePosition(PositionModel position) { return NO_ERROR; } @@ -2125,7 +2125,7 @@ namespace CMS_CORE.Osai return NO_ERROR; } - public override CmsError TOOLS_RMagazineTools(int magazineId, ref List magazinePos) + public override CmsError TOOLS_RMagazineTools(int magazineId, ref List magazinePos) { return NO_ERROR; } @@ -2135,7 +2135,12 @@ namespace CMS_CORE.Osai return NO_ERROR; } - public override CmsError TOOLS_WUpdateMagazineTools(int magazine, List newMagazine) + public override CmsError TOOLS_WLoadToolInMagazine(int magazine, NewToolInMagazineModel newMagazineTool) + { + return NO_ERROR; + } + + public override CmsError TOOLS_WUnloadToolInMagazine(int magazineId, int positionId) { return NO_ERROR; } diff --git a/CMS_CORE_Library/Siemens/Nc_Siemens.cs b/CMS_CORE_Library/Siemens/Nc_Siemens.cs index e44d666..cae7d80 100644 --- a/CMS_CORE_Library/Siemens/Nc_Siemens.cs +++ b/CMS_CORE_Library/Siemens/Nc_Siemens.cs @@ -79,7 +79,6 @@ namespace CMS_CORE.Siemens // Magazine config parameters private int MAX_TOOL_NUMER; - private int MAX_EDGES_PER_TOOL; private int MAX_TOOLS_PER_FAMILY; private int MAX_MULTITOOLS_NUMBER; @@ -92,9 +91,9 @@ namespace CMS_CORE.Siemens private SiemensEdgesConfiguration AdditionalEdgesParamConfig = new SiemensEdgesConfiguration(); private static List ToolTableData = new List(); - private static List MagazinePositions = new List(); + private static List MagazinePositions = new List(); private static List Multitools = new List(); - private static List MagazineAndTools = new List(); + private static List MagazineAndTools = new List(); public static List Families = new List(); //private static List MountedMultiTools = new List(); @@ -152,11 +151,11 @@ namespace CMS_CORE.Siemens ToolMngmtListGuid = SiemensToolSvc.Subscribe(TOOLS_UpdateToolsData); PopulateToolTable(); } - } + } catch (Exception ex) { return ManageException(ex); - } + } return NO_ERROR; } @@ -506,6 +505,7 @@ namespace CMS_CORE.Siemens SettingMode = new PowerOnDataModel() { Id = 5, Active = bits[4], Clickable = bits[20] }, StartingKey = new PowerOnDataModel() { Id = 6, Active = bits[5], Clickable = bits[21] } }; + // Create and set post power on object PostPowerOnModel postPowerOn = new PostPowerOnModel() { @@ -1217,9 +1217,11 @@ namespace CMS_CORE.Siemens try { //Setup variables - DataSvc Data = new DataSvc(); - Data.Timeout = TimeoutConn; - Data.PriorityFlag = SlPriority.highPriority; + DataSvc Data = new DataSvc + { + Timeout = TimeoutConn, + PriorityFlag = SlPriority.highPriority + }; cmsError = ConvertMemToPath(MemType, MemTable, MemIndex, MemBit, 1, 'X', out string itemString); if (cmsError.IsError()) @@ -1766,6 +1768,12 @@ namespace CMS_CORE.Siemens public override CmsError TOOLS_RConfiguration(ref ToolTableConfiguration config) { + config.MaxTools = MAX_TOOL_NUMER; + config.MaxEdgesPerTools = MAX_EDGES_PER_TOOL; + config.MaxToolsPerFamily = MAX_TOOLS_PER_FAMILY; + config.MaxMultitools = MAX_MULTITOOLS_NUMBER; + config.MaxToolsPerMultitools = MAX_TOOLS_PER_MULTITOOLS; + config.ToolsConfiguration = SiemensToolsConfig; config.FamiliesConfiguration = SiemensFamiliesConfig; config.ShanksConfiguration = SiemensShanksConfig; @@ -1773,7 +1781,7 @@ namespace CMS_CORE.Siemens config.EdgesConfiguration = ToolConfigurations.SiemensEdgesConfiguration; config.EdgesConfiguration.EdgesAdditionalParamsConfiguration = new Dictionary>(); - // Remove path and set only names + // Remove path and set only names as additionalParams foreach (int key in AdditionalEdgesParamConfig.EdgesConfig.Keys) { List tmpNames = new List(); @@ -1781,15 +1789,23 @@ namespace CMS_CORE.Siemens { tmpNames.Add(conf.Name); } + // Set config field config.EdgesConfiguration.EdgesAdditionalParamsConfiguration.Add(key, tmpNames); } - - config.Magazines = new List() + config.Magazines = new List(); + foreach(PositionModel pos in MagazinePositions) { - new MagazineModel{Id = 1, Type = MAGAZINE_TYPE.MAGAZINE}, - new MagazineModel{Id = 2, Type = MAGAZINE_TYPE.MAGAZINE}, - new MagazineModel{Id = 3, Type = MAGAZINE_TYPE.SPINDLE}, - }; + var tmp = config.Magazines.Where(x => x.Id == pos.MagazineId).FirstOrDefault(); + if (tmp == null) + { + config.Magazines.Add(new MagazineModel() + { + Id = pos.MagazineId, + Type = MAGAZINE_TYPE.MAGAZINE + }); + } + } + return NO_ERROR; } @@ -1838,18 +1854,10 @@ namespace CMS_CORE.Siemens itemToRead = new Item("/NC/_N_NC_TEA_ACX/$MN_MAX_TOOLS_PER_MULTITOOL"); dataSvc.Read(itemToRead); MAX_TOOLS_PER_MULTITOOLS = (int)itemToRead.Value; - // Read file string[] toolsStrings = ReadToolTableFile(); // Parse file - CreateToolsFromFileStrings(toolsStrings); - - //for (int i = 1; i < MAX_TOOL_NUMER; i++) - //{ - // SiemensToolModel tmpTool = CreateToolFromId(i, toolsStrings); - // if (tmpTool != null) - // ToolTableData.Add(tmpTool); - //} + PopulateToolsTableFromFileStrings(toolsStrings); } private void TOOLS_UpdateToolsData(Guid guid, ToolInfo[] toolInfos) @@ -1877,18 +1885,20 @@ namespace CMS_CORE.Siemens { case ToolAction.TOOL_DELETED: { + // Find tool SiemensToolModel tool = ToolTableData.SingleOrDefault(t => t.Id == toolInfo.tNo); if (tool != null) + // Remove ToolTableData.Remove(tool); else { + // if tool not exist, find into shanks ShankModel shank = Multitools.SingleOrDefault(t => t.Id == toolInfo.tNo); if (shank != null) Multitools.Remove(shank); } } break; - case ToolAction.TOOL_CREATED: { // string[] toolsStrings = ReadToolTableFile(); @@ -1902,7 +1912,6 @@ namespace CMS_CORE.Siemens } } break; - case ToolAction.TOOL_DATA_CHANGED: { // string[] toolsStrings = ReadToolTableFile(); @@ -1936,7 +1945,10 @@ namespace CMS_CORE.Siemens } break; - case ToolAction.TOOL_MOVED: { } break; + case ToolAction.TOOL_MOVED: + { + + } break; } } catch (Exception ex) @@ -2041,6 +2053,7 @@ namespace CMS_CORE.Siemens byte toolStatus = Convert.ToByte(toolStatusByte.Split('=').LastOrDefault()); + // Find shank, in order to get childs ShankModel oldShank = Multitools.Where(x => x.Id == multitoolId).FirstOrDefault(); // Create shank model @@ -2058,12 +2071,11 @@ namespace CMS_CORE.Siemens InUse = GetBitValue(toolStatus, 8), ChildsTools = oldShank == null ? new List() : oldShank.ChildsTools }; - return shank; } - private void CreateToolsFromFileStrings(string[] toolsStrings) + private void PopulateToolsTableFromFileStrings(string[] toolsStrings) { SiemensEdgesConfiguration toolEdgesConfig = new SiemensEdgesConfiguration(); @@ -2139,7 +2151,7 @@ namespace CMS_CORE.Siemens case "$TC_TP8": { // Get tool status - byte toolStatus = Convert.ToByte(actualString.Split('=').LastOrDefault()); + int toolStatus = Convert.ToInt32(actualString.Split('=').LastOrDefault()); ToolTableData[toolIndex].IsActive = GetBitValue(toolStatus, 1); ToolTableData[toolIndex].InFixedPlace = GetBitValue(toolStatus, 2); @@ -2180,7 +2192,10 @@ namespace CMS_CORE.Siemens case "$TC_MTPN": { // Insert new multitool - Multitools.Add(new ShankModel() { Id = firstId }); + Multitools.Add(new ShankModel() { + Id = firstId, + MaxChilds = Convert.ToInt32(actualString.Split('=').LastOrDefault()) + }); // Update Index multitoolIndex = Multitools.Count - 1; } @@ -2194,13 +2209,13 @@ namespace CMS_CORE.Siemens case "$TC_MTP3": { - Multitools[multitoolIndex].LeftSize = Convert.ToByte(actualString.Split('=').LastOrDefault()); + Multitools[multitoolIndex].LeftSize = Convert.ToInt32(actualString.Split('=').LastOrDefault()); } break; case "$TC_MTP4": { - Multitools[multitoolIndex].RightSize = Convert.ToByte(actualString.Split('=').LastOrDefault()); + Multitools[multitoolIndex].RightSize = Convert.ToInt32(actualString.Split('=').LastOrDefault()); } break; @@ -2362,15 +2377,21 @@ namespace CMS_CORE.Siemens case "$TC_MPP1": { - MagazinePositions.Add(new PositionsModel() + MagazinePositions.Add(new PositionModel() { - Id = secondId, + PositionId = secondId, MagazineId = firstId, Type = Convert.ToInt32(actualString.Split('=').LastOrDefault()) }); } break; - + case "$TC_MPP4": + { + int index = MagazinePositions.FindIndex(x => x.PositionId == secondId && x.MagazineId == x.PositionId); + if( index >= 0) + MagazinePositions[index].Disabled = GetBitValue(Convert.ToInt32(actualString.Split('=').LastOrDefault()), 1); + } + break; case "$TC_MPP6": { int toolId = Convert.ToInt32(actualString.Split('=').LastOrDefault()); @@ -2379,7 +2400,7 @@ namespace CMS_CORE.Siemens // Find tool by id SiemensToolModel tool = ToolTableData.Where(x => x.Id == toolId).FirstOrDefault(); // Find position by id - PositionsModel position = MagazinePositions.Where(x => x.MagazineId == firstId && x.Id == secondId).FirstOrDefault(); + PositionModel position = MagazinePositions.Where(x => x.MagazineId == firstId && x.PositionId == secondId).FirstOrDefault(); if (tool != null) { // Add new Magazine-Tool @@ -2537,6 +2558,7 @@ namespace CMS_CORE.Siemens families = Families; foreach (FamilyModel family in families) { + // Get family childs tools family.ChildTools = ToolTableData .Where(x => x.FamilyName == family.Name) .Select(x => new FamilyChildModel() @@ -2546,6 +2568,7 @@ namespace CMS_CORE.Siemens ToolType = x.ToolType }) .ToList(); + // Set current family child tools family.ChildTools .Sort((p, q) => p.ChildId.CompareTo(q.ChildId)); } @@ -2553,7 +2576,7 @@ namespace CMS_CORE.Siemens return NO_ERROR; } - public override CmsError TOOLS_RMagazinePositions(ref List positions) + public override CmsError TOOLS_RMagazinePositions(ref List positions) { positions = MagazinePositions; @@ -2612,8 +2635,10 @@ namespace CMS_CORE.Siemens return NO_ERROR; } - public override CmsError TOOLS_WAddShank(ref ShankModel shank) + public override CmsError TOOLS_WAddShank( ref ShankModel shank) { + if (shank.MaxChilds > MAX_TOOLS_PER_MULTITOOLS) + return INCORRECT_PARAMETERS_ERROR; try { if (shank.Name.Count() > 32) @@ -2621,7 +2646,7 @@ namespace CMS_CORE.Siemens if (Multitools.Count >= MAX_MULTITOOLS_NUMBER) return INCORRECT_PARAMETERS_ERROR; - + // Find new tool id shank.Id = GetNextToolId(); //Create Shank with NC Pi service @@ -2631,7 +2656,7 @@ namespace CMS_CORE.Siemens piArgs[2] = shank.Name.Trim().PadRight(32); piArgs[3] = "-0001"; // Reserved piArgs[4] = "00000"; // "00000" or “-0001” -> Nc choice / “00001” not allowed - piArgs[5] = "002"; // From "002" to "$MN_MAX_TOOLS_PER_MULTITOOL" // 001 not allowed + piArgs[5] = shank.MaxChilds.ToString().PadLeft(3, '0'); // From "002" to "$MN_MAX_TOOLS_PER_MULTITOOL" // 001 not allowed piArgs[6] = "1"; // “1”..”3” tipo di riconoscimento distanza tra utensili nel multitool piArgs[7] = "_N_TMCRMT"; @@ -2661,14 +2686,14 @@ namespace CMS_CORE.Siemens for (int i = 0; i <= toolIds.Count; i++) { - // If next id is different than previus + 1, there is an empty space + // If next id is different than previus + 1, there is an empty space in the array of numbers if (toolIds[i] + 1 != toolIds[i + 1]) { - // Check if the empty space is a Multitool + // Check if the empty space is a multitool ShankModel shank = Multitools.Where(x => x.Id == (toolIds[i] + 1)).FirstOrDefault(); if (shank == null) { - // Set new id + // return new id return toolIds[i] + 1; } } @@ -2682,8 +2707,24 @@ namespace CMS_CORE.Siemens return NO_ERROR; } - public override CmsError TOOLS_WUpdatePositions(PositionsModel position) + public override CmsError TOOLS_WUpdatePosition(PositionModel position) { + try + { + DataSvc dataSvc = new DataSvc(); + int paramId = (position.PositionId * 11) + 5; + // TC_MTP2 + Item item = new Item() + { + Path = string.Format("/Tool/Magazine/placeData[c{0} , {1}]", position.MagazineId, paramId), + Value = position.Disabled // TODO FIX + }; + } + catch (Exception ex) + { + return ManageException(ex); + } + return NO_ERROR; } @@ -2820,10 +2861,12 @@ namespace CMS_CORE.Siemens public override CmsError TOOLS_WDeleteEdge(int toolId, int edgeId) { + // Find tool var tool = ToolTableData.Where(x => x.Id == toolId).FirstOrDefault(); - + // If tool not exists, return if (tool == null) return INCORRECT_PARAMETERS_ERROR; + // if edge not exists, return if (tool.EdgesData.Where(x => x.Id == edgeId).FirstOrDefault() == null) return INCORRECT_PARAMETERS_ERROR; @@ -2961,7 +3004,7 @@ namespace CMS_CORE.Siemens return NO_ERROR; } - public override CmsError TOOLS_RMagazineTools(int magazineId, ref List magazinePos) + public override CmsError TOOLS_RMagazineTools(int magazineId, ref List magazinePos) { if (magazineId <= 0) return INCORRECT_PARAMETERS_ERROR; @@ -2975,11 +3018,100 @@ namespace CMS_CORE.Siemens public override CmsError TOOLS_RAvailableTools(ref List multiTools, ref List tools) { + List mountedIds = new List(); + // Find ids of tools mounted in the magazines + foreach(var mounted in MagazineAndTools) + { + if(mounted is PositionWithMultiToolModel) // If multitool + { + var tmp = mounted as PositionWithMultiToolModel; + mountedIds.Add(tmp.ChildShank.Id); // Add multitool id + mountedIds.AddRange(tmp.ChildShank.ChildsTools.Select(x => x.Id).ToList()); // Add childsId + } + else if (mounted is PositionWithToolModel) // If tool + { + var tmp = mounted as PositionWithToolModel; + mountedIds.Add(tmp.ChildTool.Id); + } + } + // Filter tools + tools = ToolTableData + .Where(x => !mountedIds.Contains(x.Id)) + .Select(x => new MountedToolModel() + { + Id = x.Id, + FamilyName = x.FamilyName, + ToolType = x.ToolType + }) + .ToList(); + + // Filter multitools + multiTools = Multitools + .Where(x => !mountedIds.Contains(x.Id)) + .Select(x => new MountedMultiToolModel() + { + Id = x.Id, + Name = x.Name, + ChildsTools = x.ChildsTools + }) + .ToList(); + return NO_ERROR; } - public override CmsError TOOLS_WUpdateMagazineTools(int magazine, List newMagazine) + public override CmsError TOOLS_WLoadToolInMagazine(int magazineId, NewToolInMagazineModel newMagazineTool) { + try + { + //Load tool in magazine + string[] piArgs = new string[8]; + piArgs[0] = "/NC"; + piArgs[1] = "401"; + piArgs[2] = newMagazineTool.ToolId.ToString().PadLeft(5, '0'); //Tool ID (> 00000) + piArgs[3] = "00001"; // Manina carico (valore fisso) + piArgs[4] = "09999"; // Magazzino di carico (valore fisso) + piArgs[5] = newMagazineTool.PositionId.ToString().PadLeft(5, '0'); // Manina di destinazione (dove caricare l'utensile) + piArgs[6] = magazineId.ToString().PadLeft(5, '0'); // Magazzino di destinazione (dove caricare l'utensile) + piArgs[7] = "_N_TMMVTL"; + + // Start NC load command + PiSvc pi = new PiSvc(piArgs); + pi.Start(); + + } + catch (Exception ex) + { + return ManageException(ex); + } + + return NO_ERROR; + } + + public override CmsError TOOLS_WUnloadToolInMagazine(int magazineId, int positionId) + { + try + { + //UnLoad tool in magazine + string[] piArgs = new string[8]; + piArgs[0] = "/NC"; + piArgs[1] = "401"; + piArgs[2] = "-0001"; // Tool ID (Fixed, no ID) + piArgs[3] = positionId.ToString().PadLeft(5, '0'); // Manina carico (valore fisso) + piArgs[4] = magazineId.ToString().PadLeft(5, '0'); // Magazzino di carico (valore fisso) + piArgs[5] = "00001"; //Manina carico (valore fisso) + piArgs[6] = "09999"; // Magazzino da cui scaricare l'utensile + piArgs[7] = "_N_TMMVTL"; + + // Start NC load command + PiSvc pi = new PiSvc(piArgs); + pi.Start(); + + } + catch (Exception ex) + { + return ManageException(ex); + } + return NO_ERROR; } diff --git a/CMS_CORE_Library/ToolConfigurations.cs b/CMS_CORE_Library/ToolConfigurations.cs index 3f31cc1..4e6a82c 100644 --- a/CMS_CORE_Library/ToolConfigurations.cs +++ b/CMS_CORE_Library/ToolConfigurations.cs @@ -131,9 +131,10 @@ namespace CMS_CORE_Library public static List SiemensMagazinePosConfig = new List() { - new FieldsConfiguration{Name = "magazineId", Type = "int", SelectValues = null, Category = "general", ReadOnly = true }, - new FieldsConfiguration{Name = "id", Type = "int", SelectValues = null, Category = "general", ReadOnly = true }, - new FieldsConfiguration{Name = "type", Type = "int", SelectValues = null, Category = "general", ReadOnly = false } + new FieldsConfiguration{Name = "magazineId", Type = "int", SelectValues = null, Category = "general", ReadOnly = true }, + new FieldsConfiguration{Name = "positionId", Type = "int", SelectValues = null, Category = "general", ReadOnly = true }, + new FieldsConfiguration{Name = "type", Type = "int", SelectValues = null, Category = "general", ReadOnly = true }, + new FieldsConfiguration{Name = "disabled", Type = "bool", SelectValues = null, Category = "general", ReadOnly = true }, }; public static EdgesConfiguration SiemensEdgesConfiguration = new EdgesConfiguration()