Modular Application Creator Use Case Based Documentation
Loading...
Searching...
No Matches
MAC_use_casesEM.cs
2using MAC_use_cases.ViewModel;
3using Newtonsoft.Json;
4using Siemens.Automation.ModularApplicationCreator.Modules;
5using Siemens.Automation.ModularApplicationCreator.Serializer;
6using Siemens.Automation.ModularApplicationCreator.Tia;
7using Siemens.Automation.ModularApplicationCreator.Tia.Helper;
8using Siemens.Automation.ModularApplicationCreator.Tia.Helper.Create_XML_Block;
9using Siemens.Automation.ModularApplicationCreator.Tia.Modules;
10using Siemens.Automation.ModularApplicationCreator.Tia.Openness;
11using Siemens.Automation.ModularApplicationCreator.Tia.Openness.SoftwareUnit;
12using Siemens.Automation.ModularApplicationCreator.Tia.TiaAttributeFuncs;
13using Siemens.Automation.ModularApplicationCreatorBasics.Logging;
14
15namespace MAC_use_cases.Model;
16
21public class MAC_use_casesEM : BaseMAC_use_casesEM
22{
26 private PlcDevice _plcDevice;
27
28 private ISoftwareUnit _softwareUnit;
29
30 // <auto-generated>
31 // This code was generated by a tool. Do not remove or modify the syntax of it.
32 // This constructor is used at first creation of this object.
33 // </auto-generated>
34 public MAC_use_casesEM()
35 {
36 // This Function can be modified to accommodate the Control Modules used in this Equipment Module
38 // Add any code here which is needed to be used only when this object is created the first time.
39
41
42 MyTo = new TechnologyObjectClass(this);
43 }
44
45 // <auto-generated>
46 // This code was generated by a tool. Do not remove or modify the syntax of it.
47 // This constructor is used only for deserialization.
48 // </auto-generated>
49 [JsonConstructor]
50 public MAC_use_casesEM(JsonConstructorMarker nullObj)
51 {
52 // Add any code here which is only necessary when this object is deserialized.
53
55
56 MyTo = new TechnologyObjectClass(this);
57 }
58
59 //-------------------------------------------
60 // This ModuleStart property is generated.
61 // It must be at the top of the class. It is used during module update.
62 //
63 // CAUTION: Do not use public instance variables as they overtake the properties in serialization.
64 //-------------------------------------------
65 public ModuleEdge ModuleStart
66 {
67 get => TopLevelEM ? new ModuleEdge() : null;
68 set { }
69 }
70
71 public HardwareGenerationExcelBasedViewModel HardwareGenerationExcelBasedViewModel { get; set; } = new();
72
76 public TechnologyObjectClass MyTo { get; set; }
77
78 public bool IsGenerateHardwareChecked { get; set; } = false;
79
83 public NonTIAProjectBased NonTiaProjectBased { get; set; } = new("myModel");
84
89 public string NameOfMyFb { get; set; } = "MyFunctionBlock";
90
95 public string NameOfMyFailSafeFb { get; set; } = "MyFunctionBlock_FailSafe";
96
97 [JsonIgnore]
98 public string NameAndType
99 {
100 get => NamingConventions.CreateModuleNameAndTypeForEM("MAC_use_cases", this);
101 }
102
103 public override bool GenerateTiaPortal(TiaTemplateContext tiaTemplateContext, string generationPhaseName)
104 {
105 switch (generationPhaseName)
106 {
107 case TiaGenerationPhases.Init:
108 _plcDevice = GetPlcDevice(tiaTemplateContext);
109 break;
110
111 // Add equipment module specific code for each generation phase here, which is
112 // necessary before the ResourceManagement is called.
113 }
114
115 ResourceManagement.Generate(tiaTemplateContext, this, generationPhaseName);
116
117 foreach (var module in ControlModules)
118 {
119 if (module is ITiaGenerateable tiaGen)
120 {
121 tiaGen.GenerateTiaPortal(tiaTemplateContext, generationPhaseName);
122 }
123 }
124
125 var opennessTiaPortalProject = GeneralSupport.GetOpennessProject(tiaTemplateContext.TiaProject);
126
127 switch (generationPhaseName)
128 {
129 case TiaGenerationPhases.Init:
130
131 if (!string.IsNullOrWhiteSpace(HardwareGenerationExcelBasedViewModel.ImportSource))
132 {
133 HardwareGenerationExcelBased.CreateNewDevicesFromExcelSheet(this, opennessTiaPortalProject,
134 HardwareGenerationExcelBasedViewModel.ImportSource);
135 }
136
137 if (!IsGenerateHardwareChecked)
138 {
139 break;
140 }
141
142 //Hardware config has to be in the Init phase.Otherwise, it can't be used in the MAC.
143 var s120 = HardwareGeneration.GenerateS120(this, "S120MACTest", "S120DeviceTest",
144 "this drive is generated with MAC");
145
146 var s210 = HardwareGeneration.GenerateS210(this, "S210MACTest", "S210DeviceTest",
147 "this drive is generated with MAC");
148 var subnet1 = HardwareGeneration.GetOrCreateSubnet(SubnetsManager, "PN/IE_1");
149
150 HardwareGeneration.ConnectDriveToSubnet(s120, subnet1, this);
151 HardwareGeneration.ConnectDriveToSubnet(s210, subnet1, this);
152
153 break;
154 case TiaGenerationPhases.Build:
155
156 // Add equipment module specific code generation here.
157 var opennessCpu = GeneralSupport.GetOpennessDeviceItem(tiaTemplateContext.TiaDevice);
158 _softwareUnit = SoftwareUnits.GetOrCreateSoftwareUnit(_plcDevice, "MyUnit", this);
159
160 // Configure a Technology Object
161 MyTo.ConfigureTO(MyTo.TechnologicalObject, this);
162 // Log messages
163 GeneralSupport.LogMessage(LogTypes.GenerationInfo, "Generate technology objects", this);
164 // Create Technology Object
165 TechnologyObjectClass.CreateTOs(_plcDevice, this);
166
167 IntegrateLibraries.CreateInstanceDB_via_XmlInstDB(this, ResourceManagement.MyFunctionBlock,
168 "CreatedDbFromMasterCopy_XmlInstDB", ResourceManagement.ModuleBlocksRootGroup, _plcDevice);
169
170 var myDataBlockGlobal =
171 GenericBlockCreation.GenerateGlobalDataBlock("MyDataBlock_Global", _plcDevice, this);
172
173 GenericBlockCreation.SetDefaultValue(myDataBlockGlobal.Name, "myParameterName", TIATYPE.INT, "99",
174 this);
175
176 GenericBlockCreation.GenerateMultiInstanceFB(_plcDevice,
177 tiaTemplateContext.TiaProject.GetEditingLanguage(), this);
178
179 var dbFromMasterCopy = IntegrateLibraries.CreateInstanceDataBlock(this,
180 ResourceManagement.MyFunctionBlock,
181 $"{nameof(ResourceManagement.MyFunctionBlock)}Db", ResourceManagement.ModuleBlocksRootGroup);
182
183 GenericBlockCreation.GenerateOB_Main(dbFromMasterCopy.Name, this,
184 tiaTemplateContext.TiaProject.GetEditingLanguage(), _plcDevice);
185
186 GenericBlockCreation.GenerateOBWithMultipleCalls("myOB", 10,
187 tiaTemplateContext.TiaProject.GetEditingLanguage(), _plcDevice, this);
188
189 GenericBlockCreation.CreateFunctionBlock($"{NameOfMyFb}_FBD", dbFromMasterCopy.Name,
190 ProgrammingLanguage.FBD,
191 _plcDevice);
192 GenericBlockCreation.CreateFunctionBlock($"{NameOfMyFb}_LAD", dbFromMasterCopy.Name,
193 ProgrammingLanguage.LAD,
194 _plcDevice);
195 GenericBlockCreation.CreateFunctionBlock($"{NameOfMyFb}_SCL", dbFromMasterCopy.Name,
196 ProgrammingLanguage.SCL,
197 _plcDevice);
198
199 var dbFromFailSafeFbMasterCopy = IntegrateLibraries.CreateInstanceDataBlock(this,
200 ResourceManagement.MyFunctionBlock_FailSafe,
201 $"{nameof(ResourceManagement.MyFunctionBlock_FailSafe)}Db",
202 ResourceManagement.ModuleBlocksRootGroup);
203
204 GenericBlockCreation.CreateFailSafeFunctionBlock($"{NameOfMyFailSafeFb}_F_LAD",
205 dbFromFailSafeFbMasterCopy.Name,
206 ProgrammingLanguage.F_LAD,
207 _plcDevice);
208 GenericBlockCreation.CreateFunctionBlockInSoftwareUnit(_softwareUnit, "MyFb_FBD",
209 ProgrammingLanguage.FBD);
210
211 var dbFromTypedMasterCopy = IntegrateLibraries.CreateInstanceDataBlock(this,
212 ResourceManagement.MyFunctionBlock_Typed,
213 $"{nameof(ResourceManagement.MyFunctionBlock_Typed)}Db", ResourceManagement.ModuleBlocksRootGroup);
214
215 GenericBlockCreation.CreateFunctionBlock($"{nameof(ResourceManagement.MyFunctionBlock_Typed)}_FBD",
216 dbFromTypedMasterCopy.Name,
217 ProgrammingLanguage.FBD,
218 _plcDevice);
219
220 var myTagTable = CreateVariables.CreateTagTable(_plcDevice, "myTagTable");
221 var mySoftwareUnitTagTable = CreateVariables.CreateTagTable(_softwareUnit, "mySoftwareUnitTagTable");
222
223 CreateVariables.CreateTagInTagTable(myTagTable, "%I", "187", "0", "myTag_0", "Bool", "myTagComment");
224 CreateVariables.CreateTagInTagTable(mySoftwareUnitTagTable, "%I", "188", "0", "myTag_1", "Bool",
225 "myTagComment");
226
227 if (IsGenerateHardwareChecked)
228 {
229 var hmiSoftware = HardwareGeneration.GetOrCreateHMISoftware(opennessTiaPortalProject, "HMI_1");
230 IntegrateLibraries.GenerateScreenFromMastercopy(hmiSoftware,
231 ResourceManagement.Lib_MAC_use_cases.Lib_Screen_1);
232 }
233
234 provider.CollectAttributes(Attributes);
235 provider.WriteValues(_plcDevice);
236 break;
237 }
238
239 return true;
240 }
241}
virtual void InitAfterFirstCreationOrDeserialization()
Every logic and setting must be here which is important at the first creation or deserialization of t...
virtual void CreateControlModules()
Creates Control Modules and adds them to the project.
This is the main class in which the workflow starts. Here are all sections for creating or generating...
string NameOfMyFb
This attribute is the string which is used for the renaming of the FB. This string can be changed in ...
PlcDevice _plcDevice
This attribute is the instance of the plcDevice.
string NameOfMyFailSafeFb
This attribute is the string which is used for the renaming of the safety-FB. This string can be chan...
TechnologyObjectClass MyTo
This attribute is the instance of the TechnologyObjectClass.
NonTIAProjectBased NonTiaProjectBased
This attribute is the instance for the serialization.
All the functions for non TIA Portal Project based operations are defined here.
All the functions to configure and generate Technology Objects are defined here.