Skip to content

Commit 15768fb

Browse files
authored
Merge pull request #54 from siemens/53-cannot-generate-with-the-testframework
fix: skipping HardwareGeneration in testFramework, can be enabled by …
2 parents cfa0fe7 + 30de377 commit 15768fb

File tree

5 files changed

+132
-114
lines changed

5 files changed

+132
-114
lines changed
Binary file not shown.

MAC_use_cases/MAC_use_cases.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package>
33
<metadata>
44
<id>MAC_use_cases</id>
5-
<version>1.0.9236-pre20250415064854</version>
5+
<version>1.0.9236-pre20250415085633</version>
66
<title>MAC_use_cases</title>
77
<authors>SIEMENS AG</authors>
88
<projectUrl>http://equipmentmodule.info/</projectUrl>

MAC_use_cases/Model/MAC_use_casesEM.cs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ public ModuleEdge ModuleStart
6969
/// </summary>
7070
public TechnologyObjectClass myTO { get; set; }
7171

72+
public bool IsGenerateHardwareChecked { get; set; } = false;
73+
7274
/// <summary>
7375
/// This attribute is the instance for the serialization
7476
/// </summary>
@@ -97,8 +99,8 @@ public override bool GenerateTiaPortal(TiaTemplateContext tiaTemplateContext, st
9799
m_plcDevice = GetPlcDevice(tiaTemplateContext);
98100
break;
99101

100-
// Add equipment module specific code for each generation phase here, which is
101-
// necessary before the ResourceManagement is called.
102+
// Add equipment module specific code for each generation phase here, which is
103+
// necessary before the ResourceManagement is called.
102104
}
103105

104106
ResourceManagement.Generate(tiaTemplateContext, this, generationPhaseName);
@@ -110,7 +112,10 @@ public override bool GenerateTiaPortal(TiaTemplateContext tiaTemplateContext, st
110112
switch (generationPhaseName)
111113
{
112114
case TiaGenerationPhases.Init:
113-
115+
if (!IsGenerateHardwareChecked)
116+
{
117+
break;
118+
}
114119
//Hardware config has to be in the Init phase.Otherwise, it can't be used in the MAC.
115120
var s120 = HardwareGeneration.GenerateS120(this, "S120MACTest", "S120DeviceTest",
116121
"this drive is generated with MAC");
@@ -175,9 +180,12 @@ public override bool GenerateTiaPortal(TiaTemplateContext tiaTemplateContext, st
175180

176181
CreateVariables.CreateTagInTagTable(myTagTable, "%I", "187", "0", "myTag", "Bool", "myTagComment");
177182

178-
var hmiSoftware = HardwareGeneration.GetOrCreateHMISoftware(opennessTIAPortalProject, "HMI_1");
179-
IntegrateLibraries.GenerateScreenFromMastercopy(hmiSoftware,
180-
ResourceManagement.Lib_MAC_use_cases.Lib_Screen_1);
183+
if (IsGenerateHardwareChecked)
184+
{
185+
var hmiSoftware = HardwareGeneration.GetOrCreateHMISoftware(opennessTIAPortalProject, "HMI_1");
186+
IntegrateLibraries.GenerateScreenFromMastercopy(hmiSoftware,
187+
ResourceManagement.Lib_MAC_use_cases.Lib_Screen_1);
188+
}
181189

182190
provider.CollectAttributes(Attributes);
183191
provider.WriteValues(m_plcDevice);
Lines changed: 107 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -1,140 +1,140 @@
1+
using System.Linq;
2+
using Siemens.Automation.ModularApplicationCreator.MacPublishedObjects.Subnet;
13
using Siemens.Automation.ModularApplicationCreator.Tia.Helper.TypeIdentifier;
24
using Siemens.Automation.ModularApplicationCreator.Tia.Helper.TypeIdentifier.Enums;
35
using Siemens.Automation.ModularApplicationCreator.Tia.Openness.DO;
6+
using Siemens.Engineering;
47
using Siemens.Engineering.Hmi;
58
using Siemens.Engineering.HW.Features;
6-
using System.Linq;
7-
using Siemens.Automation.ModularApplicationCreator.MacPublishedObjects.Subnet;
8-
using Siemens.Engineering;
99

10-
namespace MAC_use_cases.Model.UseCases
10+
namespace MAC_use_cases.Model.UseCases;
11+
12+
/// <summary>
13+
/// All the functions to configure and generate Hardware are defined here.
14+
/// </summary>
15+
public class HardwareGeneration
1116
{
1217
/// <summary>
13-
/// All the functions to configure and generate Hardware are defined here.
18+
/// This function generates an S120 Drive based on a MasterCopy
19+
/// \image html GenerateS120.png
1420
/// </summary>
15-
public class HardwareGeneration
21+
/// <param name="module">The Module</param>
22+
/// <param name="name">The name of the drive</param>
23+
/// <param name="deviceName">The name of the device</param>
24+
/// <param name="path">Path if necessary</param>
25+
/// <param name="comment">Comment if necessary</param>
26+
public static S120PNDriveInfo GenerateS120(MAC_use_casesEM module, string name, string deviceName,
27+
string path = null, string comment = null)
1628
{
17-
/// <summary>
18-
/// This function generates an S120 Drive based on a MasterCopy
19-
/// \image html GenerateS120.png
20-
/// </summary>
21-
/// <param name="module">The Module</param>
22-
/// <param name="name">The name of the drive</param>
23-
/// <param name="deviceName">The name of the device</param>
24-
/// <param name="path">Path if necessary</param>
25-
/// <param name="comment">Comment if necessary</param>
26-
public static S120PNDriveInfo GenerateS120(MAC_use_casesEM module, string name, string deviceName,
27-
string path = null, string comment = null)
29+
if (!module.SynchronizedCollection.HardwareInterfaces.OfType<ProfiDriveObjectInfo>()
30+
.Any(x => x.DriveDevice.Equals(name)))
2831
{
29-
if (!module.SynchronizedCollection.HardwareInterfaces.OfType<ProfiDriveObjectInfo>()
30-
.Any(x => x.DriveDevice.Equals(name)))
31-
{
32-
var info = HardwareBlueprintFactory.CreateDrive(S120PNOrderNumbers.S120_CU_320_2_PN).LatestFirmware()
33-
.CreateBlueprint(name, deviceName);
32+
var info = HardwareBlueprintFactory.CreateDrive(S120PNOrderNumbers.S120_CU_320_2_PN).LatestFirmware()
33+
.CreateBlueprint(name, deviceName);
3434

35-
info.DevicePath = path;
36-
info.Comment = comment;
37-
info.PlcName = module.ParentDevice.Name;
38-
info.CreateSingleAxis("SingleAxis", "OrderNumber:6SL3310-1TE32-1AAx", out _,
39-
AxisDriveObjectType.Vector);
35+
info.DevicePath = path;
36+
info.Comment = comment;
37+
info.PlcName = module.ParentDevice.Name;
38+
info.CreateSingleAxis("SingleAxis", "OrderNumber:6SL3310-1TE32-1AAx", out _,
39+
AxisDriveObjectType.Vector);
4040

41-
info.GetAxis("SingleAxis").PlcName = module.ParentDevice.Name;
41+
info.GetAxis("SingleAxis").PlcName = module.ParentDevice.Name;
4242

43-
module.SynchronizedCollection.HardwareInterfaces.Add(info);
43+
module.SynchronizedCollection.HardwareInterfaces.Add(info);
4444

45-
return info;
46-
}
47-
48-
return null;
45+
return info;
4946
}
5047

51-
/// <summary>
52-
/// This function generates an S210 Drive based on a MasterCopy
53-
/// \image html GenerateS210.png
54-
/// </summary>
55-
/// <param name="module">The Module</param>
56-
/// <param name="name">The name of the drive</param>
57-
/// <param name="deviceName">The name of the device</param>
58-
/// <param name="path">Path if necessary</param>
59-
/// <param name="comment">Comment if necessary</param>
60-
public static S210DriveInfo GenerateS210(MAC_use_casesEM module, string name, string deviceName,
61-
string path = null, string comment = null)
48+
return null;
49+
}
50+
51+
/// <summary>
52+
/// This function generates an S210 Drive based on a MasterCopy
53+
/// \image html GenerateS210.png
54+
/// </summary>
55+
/// <param name="module">The Module</param>
56+
/// <param name="name">The name of the drive</param>
57+
/// <param name="deviceName">The name of the device</param>
58+
/// <param name="path">Path if necessary</param>
59+
/// <param name="comment">Comment if necessary</param>
60+
public static S210DriveInfo GenerateS210(MAC_use_casesEM module, string name, string deviceName,
61+
string path = null, string comment = null)
62+
{
63+
if (!module.SynchronizedCollection.HardwareInterfaces.OfType<ProfiDriveObjectInfo>()
64+
.Any(x => x.DriveDevice.Equals(name)))
6265
{
63-
if (!module.SynchronizedCollection.HardwareInterfaces.OfType<ProfiDriveObjectInfo>()
64-
.Any(x => x.DriveDevice.Equals(name)))
65-
{
66-
var info = HardwareBlueprintFactory.CreateDrive(S210OrderNumbers.S210_PN_3AC_7_kW).LatestFirmware()
67-
.CreateBlueprint(name, deviceName);
66+
var info = HardwareBlueprintFactory.CreateDrive(S210OrderNumbers.S210_PN_3AC_7_kW).LatestFirmware()
67+
.CreateBlueprint(name, deviceName);
6868

69-
info.DevicePath = path;
70-
info.Comment = comment;
71-
info.PlcName = module.ParentDevice.Name;
69+
info.DevicePath = path;
70+
info.Comment = comment;
71+
info.PlcName = module.ParentDevice.Name;
7272

73-
module.SynchronizedCollection.HardwareInterfaces.Add(info);
73+
module.SynchronizedCollection.HardwareInterfaces.Add(info);
7474

75-
return info;
76-
}
77-
return null;
75+
return info;
7876
}
7977

80-
/// <summary>
81-
/// This call returns the openness object of an HMI with the desired name. If it exists, it will be returned. If not, it will create a new one.
82-
/// \image html GetOrCreateHMI.png
83-
/// </summary>
84-
/// <param name="project">This object is the openness object of the TIA Portal project</param>
85-
/// <param name="name">Thats the desired name of the HMI Device</param>
86-
public static HmiTarget GetOrCreateHMISoftware(Project project, string name)
87-
{
88-
var hmiDevice = project.Devices.FirstOrDefault(x => x.Name == name);
89-
if (hmiDevice == null)
90-
{
91-
hmiDevice = project.Devices.CreateWithItem("OrderNumber:6AV2 125-2JB23-0AX0/17.0.0.0", name, name);
92-
}
93-
var hmiSoftwareContainer = hmiDevice.DeviceItems.FirstOrDefault(x => x.Name.Contains("HMI_RT")).GetService<SoftwareContainer>();
94-
return hmiSoftwareContainer.Software as HmiTarget;
95-
}
78+
return null;
79+
}
9680

97-
/// <summary>
98-
/// Gets or creates a subnet with the desired name
99-
/// \image html GetOrCreateSubnet.png
100-
/// </summary>
101-
/// <param name="subnetsManager">The Modular Application Creator helper object</param>
102-
/// <param name="name">The name of the subnet</param>
103-
public static ISubnetInfo GetOrCreateSubnet(ISubnetsManager subnetsManager, string name)
104-
{
105-
return subnetsManager.GetOrCreateProfinet(name);
106-
}
81+
/// <summary>
82+
/// This call returns the openness object of an HMI with the desired name. If it exists, it will be returned. If not,
83+
/// it will create a new one.
84+
/// \image html GetOrCreateHMI.png
85+
/// </summary>
86+
/// <param name="project">This object is the openness object of the TIA Portal project</param>
87+
/// <param name="name">That's the desired name of the HMI Device</param>
88+
public static HmiTarget GetOrCreateHMISoftware(Project project, string name)
89+
{
90+
var hmiDevice = project.Devices.FirstOrDefault(x => x.Name == name);
91+
if (hmiDevice == null)
92+
hmiDevice = project.Devices.CreateWithItem("OrderNumber:6AV2 125-2JB23-0AX0/17.0.0.0", name, name);
93+
var hmiSoftwareContainer = hmiDevice.DeviceItems.FirstOrDefault(x => x.Name.Contains("HMI_RT"))
94+
.GetService<SoftwareContainer>();
95+
return hmiSoftwareContainer.Software as HmiTarget;
96+
}
10797

108-
/// <summary>
109-
/// Connectes the desired drive to the desired subnet
110-
/// \image html ConnectDriveToSubnet.png
111-
/// </summary>
112-
/// <param name="drive">The desired drive</param>
113-
/// <param name="subnet">The desired subnet</param>
114-
/// <param name="module">The module</param>
115-
public static void ConnectDriveToSubnet(ProfiDriveObjectInfo drive, ISubnetInfo subnet, MAC_use_casesEM module)
116-
{
117-
var device = module.SynchronizedCollection.HardwareInterfaces.OfType<ProfiDriveObjectInfo>().FirstOrDefault(x => x.Name.Equals(drive.Name));
98+
/// <summary>
99+
/// Gets or creates a subnet with the desired name
100+
/// \image html GetOrCreateSubnet.png
101+
/// </summary>
102+
/// <param name="subnetsManager">The Modular Application Creator helper object</param>
103+
/// <param name="name">The name of the subnet</param>
104+
public static ISubnetInfo GetOrCreateSubnet(ISubnetsManager subnetsManager, string name)
105+
{
106+
return subnetsManager.GetOrCreateProfinet(name);
107+
}
118108

119-
var plcNwItf = module.ParentDeviceAsHardwareInfo.ControllerProfinetInterfaces.First();
120-
plcNwItf.ConnectedSubnetInfo = subnet;
109+
/// <summary>
110+
/// Connects the desired drive to the desired subnet
111+
/// \image html ConnectDriveToSubnet.png
112+
/// </summary>
113+
/// <param name="drive">The desired drive</param>
114+
/// <param name="subnet">The desired subnet</param>
115+
/// <param name="module">The module</param>
116+
public static void ConnectDriveToSubnet(ProfiDriveObjectInfo drive, ISubnetInfo subnet, MAC_use_casesEM module)
117+
{
118+
var device = module.SynchronizedCollection.HardwareInterfaces.OfType<ProfiDriveObjectInfo>()
119+
.FirstOrDefault(x => x.Name.Equals(drive.Name));
121120

122-
var ioSystem = plcNwItf.ConnectedSubnetInfo.GetOrCreateIoSystem(plcNwItf, "PROFINET IO-System");
121+
var plcNwItf = module.ParentDeviceAsHardwareInfo.ControllerProfinetInterfaces.First();
122+
plcNwItf.ConnectedSubnetInfo = subnet;
123123

124-
if (device.GetType() == typeof(S120PNDriveInfo))
125-
{
126-
(device as S120PNDriveInfo).ProfinetInterface.ConnectedSubnetInfo = subnet;
127-
ioSystem.ConnectIoDevice((device as S120PNDriveInfo).ProfinetInterface.IoConnectors.First().Value);
128-
plcNwItf.Ports.First().Connect((device as S120PNDriveInfo).ProfinetInterface.Ports.First());
129-
}
130-
if (device.GetType() == typeof(S210DriveInfo))
131-
{
132-
(device as S210DriveInfo).ProfinetInterface.ConnectedSubnetInfo = subnet;
133-
ioSystem.ConnectIoDevice((device as S210DriveInfo).ProfinetInterface.IoConnectors.First().Value);
134-
plcNwItf.Ports.First().Connect((device as S210DriveInfo).ProfinetInterface.Ports.First());
135-
}
124+
var ioSystem = plcNwItf.ConnectedSubnetInfo.GetOrCreateIoSystem(plcNwItf, "PROFINET IO-System");
136125

126+
if (device.GetType() == typeof(S120PNDriveInfo))
127+
{
128+
(device as S120PNDriveInfo).ProfinetInterface.ConnectedSubnetInfo = subnet;
129+
ioSystem.ConnectIoDevice((device as S120PNDriveInfo).ProfinetInterface.IoConnectors.First().Value);
130+
plcNwItf.Ports.First().Connect((device as S120PNDriveInfo).ProfinetInterface.Ports.First());
131+
}
137132

133+
if (device.GetType() == typeof(S210DriveInfo))
134+
{
135+
(device as S210DriveInfo).ProfinetInterface.ConnectedSubnetInfo = subnet;
136+
ioSystem.ConnectIoDevice((device as S210DriveInfo).ProfinetInterface.IoConnectors.First().Value);
137+
plcNwItf.Ports.First().Connect((device as S210DriveInfo).ProfinetInterface.Ports.First());
138138
}
139139
}
140140
}

MAC_use_cases/UI/FirstPage.xaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<RowDefinition Height="Auto" />
1818
<RowDefinition Height="Auto" />
1919
<RowDefinition Height="Auto" />
20+
<RowDefinition Height="Auto" />
2021
</Grid.RowDefinitions>
2122
<Grid.ColumnDefinitions>
2223
<ColumnDefinition Width="Auto" />
@@ -63,5 +64,14 @@
6364
Width="400"
6465
HorizontalAlignment="Left"
6566
Margin="5" />
67+
68+
<!-- Row 5 -->
69+
<TextBlock Grid.Row="5" Grid.Column="0"
70+
Text="Generate Hardware:"
71+
Margin="5" />
72+
<CheckBox Grid.Row="5" Grid.Column="1"
73+
HorizontalAlignment="Left"
74+
Margin="5"
75+
IsChecked="{Binding IsGenerateHardwareChecked}"/>
6676
</Grid>
6777
</modulesUI:BaseEditor>

0 commit comments

Comments
 (0)