From 69c20d683cdf02eb191ab7840e9ef6018b177146 Mon Sep 17 00:00:00 2001 From: TomKovac <61820360+TomKovac@users.noreply.github.com> Date: Tue, 13 Feb 2024 18:57:48 +0100 Subject: [PATCH] generating hwid so as the io address changed to optionally switch on and off using parameter (#10) --- src/tia2ax/V18_0/ApiResolver/ApiWrapper.cs | 10 ++++++---- src/tia2ax/V18_0/Program.cs | 9 ++++++--- src/tia2ax/V18_0/Tia2AxServices.cs | 4 ++-- src/tia2ax/V19_0/ApiResolver/ApiWrapper.cs | 10 ++++++---- src/tia2ax/V19_0/Program.cs | 9 ++++++--- src/tia2ax/V19_0/Tia2AxServices.cs | 4 ++-- src/tia2axtool/Program.cs | 7 +++++-- src/tia2axtool/Properties/launchSettings.json | 2 +- tests/V18/tia2axIntegrationTests/Integration.cs | 2 +- tests/V19/tia2axIntegrationTests/Integration.cs | 2 +- 10 files changed, 36 insertions(+), 23 deletions(-) diff --git a/src/tia2ax/V18_0/ApiResolver/ApiWrapper.cs b/src/tia2ax/V18_0/ApiResolver/ApiWrapper.cs index 4313b15..aca87e3 100644 --- a/src/tia2ax/V18_0/ApiResolver/ApiWrapper.cs +++ b/src/tia2ax/V18_0/ApiResolver/ApiWrapper.cs @@ -716,7 +716,7 @@ public bool IsNewHardwareId(string name, IList HwIdentifiers) /// /// Export all PLCs /// - public void ExportAllPLCs(string exportDirectory, bool hwidOnly, ProjectItem projectItem) + public void ExportAllPLCs(string exportDirectory, bool IO, bool HWID, ProjectItem projectItem) { DeleteFolder(exportDirectory); Directory.CreateDirectory(exportDirectory); @@ -725,7 +725,7 @@ public void ExportAllPLCs(string exportDirectory, bool hwidOnly, ProjectItem pro string exportDir = String.IsNullOrEmpty(exportDirectory) ? Path.Combine(Environment.CurrentDirectory, plcItem.Name) : Path.Combine(exportDirectory, plcItem.Name); Directory.CreateDirectory(exportDir); - if (!hwidOnly) + if (IO) { ExportMappingItems(plcItem, exportDir, ExportItemType.HwInput); ExportMappingItems(plcItem, exportDir, ExportItemType.HwOutput); @@ -736,8 +736,10 @@ public void ExportAllPLCs(string exportDirectory, bool hwidOnly, ProjectItem pro ExportConfiguration(exportDir); ExportProgram(exportDir); } - - ExportHwIdentifiers(plcItem, exportDir); + if (HWID) + { + ExportHwIdentifiers(plcItem, exportDir); + } } } diff --git a/src/tia2ax/V18_0/Program.cs b/src/tia2ax/V18_0/Program.cs index acbb03b..eb8a93c 100644 --- a/src/tia2ax/V18_0/Program.cs +++ b/src/tia2ax/V18_0/Program.cs @@ -44,7 +44,7 @@ private static void GoAhead(Options options) var creator = new Tia2AxServices(traceWriter, apiWrapper); creator.OpenProject(options.TiaSourceProject); - creator.GetPlcList(options.OutputProjectFolder,options.HwIdOnly); + creator.GetPlcList(options.OutputProjectFolder, options.IO, options.HwId); } } @@ -60,8 +60,11 @@ internal class Options HelpText = "Output project folder where generator emits result.")] public string OutputProjectFolder { get; set; } - [Option('h', "hwid-only", Required = false, HelpText = "Export only hardware idntifiers")] - public bool HwIdOnly { get; set; } + [Option('i', "io", Required = false, HelpText = "Export IO addresses")] + public bool IO { get; set; } + + [Option('h', "hwid", Required = false, HelpText = "Export hardware identifiers")] + public bool HwId { get; set; } } diff --git a/src/tia2ax/V18_0/Tia2AxServices.cs b/src/tia2ax/V18_0/Tia2AxServices.cs index aff7853..08dffe7 100644 --- a/src/tia2ax/V18_0/Tia2AxServices.cs +++ b/src/tia2ax/V18_0/Tia2AxServices.cs @@ -276,13 +276,13 @@ public void CloseProject([CallerMemberName] string caller = "") /// Retrieve the PLCs from the current project /// /// - public void GetPlcList(string outputFolder, bool hwidOnly, [CallerMemberName] string caller = "") + public void GetPlcList(string outputFolder, bool IO, bool HWID, [CallerMemberName] string caller = "") { var methodBase = MethodBase.GetCurrentMethod(); if (methodBase.ReflectedType != null) _traceWriter.WriteLine(methodBase.ReflectedType.Name + "." + methodBase.Name + " called from " + caller); _apiWrapper.GetPlcList(ProjectItem); - _apiWrapper.ExportAllPLCs(outputFolder, hwidOnly, ProjectItem); + _apiWrapper.ExportAllPLCs(outputFolder, IO, HWID, ProjectItem); } #endregion // TIA Portal Project diff --git a/src/tia2ax/V19_0/ApiResolver/ApiWrapper.cs b/src/tia2ax/V19_0/ApiResolver/ApiWrapper.cs index 51c96d0..68a6f96 100644 --- a/src/tia2ax/V19_0/ApiResolver/ApiWrapper.cs +++ b/src/tia2ax/V19_0/ApiResolver/ApiWrapper.cs @@ -716,7 +716,7 @@ public bool IsNewHardwareId(string name, IList HwIdentifiers) /// /// Export all PLCs /// - public void ExportAllPLCs(string exportDirectory, bool hwidOnly ,ProjectItem projectItem) + public void ExportAllPLCs(string exportDirectory, bool IO, bool HWID, ProjectItem projectItem) { DeleteFolder(exportDirectory); Directory.CreateDirectory(exportDirectory); @@ -725,7 +725,7 @@ public void ExportAllPLCs(string exportDirectory, bool hwidOnly ,ProjectItem pro string exportDir = String.IsNullOrEmpty(exportDirectory) ? Path.Combine(Environment.CurrentDirectory, plcItem.Name) : Path.Combine(exportDirectory, plcItem.Name); Directory.CreateDirectory(exportDir); - if (!hwidOnly) + if (IO) { ExportMappingItems(plcItem, exportDir, ExportItemType.HwInput); ExportMappingItems(plcItem, exportDir, ExportItemType.HwOutput); @@ -736,8 +736,10 @@ public void ExportAllPLCs(string exportDirectory, bool hwidOnly ,ProjectItem pro ExportConfiguration(exportDir); ExportProgram(exportDir); } - - ExportHwIdentifiers(plcItem, exportDir); + if (HWID) + { + ExportHwIdentifiers(plcItem, exportDir); + } } } diff --git a/src/tia2ax/V19_0/Program.cs b/src/tia2ax/V19_0/Program.cs index 71bb161..6bcc02b 100644 --- a/src/tia2ax/V19_0/Program.cs +++ b/src/tia2ax/V19_0/Program.cs @@ -44,7 +44,7 @@ private static void GoAhead(Options options) var creator = new Tia2AxServices(traceWriter, apiWrapper); creator.OpenProject(options.TiaSourceProject); - creator.GetPlcList(options.OutputProjectFolder,options.HwIdOnly); + creator.GetPlcList(options.OutputProjectFolder, options.IO, options.HwId); } } @@ -60,8 +60,11 @@ internal class Options HelpText = "Output project folder where generator emits result.")] public string OutputProjectFolder { get; set; } - [Option('h', "hwid-only", Required = false, HelpText = "Export only hardware idntifiers")] - public bool HwIdOnly { get; set; } + [Option('i', "io", Required = false, HelpText = "Export IO addresses")] + public bool IO { get; set; } + + [Option('h', "hwid", Required = false, HelpText = "Export hardware identifiers")] + public bool HwId { get; set; } } } diff --git a/src/tia2ax/V19_0/Tia2AxServices.cs b/src/tia2ax/V19_0/Tia2AxServices.cs index 0c1e6d5..08dffe7 100644 --- a/src/tia2ax/V19_0/Tia2AxServices.cs +++ b/src/tia2ax/V19_0/Tia2AxServices.cs @@ -276,13 +276,13 @@ public void CloseProject([CallerMemberName] string caller = "") /// Retrieve the PLCs from the current project /// /// - public void GetPlcList(string outputFolder,bool hwidOnly, [CallerMemberName] string caller = "") + public void GetPlcList(string outputFolder, bool IO, bool HWID, [CallerMemberName] string caller = "") { var methodBase = MethodBase.GetCurrentMethod(); if (methodBase.ReflectedType != null) _traceWriter.WriteLine(methodBase.ReflectedType.Name + "." + methodBase.Name + " called from " + caller); _apiWrapper.GetPlcList(ProjectItem); - _apiWrapper.ExportAllPLCs(outputFolder, hwidOnly, ProjectItem); + _apiWrapper.ExportAllPLCs(outputFolder, IO, HWID, ProjectItem); } #endregion // TIA Portal Project diff --git a/src/tia2axtool/Program.cs b/src/tia2axtool/Program.cs index db37082..31bb64a 100644 --- a/src/tia2axtool/Program.cs +++ b/src/tia2axtool/Program.cs @@ -87,8 +87,11 @@ internal class Options HelpText = "Output project folder where generator emits result.")] public string OutputProjectFolder { get; set; } - [Option('h', "hwid-only", Required = false, HelpText = "Export only hardware idntifiers")] - public bool HwIdOnly { get; set; } + [Option('i', "io", Required = false, HelpText = "Export IO addresses")] + public bool IO { get; set; } + + [Option('h', "hwid", Required = false, HelpText = "Export hardware identifiers")] + public bool HwId { get; set; } } } } \ No newline at end of file diff --git a/src/tia2axtool/Properties/launchSettings.json b/src/tia2axtool/Properties/launchSettings.json index 5469862..4cf1b97 100644 --- a/src/tia2axtool/Properties/launchSettings.json +++ b/src/tia2axtool/Properties/launchSettings.json @@ -3,7 +3,7 @@ "tia2ax": { "commandName": "Project", //"commandLineArgs": "-x D:\\github\\ix-ax\\TiaProjects\\AX_Plc1518V3_CmmtAs\\AX_Plc1518V3_CmmtAs.ap18 -o D:\\github\\ix-ax\\Export", - "commandLineArgs": "-x D:\\github\\ix-ax\\TiaProjects\\HW_Plc1518V3_CmmtAs\\HW_Plc1518V3_CmmtAs.ap19 -o D:\\github\\ix-ax\\Export" + "commandLineArgs": "-x D:\\github\\ix-ax\\TiaProjects\\HW_Plc1518V3_CmmtAs\\HW_Plc1518V3_CmmtAs.ap19 -o D:\\github\\ix-ax\\Export -i -h" } } } \ No newline at end of file diff --git a/tests/V18/tia2axIntegrationTests/Integration.cs b/tests/V18/tia2axIntegrationTests/Integration.cs index b77b5da..c0b4f08 100644 --- a/tests/V18/tia2axIntegrationTests/Integration.cs +++ b/tests/V18/tia2axIntegrationTests/Integration.cs @@ -158,7 +158,7 @@ internal static void TestRun(string testCaseFolder) string exportPath = generatedDir.FullName; creator.OpenProject(tiaProjectPath); - creator.GetPlcList(exportPath,false); + creator.GetPlcList(exportPath,true,true); Assert.IsTrue(TestsCommon.AllFilesAreEqual(expectedDir.FullName, generatedDir.FullName)); diff --git a/tests/V19/tia2axIntegrationTests/Integration.cs b/tests/V19/tia2axIntegrationTests/Integration.cs index e08f7f2..a89b99c 100644 --- a/tests/V19/tia2axIntegrationTests/Integration.cs +++ b/tests/V19/tia2axIntegrationTests/Integration.cs @@ -158,7 +158,7 @@ internal static void TestRun(string testCaseFolder) string exportPath = generatedDir.FullName; creator.OpenProject(tiaProjectPath); - creator.GetPlcList(exportPath,false); + creator.GetPlcList(exportPath,true,true); Assert.IsTrue(TestsCommon.AllFilesAreEqual(expectedDir.FullName, generatedDir.FullName));