From 2cf7a329876b46563eec8893a22fae69c30b74c6 Mon Sep 17 00:00:00 2001 From: Lucio Maranta Date: Tue, 4 Jun 2019 15:20:21 +0000 Subject: [PATCH] Added real length real radius --- CMS_CORE_Application/Form1.cs | 194 +++++++++++++------------ CMS_CORE_Library/Demo/Nc_Demo.cs | 5 +- CMS_CORE_Library/Fanuc/Nc_Fanuc.cs | 8 +- CMS_CORE_Library/Models/NcToolModel.cs | 3 + CMS_CORE_Library/Nc.cs | 2 +- CMS_CORE_Library/Osai/Nc_Osai.cs | 10 +- CMS_CORE_Library/Siemens/Nc_Siemens.cs | 3 +- CMS_CORE_Library/ToolConfigurations.cs | 10 +- 8 files changed, 129 insertions(+), 106 deletions(-) diff --git a/CMS_CORE_Application/Form1.cs b/CMS_CORE_Application/Form1.cs index f1045ae..9fd9094 100644 --- a/CMS_CORE_Application/Form1.cs +++ b/CMS_CORE_Application/Form1.cs @@ -7,8 +7,6 @@ using CMS_CORE_Library.Siemens; using System; using System.Collections.Generic; using System.Diagnostics; -using System.Globalization; -using System.IO; using System.Linq; using System.Threading; using System.Windows.Forms; @@ -54,108 +52,114 @@ namespace CMS_CORE_Application private void ReadBasicData() { - PROC_MODE mode = PROC_MODE.AUTO; - PROC_STATUS status = PROC_STATUS.ERROR; - ushort procnum = 0; - string MachNumber = ""; - string ModelName = ""; - string SFTVersion = ""; - string PPName = ""; - DateTime NcTime = new DateTime(); - Dictionary Axes = new Dictionary(); - Dictionary messages = new Dictionary(); - Stopwatch sw = new Stopwatch(); - List procAlarms = new List(); - List plcMsg = new List(); - PreAndPostPowerOnModel powerOn = new PreAndPostPowerOnModel(); - List ncAlarms = new List(); - List Lines = new List(); - List < HeadDataModel> Heads = new List(); - - N = SetNcByType(); - - CmsError cmsError = N.NC_Connect(); - MessageBox.Show(cmsError.localizationKey); - cmsError = N.NC_RModelName(ref ModelName); - List val = new List(); - - bool error = false; - string serial = ""; - - while (true) + try { - /////////////////////////////////// Load basic data - cmsError = N.PROC_RMode(1, ref mode); - if (cmsError.IsError()) { error = true; SetError(Lines, cmsError); } + PROC_MODE mode = PROC_MODE.AUTO; + PROC_STATUS status = PROC_STATUS.ERROR; + ushort procnum = 0; + string MachNumber = ""; + string ModelName = ""; + string SFTVersion = ""; + string PPName = ""; + DateTime NcTime = new DateTime(); + Dictionary Axes = new Dictionary(); + Dictionary messages = new Dictionary(); + Stopwatch sw = new Stopwatch(); + List procAlarms = new List(); + List plcMsg = new List(); + PreAndPostPowerOnModel powerOn = new PreAndPostPowerOnModel(); + List ncAlarms = new List(); + List Lines = new List(); + List Heads = new List(); - cmsError = N.PROC_RStatus(1, ref status); - if (cmsError.IsError()) { error = true; SetError(Lines, cmsError); } + N = SetNcByType(); - cmsError = N.PROC_RActiveAlarms(1, ref procAlarms); - if (cmsError.IsError()) { error = true; SetError(Lines, cmsError); } + CmsError cmsError = N.NC_Connect(); + MessageBox.Show(cmsError.localizationKey); + cmsError = N.NC_RModelName(ref ModelName); + List val = new List(); - cmsError = N.NC_RActiveAlarms(ref ncAlarms); - if (cmsError.IsError()) { error = true; SetError(Lines, cmsError); } + bool error = false; + string serial = ""; - cmsError = N.PLC_RActiveMessages(ref plcMsg); - if (cmsError.IsError()) { error = true; SetError(Lines, cmsError); } - - cmsError = N.NC_RDateTime(ref NcTime); - if (cmsError.IsError()) { error = true; SetError(Lines, cmsError); } - - cmsError = N.PLC_RHeadsData(Heads,3); - if (cmsError.IsError()) { error = true; SetError(Lines, cmsError); } - - - cmsError = N.NC_RSerialNumber(ref serial); - if (cmsError.IsError()){ error = true; SetError(Lines, cmsError); } - Dictionary dictionary = new Dictionary(); - cmsError = N.NC_GetTranslatedPlcMessages("it", ref dictionary); - List b = new List(); - - N.PLC_ROperatorInputIsNeeded(ref b); - - ////////////////////////////////////////////////////////////// TEST - Stopwatch st = new Stopwatch(); - sw.Restart(); - - cmsError = N.NC_WMDICommand(1, "X0"); - - sw.Stop(); - Console.WriteLine(sw.ElapsedMilliseconds); - - ////////////////////////////////////////////////////////////// END TEST - if (!this.IsDisposed && this.InvokeRequired) + while (true) { - this.Invoke((ThreadStart)delegate () + /////////////////////////////////// Load basic data + 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 plcMsg); + if (cmsError.IsError()) { error = true; SetError(Lines, cmsError); } + + cmsError = N.NC_RDateTime(ref NcTime); + if (cmsError.IsError()) { error = true; SetError(Lines, cmsError); } + + cmsError = N.PLC_RHeadsData(Heads, 3); + if (cmsError.IsError()) { error = true; SetError(Lines, cmsError); } + + cmsError = N.NC_RSerialNumber(ref serial); + if (cmsError.IsError()) { error = true; SetError(Lines, cmsError); } + Dictionary dictionary = new Dictionary(); + cmsError = N.NC_GetTranslatedPlcMessages("it", ref dictionary); + List b = new List(); + + N.PLC_ROperatorInputIsNeeded(ref b); + + ////////////////////////////////////////////////////////////// TEST + Stopwatch st = new Stopwatch(); + sw.Restart(); + + cmsError = N.NC_WMDICommand(1, "X0"); + + sw.Stop(); + Console.WriteLine(sw.ElapsedMilliseconds); + + ////////////////////////////////////////////////////////////// END TEST + if (!this.IsDisposed && this.InvokeRequired) { - 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, plcMsg.Select(x => x.Id)); - TXTPPName.Text = PPName; - TXTNow.Text = NcTime.ToString(); + 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, plcMsg.Select(x => x.Id)); + TXTPPName.Text = PPName; + TXTNow.Text = NcTime.ToString(); - if (error == false) - Error.Text = ""; + if (error == false) + Error.Text = ""; - TXTPPLines.Text = string.Join(Environment.NewLine, Lines); - Connect.Enabled = false; - Disconnect.Enabled = true; - }); + 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(50); } - error = false; - - if ((200 - (int)sw.ElapsedMilliseconds) < 0) - Debug.WriteLine("Ritardo " + sw.ElapsedMilliseconds); - - Thread.Sleep(50); + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); } } @@ -226,7 +230,7 @@ namespace CMS_CORE_Application if (t != null) t.Abort(); - if(N != null) + if (N != null) N.NC_Disconnect(); } diff --git a/CMS_CORE_Library/Demo/Nc_Demo.cs b/CMS_CORE_Library/Demo/Nc_Demo.cs index c5dcbb1..ed5d7ae 100644 --- a/CMS_CORE_Library/Demo/Nc_Demo.cs +++ b/CMS_CORE_Library/Demo/Nc_Demo.cs @@ -3324,7 +3324,7 @@ namespace CMS_CORE_Library.Demo return NO_ERROR; } - public override CmsError TOOLS_WOffset(short offsetId, OffsetModel offset) + public override CmsError TOOLS_WOffset(short offsetId, ref OffsetModel offset) { offset.Id = offsetId; @@ -3342,6 +3342,9 @@ namespace CMS_CORE_Library.Demo return ManageException(ex); } + offset.RealLength = offset.Length + offset.WearLength; + offset.RealRadius = offset.RealRadius + offset.WearRadius; + return NO_ERROR; } diff --git a/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs b/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs index 53ce562..a28a9ae 100644 --- a/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs +++ b/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs @@ -3509,10 +3509,13 @@ namespace CMS_CORE_Library.Fanuc } } + offset.RealLength = Math.Round(offset.Length + offset.WearLength, 5); + offset.RealRadius = Math.Round(offset.Radius + offset.WearRadius, 5); + return NO_ERROR; } - public override CmsError TOOLS_WOffset(short offsetId, OffsetModel offset) + public override CmsError TOOLS_WOffset(short offsetId, ref OffsetModel offset) { // Check if the NC is Connected CmsError cmsError = CheckConnection(); @@ -3555,6 +3558,9 @@ namespace CMS_CORE_Library.Fanuc short nReturn = Focas1.cnc_wrtofs(nLibHandle[0], offsetId, i, 8, valueToWrite); if (nReturn != 0) return GetNcError(nReturn); + + offset.RealLength = Math.Round(offset.Length + offset.WearLength, 5); + offset.RealRadius = Math.Round(offset.Radius + offset.WearRadius, 5); } return NO_ERROR; diff --git a/CMS_CORE_Library/Models/NcToolModel.cs b/CMS_CORE_Library/Models/NcToolModel.cs index 75b145e..8e27750 100644 --- a/CMS_CORE_Library/Models/NcToolModel.cs +++ b/CMS_CORE_Library/Models/NcToolModel.cs @@ -28,6 +28,9 @@ namespace CMS_CORE_Library.Models public double WearRadius { get; set; } public string UnitOfMeasure { get; set; } + + public double RealLength { get; set; } + public double RealRadius { get; set; } } public class NcShankModel diff --git a/CMS_CORE_Library/Nc.cs b/CMS_CORE_Library/Nc.cs index 42dc494..80e7462 100644 --- a/CMS_CORE_Library/Nc.cs +++ b/CMS_CORE_Library/Nc.cs @@ -1674,7 +1674,7 @@ namespace CMS_CORE_Library public abstract CmsError TOOLS_ROffset(short offsetId, ref OffsetModel offset); - public abstract CmsError TOOLS_WOffset(short offsetId, OffsetModel offset); + public abstract CmsError TOOLS_WOffset(short offsetId, ref OffsetModel offset); public abstract CmsError TOOLS_WStartEditData(); diff --git a/CMS_CORE_Library/Osai/Nc_Osai.cs b/CMS_CORE_Library/Osai/Nc_Osai.cs index 6fbe32a..6ecbcb4 100644 --- a/CMS_CORE_Library/Osai/Nc_Osai.cs +++ b/CMS_CORE_Library/Osai/Nc_Osai.cs @@ -3600,6 +3600,9 @@ namespace CMS_CORE_Library.Osai offset.Length = Math.Round(offsetData.LenVal[0].ValOrig / divider, 5); offset.WearLength = Math.Round(offsetData.LenVal[0].ActChangeVal / divider, 5); offset.UnitOfMeasure = unitOfMeasure; + + offset.RealLength = Math.Round(offset.Length + offset.WearLength, 5); + offset.RealRadius = Math.Round(offset.Radius + offset.WearRadius, 5); } catch (Exception ex) { @@ -3609,7 +3612,7 @@ namespace CMS_CORE_Library.Osai return NO_ERROR; } - public override CmsError TOOLS_WOffset(short offsetId, OffsetModel offset) + public override CmsError TOOLS_WOffset(short offsetId, ref OffsetModel offset) { //Check if the NC is Connected CmsError cmsError = CheckConnection(); @@ -3634,11 +3637,12 @@ namespace CMS_CORE_Library.Osai offsetData.DiaVal[0].ActChangeVal = offset.WearRadius * divider; offsetData.LenVal[0].ValOrig = offset.Length * divider; offsetData.LenVal[0].ActChangeVal = offset.WearLength * divider; - - nReturn = OpenNC.SetOffsetTabRecordII((uint)offsetId, offsetData, out errorClass, out errorNum); if (errorClass != 0 || errorNum != 0 || nReturn == 0) return GetNCError(errorClass, errorNum); + + offset.RealLength = Math.Round(offset.Length + offset.WearLength, 5); + offset.RealRadius = Math.Round(offset.Radius + offset.WearRadius, 5); } catch (Exception ex) { diff --git a/CMS_CORE_Library/Siemens/Nc_Siemens.cs b/CMS_CORE_Library/Siemens/Nc_Siemens.cs index b5b849b..fa0bd15 100644 --- a/CMS_CORE_Library/Siemens/Nc_Siemens.cs +++ b/CMS_CORE_Library/Siemens/Nc_Siemens.cs @@ -664,6 +664,7 @@ namespace CMS_CORE_Library.Siemens try { FileSvc fileSvc = new FileSvc(); + var a = fileSvc.ReadMdaBuffer(1); fileSvc.WriteMdaBuffer(processId, mdiString); } catch(Exception ex) @@ -4262,7 +4263,7 @@ namespace CMS_CORE_Library.Siemens return FUNCTION_NOT_ALLOWED_ERROR; } - public override CmsError TOOLS_WOffset(short offsetId, OffsetModel offset) + public override CmsError TOOLS_WOffset(short offsetId, ref OffsetModel offset) { return FUNCTION_NOT_ALLOWED_ERROR; } diff --git a/CMS_CORE_Library/ToolConfigurations.cs b/CMS_CORE_Library/ToolConfigurations.cs index b136e98..38e0ba9 100644 --- a/CMS_CORE_Library/ToolConfigurations.cs +++ b/CMS_CORE_Library/ToolConfigurations.cs @@ -250,8 +250,8 @@ namespace CMS_CORE_Library new FieldsConfiguration{ Name = "id", Type = "int", SelectValues = null, Category = "general", ReadOnly = true, MinValue = 0, MaxValue = 0}, new FieldsConfiguration{ Name = "name", Type = "string", SelectValues = null, Category = "general", ReadOnly = false, MinValue = 0, MaxValue = 0}, new FieldsConfiguration{ Name = "toolType", Type = "select", SelectValues = toolTypeCodeList, Category = "general", ReadOnly = false, MinValue = 0, MaxValue = byte.MaxValue}, - new FieldsConfiguration{ Name = "leftSize", Type = "int", SelectValues = null, Category = "magazine", ReadOnly = false, MinValue = 1, MaxValue = byte.MaxValue}, - new FieldsConfiguration{ Name = "rightSize", Type = "int", SelectValues = null, Category = "magazine", ReadOnly = false, MinValue = 1, MaxValue = byte.MaxValue}, + new FieldsConfiguration{ Name = "leftSize", Type = "int", SelectValues = null, Category = "shankOpt", ReadOnly = false, MinValue = 1, MaxValue = byte.MaxValue}, + new FieldsConfiguration{ Name = "rightSize", Type = "int", SelectValues = null, Category = "shankOpt", ReadOnly = false, MinValue = 1, MaxValue = byte.MaxValue}, new FieldsConfiguration{ Name = "tcpTable", Type = "int", SelectValues = null, Category = "tcp", ReadOnly = false, MinValue = 0, MaxValue = byte.MaxValue}, new FieldsConfiguration{ Name = "gamma", Type = "int", SelectValues = null, Category = "gamma", ReadOnly = false, MinValue = 0, MaxValue = byte.MaxValue}, new FieldsConfiguration{ Name = "rotationType", Type = "select", SelectValues = cmsRotationTypeList, Category = "general", ReadOnly = false, MinValue = 0, MaxValue = byte.MaxValue}, @@ -345,11 +345,13 @@ namespace CMS_CORE_Library EdgeConfiguration = new List() { new FieldsConfiguration{Name = "id", Type = "int", SelectValues = null, Category = "general", ReadOnly = true, MinValue = 0, MaxValue = 0 }, - new FieldsConfiguration{Name = "unitOfMeasure", Type = "string", SelectValues = null, Category = "general", ReadOnly = true, MinValue = 0, MaxValue = 0 }, + new FieldsConfiguration{Name = "unitOfMeasure", Type = "string", SelectValues = null, Category = "general", ReadOnly = true, MinValue = 0, MaxValue = 0 }, new FieldsConfiguration{Name = "length", Type = "double", SelectValues = null, Category = "general", ReadOnly = false, MinValue = 0, MaxValue = int.MaxValue }, new FieldsConfiguration{Name = "radius", Type = "double", SelectValues = null, Category = "general", ReadOnly = false, MinValue = 0, MaxValue = int.MaxValue }, new FieldsConfiguration{Name = "wearLength", Type = "double", SelectValues = null, Category = "general", ReadOnly = false, MinValue = int.MinValue, MaxValue = int.MaxValue }, - new FieldsConfiguration{Name = "wearRadius", Type = "double", SelectValues = null, Category = "general", ReadOnly = false, MinValue = int.MinValue, MaxValue = int.MaxValue } + new FieldsConfiguration{Name = "wearRadius", Type = "double", SelectValues = null, Category = "general", ReadOnly = false, MinValue = int.MinValue, MaxValue = int.MaxValue }, + new FieldsConfiguration{Name = "realLength", Type = "double", SelectValues = null, Category = "general", ReadOnly = true, MinValue = int.MinValue, MaxValue = int.MaxValue } + new FieldsConfiguration{Name = "realRadius", Type = "double", SelectValues = null, Category = "general", ReadOnly = true, MinValue = int.MinValue, MaxValue = int.MaxValue }, }, EdgesAdditionalParamsConfiguration = new Dictionary>() // Set value runtime, based on NC vendor };