Skip to content

Commit

Permalink
generating hwid so as the io address changed to optionally switch on …
Browse files Browse the repository at this point in the history
…and off using parameter (#10)
  • Loading branch information
TomKovac authored Feb 13, 2024
1 parent 769f4bf commit 69c20d6
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 23 deletions.
10 changes: 6 additions & 4 deletions src/tia2ax/V18_0/ApiResolver/ApiWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ public bool IsNewHardwareId(string name, IList<HwIdentifierItem> HwIdentifiers)
/// <summary>
/// Export all PLCs
/// </summary>
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);
Expand All @@ -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);
Expand All @@ -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);
}
}
}

Expand Down
9 changes: 6 additions & 3 deletions src/tia2ax/V18_0/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand All @@ -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; }


}
Expand Down
4 changes: 2 additions & 2 deletions src/tia2ax/V18_0/Tia2AxServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -276,13 +276,13 @@ public void CloseProject([CallerMemberName] string caller = "")
/// Retrieve the PLCs from the current project
/// </summary>
/// <param name="caller"></param>
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
Expand Down
10 changes: 6 additions & 4 deletions src/tia2ax/V19_0/ApiResolver/ApiWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ public bool IsNewHardwareId(string name, IList<HwIdentifierItem> HwIdentifiers)
/// <summary>
/// Export all PLCs
/// </summary>
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);
Expand All @@ -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);
Expand All @@ -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);
}
}
}

Expand Down
9 changes: 6 additions & 3 deletions src/tia2ax/V19_0/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand All @@ -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; }

}
}
Expand Down
4 changes: 2 additions & 2 deletions src/tia2ax/V19_0/Tia2AxServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -276,13 +276,13 @@ public void CloseProject([CallerMemberName] string caller = "")
/// Retrieve the PLCs from the current project
/// </summary>
/// <param name="caller"></param>
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
Expand Down
7 changes: 5 additions & 2 deletions src/tia2axtool/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
}
}
2 changes: 1 addition & 1 deletion src/tia2axtool/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
2 changes: 1 addition & 1 deletion tests/V18/tia2axIntegrationTests/Integration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
2 changes: 1 addition & 1 deletion tests/V19/tia2axIntegrationTests/Integration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down

0 comments on commit 69c20d6

Please sign in to comment.