diff --git a/CMS_CORE_Application/Form1.cs b/CMS_CORE_Application/Form1.cs index dd9f1b9..e4d7ef2 100644 --- a/CMS_CORE_Application/Form1.cs +++ b/CMS_CORE_Application/Form1.cs @@ -208,7 +208,7 @@ namespace CMS_CORE_Application error = true; SetError(Lines, cmsError); } - + // cmsError = N.TOOLS_WAddShank(ref newShank); // List a = new List() ; // N.TOOLS_RMagazineTools(1, ref a); @@ -518,15 +518,24 @@ namespace CMS_CORE_Application private void writeFileBtn_Click(object sender, EventArgs e) { - using (FileStream fileStream = new FileStream("C:\\test.csv", FileMode.OpenOrCreate)) + //using (FileStream fileStream = new FileStream("C:\\test.csv", FileMode.OpenOrCreate)) + //{ + // CmsError cms = N.FILES_WProgramFromFile(@"test\\OEM\\CMS\\SYS\\STEP\\Tools.csv", fileStream); + // if (cms.IsError()) + // { + // MessageBox.Show(cms.localizationKey); + // } + //} + List obj = new List() { - CmsError cms = N.FILES_WProgramFromFile(@"test\\OEM\\CMS\\SYS\\STEP\\Tools.csv", fileStream); - if (cms.IsError()) - { - MessageBox.Show(cms.localizationKey); - } + new OffsetModel() { Id = 22, Length = 44, Radius = 44, WearLength = 44, WearRadius = 33 }, + new OffsetModel{ Id = 22, Length = 44, Radius = 44, WearLength = 44, WearRadius = 33 } + }; + CmsError cms = N.TOOLS_WUpdateTool(obj); + if (cms.IsError()) + { + MessageBox.Show(cms.localizationKey); } - } private void readFileBtn_Click(object sender, EventArgs e) diff --git a/CMS_CORE_Library/Demo/Nc_Demo.cs b/CMS_CORE_Library/Demo/Nc_Demo.cs index 39fd774..a6cd6eb 100644 --- a/CMS_CORE_Library/Demo/Nc_Demo.cs +++ b/CMS_CORE_Library/Demo/Nc_Demo.cs @@ -2488,6 +2488,10 @@ namespace CMS_CORE.Demo return NO_ERROR; } + public override CmsError TOOLS_WUpdateTool(List list) + { + return NO_ERROR; + } #endregion Nc Tool Manager /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs b/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs index dc1ca41..59d340b 100644 --- a/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs +++ b/CMS_CORE_Library/Fanuc/Nc_Fanuc.cs @@ -1821,6 +1821,11 @@ namespace CMS_CORE.Fanuc { return NO_ERROR; } + + public override CmsError TOOLS_WUpdateTool(List list) + { + return NO_ERROR; + } #endregion Nc Tool Manager /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/CMS_CORE_Library/Nc.cs b/CMS_CORE_Library/Nc.cs index 9d020d0..743bd70 100644 --- a/CMS_CORE_Library/Nc.cs +++ b/CMS_CORE_Library/Nc.cs @@ -1527,6 +1527,8 @@ namespace CMS_CORE public abstract CmsError TOOLS_WAddTool(); + public abstract CmsError TOOLS_WUpdateTool(List list); + #endregion Nc Tool Manager /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/CMS_CORE_Library/Osai/Nc_Osai.cs b/CMS_CORE_Library/Osai/Nc_Osai.cs index b54c9de..6365457 100644 --- a/CMS_CORE_Library/Osai/Nc_Osai.cs +++ b/CMS_CORE_Library/Osai/Nc_Osai.cs @@ -1903,7 +1903,7 @@ namespace CMS_CORE.Osai return NO_ERROR; } - private CmsError FILES_RProgram(string partProgramPath, ref string partProgramContent) + private CmsError FILES_RProgram(string filePath, ref string fileContent) { //Check if the NC is Connected CmsError cmsError = CheckConnection(); @@ -1917,13 +1917,16 @@ namespace CMS_CORE.Osai try { // Get part program file size - nReturn = OpenNC.LogFSGetFileSize(partProgramPath, out size, out errorClass, out errorNum); + nReturn = OpenNC.LogFSGetFileSize(filePath, out size, out errorClass, out errorNum); //If there's an error launch exception if (errorClass != 0 || errorNum != 0 || nReturn == 0) return GetNCError(errorClass, errorNum); - // Read part program content - nReturn = OpenNC.GetFile(partProgramPath, ref size, out partProgramContent, out errorClass, out errorNum); + // Read file content + // nReturn = OpenNC.GetFile(filePath, ref size, out fileContentContent, out errorClass, out errorNum); + nReturn = OpenNC.GetBinaryFile(filePath, size, out byte[] data, out errorClass, out errorNum); + // Convert byte[] into string + fileContent = Encoding.UTF8.GetString(data); //If there's an error launch exception if (errorClass != 0 || errorNum != 0 || nReturn == 0) @@ -2329,38 +2332,81 @@ namespace CMS_CORE.Osai CmsError cmsError = CheckConnection(); if (cmsError.IsError()) return cmsError; - - List siemens = new List() {new OffsetModel(){Id = 22, Length = 33, Radius = 44, WearLength = 11, WearRadius =5432 } }; - // Generate tool data csv string - string csvToolData = GenerateModelCsv(siemens); + List siemens = new List() { new OffsetModel() { Id = 22, Length = 33, Radius = 44, WearLength = 11, WearRadius = 5432 } }; string filePath = TOOL_MANAGER_DIRECTORY_PATH + TOOLS_FILE_NAME + ".csv"; try { - Stopwatch sw = new Stopwatch(); - sw.Start(); + // Update file + cmsError = UpdateToolManagerFile(filePath, siemens); + if (cmsError.IsError()) + return cmsError; + + } + catch (Exception ex) + { + return ManageException(ex); + } + + return NO_ERROR; + } + + public override CmsError TOOLS_WUpdateTool(List list) + { + //Check if the NC is Connected + CmsError cmsError = CheckConnection(); + if (cmsError.IsError()) + return cmsError; + + string filePath = TOOL_MANAGER_DIRECTORY_PATH + TOOLS_FILE_NAME + ".csv"; + + try + { + // Update file + cmsError = UpdateToolManagerFile(filePath, list); + if (cmsError.IsError()) + return cmsError; + + } + catch (Exception ex) + { + return ManageException(ex); + } + + return NO_ERROR; + } + + private CmsError UpdateToolManagerFile(string filePath, List objs) where T : class + { + //Check if the NC is Connected + CmsError cmsError = CheckConnection(); + if (cmsError.IsError()) + return cmsError; + + try + { + Stopwatch sw = new Stopwatch();sw.Start(); + + List lines = new List(); + + // Convert data in a csv string + string csvContent = GenerateModelCsv(objs); + lines.Add(csvContent); + + // Write into local file + File.WriteAllLines("C:\\test.csv", lines); + + // Update file using (FileStream fileStream = new FileStream("C:\\test.csv", FileMode.OpenOrCreate)) { - // Read tool file - cmsError = FILES_RProgramToFile(filePath, fileStream); + // Write NcFile + cmsError = FILES_WProgramFromFile(filePath, fileStream); if (cmsError.IsError()) return cmsError; } - using (FileStream fileStream = new FileStream("C:\\test.csv", FileMode.OpenOrCreate)) - { - using (StreamWriter writer = new StreamWriter(fileStream)) - { - // Write local file - writer.WriteLine(csvToolData); - // Write NcFile - cmsError = FILES_WProgramFromFile(filePath, fileStream); - if (cmsError.IsError()) - return cmsError; - } - } Console.WriteLine("Scrivere tool: " + sw.ElapsedMilliseconds); } catch (Exception ex) @@ -2386,7 +2432,7 @@ namespace CMS_CORE.Osai .Select(n => n?.ToString()) .Aggregate((a, b) => a + delimiter + b); - sw.Write(row); + sw.WriteLine(row); } output = sw.ToString(); } diff --git a/CMS_CORE_Library/Siemens/Nc_Siemens.cs b/CMS_CORE_Library/Siemens/Nc_Siemens.cs index e2a6c2a..694ac48 100644 --- a/CMS_CORE_Library/Siemens/Nc_Siemens.cs +++ b/CMS_CORE_Library/Siemens/Nc_Siemens.cs @@ -2891,14 +2891,19 @@ namespace CMS_CORE.Siemens public override CmsError TOOLS_WStopEdit() { - return NO_ERROR; + return FUNCTION_NOT_ALLOWED_ERROR; } public override CmsError TOOLS_WAddTool() { - return NO_ERROR; + return FUNCTION_NOT_ALLOWED_ERROR; } - + + public override CmsError TOOLS_WUpdateTool(List list) + { + return FUNCTION_NOT_ALLOWED_ERROR; + } + #endregion Nc Tool Manager /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -3354,29 +3359,30 @@ namespace CMS_CORE.Siemens // 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(); + //// 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(); - } + // // 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() { @@ -3385,7 +3391,7 @@ namespace CMS_CORE.Siemens OriginPosition = Convert.ToInt32(magazineValue[sourcePosIndex].Value), DestinationMagazine = Convert.ToInt32(magazineValue[destinationMagIndex].Value), DestinationPosition = Convert.ToInt32(magazineValue[destinationPosIndex].Value), - Tool = tool ?? new MagazineActionToolModel() + Tool = null // tool ?? new MagazineActionToolModel() }; } break;