Modular Application Creator Use Case Based Documentation
Loading...
Searching...
No Matches
GeneralSupport.cs
1using System.Collections.Generic;
2using System.Linq;
3using System.Windows;
4using Siemens.Automation.ModularApplicationCreator.Core;
5using Siemens.Automation.ModularApplicationCreator.Tia;
6using Siemens.Automation.ModularApplicationCreatorBasics.Logging;
7using Siemens.Engineering.HW;
8using Siemens.Engineering.HW.Features;
9using Siemens.Engineering.SW;
10using Siemens.Engineering.SW.Blocks;
11using Device = Siemens.Automation.ModularApplicationCreator.Tia.Openness.Device;
12using Project = Siemens.Engineering.Project;
13
15{
19 public class GeneralSupport
20 {
28 public static void LogMessage(LogTypes logType, string logMessage, MAC_use_casesEM equipmentModule)
29 {
30 MacManagement.LoggingService.LogMessage(logType, logMessage, equipmentModule.Name);
31 }
32
42 public static string GetLocalizedString(string key)
43 {
44 return MacManagement.LanguageService.GetString(key);
45 }
46
56 public static DeviceItem GetOpennessDeviceItem(Device device)
57 {
58 var opennessDevice = (Siemens.Engineering.HW.Device)device;
59 return opennessDevice.DeviceItems.FirstOrDefault(x => x.Classification == DeviceItemClassifications.CPU);
60 }
61
66 public static Project GetOpennessProject(
67 Siemens.Automation.ModularApplicationCreator.Tia.Openness.Project tiaProject)
68 {
69 return (Project)tiaProject;
70 }
71
88 public static void ReadAdditionalInformationsFromTIAPortalProject(MAC_use_casesEM module, TiaTemplateContext tiaTemplateContext)
89 {
90 DeviceItem plc = null;
91 foreach (var device in ((Siemens.Engineering.Project)tiaTemplateContext.TiaProject).Devices)
92 {
93 foreach (var deviceItem in device.DeviceItems)
94 {
95 if (deviceItem.Classification == DeviceItemClassifications.CPU)
96 {
97 plc = deviceItem;
98 continue;
99 }
100 }
101 }
102 var softwareContainer = plc.GetService<SoftwareContainer>().Software as PlcSoftware;
103 var allBlocks = GetAllBlocksRecursive(softwareContainer.BlockGroup);
104
105 Application.Current.Dispatcher.Invoke(() =>
106 {
107 module.PlcBlockNames.Clear();
108 foreach (var block in allBlocks)
109 {
110 module.PlcBlockNames.Add(block.Name);
111 }
112 });
113 }
114
121 private static List<PlcBlock> GetAllBlocksRecursive(PlcBlockGroup group)
122 {
123 var result = new List<PlcBlock>();
124
125 foreach (var block in group.Blocks)
126 {
127 result.Add(block);
128 }
129
130 foreach (var subGroup in group.Groups)
131 {
132 result.AddRange(GetAllBlocksRecursive(subGroup));
133 }
134
135 return result;
136 }
137 }
138}
This is the main class in which the workflow starts. Here are all sections for creating or generating...
This are functions that support you in different ways while using Modular Application Creator.
static DeviceItem GetOpennessDeviceItem(Device device)
Retrieves the CPU DeviceItem from a TIA Portal device using the Openness API.
static Project GetOpennessProject(Siemens.Automation.ModularApplicationCreator.Tia.Openness.Project tiaProject)
This call returns the openness object of the TIA Portal project.
static void LogMessage(LogTypes logType, string logMessage, MAC_use_casesEM equipmentModule)
This call generates a log message while generating a project.
static void ReadAdditionalInformationsFromTIAPortalProject(MAC_use_casesEM module, TiaTemplateContext tiaTemplateContext)
Reads additional information from the TIA Portal project and populates MAC_use_casesEM....
static List< PlcBlock > GetAllBlocksRecursive(PlcBlockGroup group)
Recursively collects all PlcBlock objects from the given PlcBlockGroup and all its nested subgroups.
static string GetLocalizedString(string key)
Retrieves a localized string value from the language resource dictionary using the specified key....