Modular Application Creator Use Case Based Documentation
Loading...
Searching...
No Matches
MAC_use_casesEM.cs
2using System.Collections.ObjectModel;
4using MAC_use_cases.ViewModel;
5using Newtonsoft.Json;
6using Siemens.Automation.ModularApplicationCreator.Modules;
7using Siemens.Automation.ModularApplicationCreator.Serializer;
8using Siemens.Automation.ModularApplicationCreator.Tia;
9using Siemens.Automation.ModularApplicationCreator.Tia.Helper;
10using Siemens.Automation.ModularApplicationCreator.Tia.Helper.Create_XML_Block;
11using Siemens.Automation.ModularApplicationCreator.Tia.Modules;
12using Siemens.Automation.ModularApplicationCreator.Tia.Openness;
13using Siemens.Automation.ModularApplicationCreator.Tia.Openness.SoftwareUnit;
14using Siemens.Automation.ModularApplicationCreator.Tia.TiaAttributeFuncs;
15using Siemens.Automation.ModularApplicationCreatorBasics.Logging;
16
17namespace MAC_use_cases.Model
18{
23 public class MAC_use_casesEM : BaseMAC_use_casesEM
24 {
28 private PlcDevice _plcDevice;
29
30 private ISoftwareUnit _softwareUnit;
31
32 // <auto-generated>
33 // This code was generated by a tool. Do not remove or modify the syntax of it.
34 // This constructor is used at first creation of this object.
35 // </auto-generated>
36 public MAC_use_casesEM()
37 {
38 // This Function can be modified to accommodate the Control Modules used in this Equipment Module
40 // Add any code here which is needed to be used only when this object is created the first time.
41
43
44 MyTo = new TechnologyObjectClass(this);
46 }
47
48 // <auto-generated>
49 // This code was generated by a tool. Do not remove or modify the syntax of it.
50 // This constructor is used only for deserialization.
51 // </auto-generated>
52 [JsonConstructor]
53 public MAC_use_casesEM(JsonConstructorMarker nullObj)
54 {
55 // Add any code here which is only necessary when this object is deserialized.
56
58
59 MyTo = new TechnologyObjectClass(this);
61 }
62
63 //-------------------------------------------
64 // This ModuleStart property is generated.
65 // It must be at the top of the class. It is used during module update.
66 //
67 // CAUTION: Do not use public instance variables as they overtake the properties in serialization.
68 //-------------------------------------------
69 public ModuleEdge ModuleStart
70 {
71 get => TopLevelEM ? new ModuleEdge() : null;
72 set { }
73 }
74
75 public HardwareGenerationExcelBasedViewModel HardwareGenerationExcelBasedViewModel { get; set; } = new HardwareGenerationExcelBasedViewModel();
76
80 public TechnologyObjectClass MyTo { get; set; }
81
85 [JsonIgnore]
87
88 public bool IsGenerateHardwareChecked { get; set; } = false;
89
90 public bool IsGenerateSafetyBlockChecked { get; set; } = false;
94 public NonTIAProjectBased NonTiaProjectBased { get; set; } = new NonTIAProjectBased("myModel");
95
100 public string NameOfMyFb { get; set; } = "MyFunctionBlock";
101
106 public string NameOfMyFailSafeFb { get; set; } = "MyFunctionBlock_FailSafe";
107
112 public override bool IsAdditionalReadOutRequired() => false;
113
114 [JsonIgnore]
115 public ObservableCollection<string> PlcBlockNames { get; set; } = new ObservableCollection<string>();
116
117 public override void ReadTiaPortalAfterAssignOrUpdate(TiaTemplateContext tiaTemplateContext)
118 {
119 base.ReadTiaPortalAfterAssignOrUpdate(tiaTemplateContext);
121 }
122
123 [JsonIgnore]
124 public string NameAndType
125 {
126 get => NamingConventions.CreateModuleNameAndTypeForEM("MAC_use_cases", this);
127 }
128
129 public override bool GenerateTiaPortal(TiaTemplateContext tiaTemplateContext, string generationPhaseName)
130 {
131 switch (generationPhaseName)
132 {
133 case TiaGenerationPhases.Init:
134 _plcDevice = GetPlcDevice(tiaTemplateContext);
135 break;
136
137 // Add equipment module specific code for each generation phase here, which is
138 // necessary before the ResourceManagement is called.
139 }
140
141 ResourceManagement.Generate(tiaTemplateContext, this, generationPhaseName);
142
143 foreach (var module in ControlModules)
144 {
145 if (module is ITiaGenerateable tiaGen)
146 {
147 tiaGen.GenerateTiaPortal(tiaTemplateContext, generationPhaseName);
148 }
149 }
150
151 var opennessTiaPortalProject = GeneralSupport.GetOpennessProject(tiaTemplateContext.TiaProject);
152
153 switch (generationPhaseName)
154 {
155 case TiaGenerationPhases.Init:
156
157 //if (!string.IsNullOrWhiteSpace(HardwareGenerationExcelBasedViewModel.ImportSource))
158 //{
159 // HardwareGenerationExcelBased.CreateNewDevicesFromExcelSheet(this, opennessTiaPortalProject,
160 // HardwareGenerationExcelBasedViewModel.ImportSource);
161 //}
162
163 //if (!IsGenerateHardwareChecked)
164 //{
165 // break;
166 //}
167
168 //Hardware config has to be in the Init phase.Otherwise, it can't be used in the MAC.
169 var s120 = HardwareGeneration.GenerateS120(this, "S120MACTest", "S120DeviceTest",
170 "this drive is generated with MAC");
171
172 var s210 = HardwareGeneration.GenerateS210(this, "S210MACTest", "S210DeviceTest",
173 "this drive is generated with MAC");
174 //var subnet1 = HardwareGeneration.GetOrCreateSubnet(SubnetsManager, "PN/IE_1");
175
176 //HardwareGeneration.ConnectDriveToSubnet(s120, subnet1, this);
177 //HardwareGeneration.ConnectDriveToSubnet(s210, subnet1, this);
178
179 break;
180 case TiaGenerationPhases.Build:
181
182 // Add equipment module specific code generation here.
183 var opennessCpu = GeneralSupport.GetOpennessDeviceItem(tiaTemplateContext.TiaDevice);
184 _softwareUnit = SoftwareUnits.GetOrCreateSoftwareUnit(_plcDevice, "MyUnit", this, "Namesapce_example");
185
186 // Configure a Technology Object
187 MyTo.ConfigureTO(MyTo.TechnologicalObject, this);
188 // Log messages
189 GeneralSupport.LogMessage(LogTypes.GenerationInfo, "Generate technology objects", this);
190 // Create Technology Object
191 TechnologyObjectClass.CreateTOs(_plcDevice, this);
192
193 IntegrateLibraries.CreateInstanceDB_via_XmlInstDB(this, ResourceManagement.MyFunctionBlock,
194 "CreatedDbFromMasterCopy_XmlInstDB", ResourceManagement.ModuleBlocksRootGroup, _plcDevice);
195
196 var myDataBlockGlobal =
197 GenericBlockCreation.GenerateGlobalDataBlock("MyDataBlock_Global", _plcDevice, this);
198
199 GenericBlockCreation.SetDefaultValue(myDataBlockGlobal.Name, "myParameterName", TIATYPE.INT, "99",
200 this);
201
202 GenericBlockCreation.GenerateMultiInstanceFB(_plcDevice,
203 tiaTemplateContext.TiaProject.GetEditingLanguage(), this);
204
205 var dbFromMasterCopy = IntegrateLibraries.CreateInstanceDataBlock(this,
206 ResourceManagement.MyFunctionBlock,
207 $"{nameof(ResourceManagement.MyFunctionBlock)}Db", ResourceManagement.ModuleBlocksRootGroup);
208
209 GenericBlockCreation.GenerateOB_Main(dbFromMasterCopy.Name, this,
210 tiaTemplateContext.TiaProject.GetEditingLanguage(), _plcDevice);
211
212 GenericBlockCreation.GenerateOBWithMultipleCalls("myOB", 10,
213 tiaTemplateContext.TiaProject.GetEditingLanguage(), _plcDevice, this);
214
215 GenericBlockCreation.CreateFunctionBlock($"{NameOfMyFb}_FBD", dbFromMasterCopy.Name,
216 ProgrammingLanguage.FBD,
217 _plcDevice);
218 GenericBlockCreation.CreateFunctionBlock($"{NameOfMyFb}_LAD", dbFromMasterCopy.Name,
219 ProgrammingLanguage.LAD,
220 _plcDevice);
221 GenericBlockCreation.CreateFunctionBlock($"{NameOfMyFb}_SCL", dbFromMasterCopy.Name,
222 ProgrammingLanguage.SCL,
223 _plcDevice);
224
225 var dbFromFailSafeFbMasterCopy = IntegrateLibraries.CreateInstanceDataBlock(this,
226 ResourceManagement.MyFunctionBlock_FailSafe,
227 $"{nameof(ResourceManagement.MyFunctionBlock_FailSafe)}Db",
228 ResourceManagement.ModuleBlocksRootGroup);
229
230 if (IsGenerateSafetyBlockChecked)
231 {
232 GenericBlockCreation.CreateFailSafeFunctionBlock($"{NameOfMyFailSafeFb}_F_LAD",
233 dbFromFailSafeFbMasterCopy.Name,
234 ProgrammingLanguage.F_LAD,
235 _plcDevice);
236 }
237 GenericBlockCreation.CreateFunctionBlockInSoftwareUnit(_softwareUnit, "MyFb_FBD",
238 ProgrammingLanguage.FBD, _plcDevice);
239 GenericBlockCreation.CreateFunctionBlockInSoftwareUnit(_softwareUnit, "MyFb_LAD",
240 ProgrammingLanguage.LAD, _plcDevice);
241 GenericBlockCreation.CreateFunctionBlockInSoftwareUnit(_softwareUnit, "MyFb_SCL", ProgrammingLanguage.SCL, _plcDevice);
242
243 var dbFromTypedMasterCopy = IntegrateLibraries.CreateInstanceDataBlock(this,
244 ResourceManagement.MyFunctionBlock_Typed,
245 $"{nameof(ResourceManagement.MyFunctionBlock_Typed)}Db", ResourceManagement.ModuleBlocksRootGroup);
246
247 GenericBlockCreation.CreateFunctionBlock($"{nameof(ResourceManagement.MyFunctionBlock_Typed)}_FBD",
248 dbFromTypedMasterCopy.Name,
249 ProgrammingLanguage.FBD,
250 _plcDevice);
251
252 var myTagTable = CreateVariables.CreateTagTable(_plcDevice, "myTagTable");
253 var mySoftwareUnitTagTable = CreateVariables.CreateTagTable(_softwareUnit, "mySoftwareUnitTagTable");
254
255 CreateVariables.CreateTagInTagTable(myTagTable, "%I", "187", "0", "myTag_0", "Bool", "myTagComment");
256 CreateVariables.CreateTagInTagTable(mySoftwareUnitTagTable, "%I", "188", "0", "myTag_1", "Bool",
257 "myTagComment");
258 this.MyEssentialTechnologyObjectViewModel.Model.AddTechnologicalObjectParams();
259 this._plcDevice.TechnologicalObjects.GetOrCreateRootTO(MyEssentialTechnologyObjectViewModel.Model
260 .TechObjectInfo, this);
261
262 if (IsGenerateHardwareChecked)
263 {
264 var hmiSoftware = HardwareGeneration.GetOrCreateHMISoftware(opennessTiaPortalProject, "HMI_1");
265 IntegrateLibraries.GenerateScreenFromMastercopy(hmiSoftware,
266 ResourceManagement.Lib_MAC_use_cases.Lib_Screen_1);
267 }
268
269 provider.CollectAttributes(Attributes);
270 provider.WriteValues(_plcDevice);
271 break;
272 }
273
274 return true;
275 }
276 }
277}
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 ...
TechnologyObjectViewModel MyEssentialTechnologyObjectViewModel
Gets or sets the essential data model for the technology object (Example of using Module Essentials).
override bool IsAdditionalReadOutRequired()
Controls whether additional readout from TIA Portal is required. Set this to true when you need to re...
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.
This are functions that support you in different ways while using Modular Application Creator.
static void ReadAdditionalInformationsFromTIAPortalProject(MAC_use_casesEM module, TiaTemplateContext tiaTemplateContext)
Reads additional information from the TIA Portal project and populates MAC_use_casesEM....
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.