From 0d915a7f6ec9e43c3cad02d96f9a95fd27b42d6f Mon Sep 17 00:00:00 2001 From: densogiaichned Date: Thu, 11 Jul 2024 17:50:42 +0200 Subject: [PATCH] feat(v0.4/#59): Port Submodule - Add attributes for *.xti Closes #59. Also, update dependencies. --- .../Export/TC/Constants.cs | 5 +++ .../Export/TC/TcSmItem.cs | 33 +++++++++++++++++++ .../Export/TC/XtiExporter.cs | 17 ++++++++-- .../dsian.TcPnScanner.CLI.csproj | 10 +++--- .../dsian.TcPnScanner.IntegrationTests.csproj | 12 +++---- 5 files changed, 64 insertions(+), 13 deletions(-) diff --git a/src/dsian.TcPnScanner.CLI/Export/TC/Constants.cs b/src/dsian.TcPnScanner.CLI/Export/TC/Constants.cs index e358266..b0915f9 100644 --- a/src/dsian.TcPnScanner.CLI/Export/TC/Constants.cs +++ b/src/dsian.TcPnScanner.CLI/Export/TC/Constants.cs @@ -21,6 +21,10 @@ internal static class Constants internal const uint SUBMODULE_INDEX_START = 0x031C0000u; + internal const ushort SUBSLOT_NR_PORT1 = 32769; + + internal const ushort SUBSLOT_NR_PORT2 = 32770; + internal const uint BOX_IMAGE_ID = 121; internal const uint API_IMAGE_ID = 4; @@ -35,4 +39,5 @@ internal static class Constants internal const uint BOX_PROFINET_FLAGS = 0x410u; internal const uint BOX_PROFINET_FRAME_OFFSET = 0x8000u; + } diff --git a/src/dsian.TcPnScanner.CLI/Export/TC/TcSmItem.cs b/src/dsian.TcPnScanner.CLI/Export/TC/TcSmItem.cs index b22db3f..37f8545 100644 --- a/src/dsian.TcPnScanner.CLI/Export/TC/TcSmItem.cs +++ b/src/dsian.TcPnScanner.CLI/Export/TC/TcSmItem.cs @@ -2965,6 +2965,9 @@ public partial class TcSmItemDeviceBoxProfinetAPIModuleSubModule private uint subModuleIdentNumberField; + private uint typeOfSubmoduleField; + private bool typeOfSubmoduleFieldSpecified; + private uint subSlotNumberField; private bool isFixSubmoduleField; @@ -3091,6 +3094,35 @@ public uint SubModuleIdentNumber } } + /// + [System.Xml.Serialization.XmlAttributeAttribute()] + public uint TypeOfSubModule + { + get + { + return this.typeOfSubmoduleField; + } + set + { + this.typeOfSubmoduleField = value; + this.typeOfSubmoduleFieldSpecified = true; + } + } + + /// + [System.Xml.Serialization.XmlIgnoreAttribute()] + public bool TypeOfSubModuleSpecified + { + get + { + return this.typeOfSubmoduleFieldSpecified; + } + set + { + this.typeOfSubmoduleFieldSpecified = value; + } + } + /// [System.Xml.Serialization.XmlAttributeAttribute()] public uint SubSlotNumber @@ -3144,6 +3176,7 @@ public uint AddSubModFlags set { this.addSubModFlagsField = value; + this.addSubModFlagsFieldSpecified = true; } } diff --git a/src/dsian.TcPnScanner.CLI/Export/TC/XtiExporter.cs b/src/dsian.TcPnScanner.CLI/Export/TC/XtiExporter.cs index 93708f5..7c17d30 100644 --- a/src/dsian.TcPnScanner.CLI/Export/TC/XtiExporter.cs +++ b/src/dsian.TcPnScanner.CLI/Export/TC/XtiExporter.cs @@ -184,7 +184,7 @@ private static TcSmItemDeviceBoxProfinetAPIModuleSubModule[] GetSubModules(APIEx foreach (var submodule in api.Submodules) { - subModules.Add(new TcSmItemDeviceBoxProfinetAPIModuleSubModule + var subModuleToAdd = new TcSmItemDeviceBoxProfinetAPIModuleSubModule { Id = PrintAsHex(CreateModuleIndex(Constants.SUBMODULE_INDEX_START, (ushort)(submodule.SubslotNumber + 1))), Name = $"Subterm {submodule.SubslotNumber}{PrintSubTermIoLabel(submodule)}", @@ -195,7 +195,16 @@ private static TcSmItemDeviceBoxProfinetAPIModuleSubModule[] GetSubModules(APIEx APINr = api.APIId, APINrSpecified = api.APIId != 0, Vars = GetIoVarsForSubmodule(submodule) - }); + + }; + if (IsPortSubmodule(submodule)) + { + subModuleToAdd.Name += $" (Port {submodule.SubslotNumber - (Constants.SUBSLOT_NR_PORT1 - 1)})"; + subModuleToAdd.PortData = ""; + subModuleToAdd.TypeOfSubModule = 2; + subModuleToAdd.AddSubModFlags = 28; + } + subModules.Add(subModuleToAdd); } return subModules.ToArray(); @@ -292,4 +301,8 @@ private static string PrintAsHex(uint index) { return $"#x{index:X08}"; } + private static bool IsPortSubmodule(in Submodule submodule) + { + return submodule.SubslotNumber >= Constants.SUBSLOT_NR_PORT1 && submodule.SubslotNumber <= Constants.SUBSLOT_NR_PORT2; + } } diff --git a/src/dsian.TcPnScanner.CLI/dsian.TcPnScanner.CLI.csproj b/src/dsian.TcPnScanner.CLI/dsian.TcPnScanner.CLI.csproj index e2db98d..19e8990 100644 --- a/src/dsian.TcPnScanner.CLI/dsian.TcPnScanner.CLI.csproj +++ b/src/dsian.TcPnScanner.CLI/dsian.TcPnScanner.CLI.csproj @@ -18,7 +18,7 @@ Scans a PROFINET and adds all Stations to a PROFINET IO Device (TF6270) Copyright (c) 2023 densogiaichned TwinCAT Profinet Device Scanner - 0.3.1 + 0.4.0 $(Version) $(Version) false @@ -55,11 +55,11 @@ - + - - - + + + diff --git a/tests/dsian.TcPnScanner.IntegrationTests/dsian.TcPnScanner.IntegrationTests.csproj b/tests/dsian.TcPnScanner.IntegrationTests/dsian.TcPnScanner.IntegrationTests.csproj index 7cf1044..e47686d 100644 --- a/tests/dsian.TcPnScanner.IntegrationTests/dsian.TcPnScanner.IntegrationTests.csproj +++ b/tests/dsian.TcPnScanner.IntegrationTests/dsian.TcPnScanner.IntegrationTests.csproj @@ -10,15 +10,15 @@ - - - - - + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all