23 public class MAC_use_casesEM : BaseMAC_use_casesEM
30 private ISoftwareUnit _softwareUnit;
36 public MAC_use_casesEM()
69 public ModuleEdge ModuleStart
71 get => TopLevelEM ?
new ModuleEdge() : null;
75 public HardwareGenerationExcelBasedViewModel HardwareGenerationExcelBasedViewModel {
get;
set; } =
new HardwareGenerationExcelBasedViewModel();
88 public bool IsGenerateHardwareChecked {
get;
set; } =
false;
90 public bool IsGenerateSafetyBlockChecked {
get;
set; } =
false;
115 public ObservableCollection<string> PlcBlockNames {
get;
set; } =
new ObservableCollection<string>();
117 public override void ReadTiaPortalAfterAssignOrUpdate(TiaTemplateContext tiaTemplateContext)
119 base.ReadTiaPortalAfterAssignOrUpdate(tiaTemplateContext);
124 public string NameAndType
126 get => NamingConventions.CreateModuleNameAndTypeForEM(
"MAC_use_cases",
this);
129 public override bool GenerateTiaPortal(TiaTemplateContext tiaTemplateContext,
string generationPhaseName)
131 switch (generationPhaseName)
133 case TiaGenerationPhases.Init:
134 _plcDevice = GetPlcDevice(tiaTemplateContext);
141 ResourceManagement.Generate(tiaTemplateContext,
this, generationPhaseName);
143 foreach (var module
in ControlModules)
145 if (module is ITiaGenerateable tiaGen)
147 tiaGen.GenerateTiaPortal(tiaTemplateContext, generationPhaseName);
151 var opennessTiaPortalProject = GeneralSupport.GetOpennessProject(tiaTemplateContext.TiaProject);
153 switch (generationPhaseName)
155 case TiaGenerationPhases.Init:
169 var s120 = HardwareGeneration.GenerateS120(
this,
"S120MACTest",
"S120DeviceTest",
170 "this drive is generated with MAC");
172 var s210 = HardwareGeneration.GenerateS210(
this,
"S210MACTest",
"S210DeviceTest",
173 "this drive is generated with MAC");
180 case TiaGenerationPhases.Build:
183 var opennessCpu = GeneralSupport.GetOpennessDeviceItem(tiaTemplateContext.TiaDevice);
184 _softwareUnit = SoftwareUnits.GetOrCreateSoftwareUnit(
_plcDevice,
"MyUnit",
this,
"Namesapce_example");
187 MyTo.ConfigureTO(
MyTo.TechnologicalObject,
this);
189 GeneralSupport.LogMessage(LogTypes.GenerationInfo,
"Generate technology objects",
this);
191 TechnologyObjectClass.CreateTOs(
_plcDevice,
this);
193 IntegrateLibraries.CreateInstanceDB_via_XmlInstDB(
this, ResourceManagement.MyFunctionBlock,
194 "CreatedDbFromMasterCopy_XmlInstDB", ResourceManagement.ModuleBlocksRootGroup,
_plcDevice);
196 var myDataBlockGlobal =
197 GenericBlockCreation.GenerateGlobalDataBlock(
"MyDataBlock_Global",
_plcDevice,
this);
199 GenericBlockCreation.SetDefaultValue(myDataBlockGlobal.Name,
"myParameterName", TIATYPE.INT,
"99",
202 GenericBlockCreation.GenerateMultiInstanceFB(
_plcDevice,
203 tiaTemplateContext.TiaProject.GetEditingLanguage(),
this);
205 var dbFromMasterCopy = IntegrateLibraries.CreateInstanceDataBlock(
this,
206 ResourceManagement.MyFunctionBlock,
207 $
"{nameof(ResourceManagement.MyFunctionBlock)}Db", ResourceManagement.ModuleBlocksRootGroup);
209 GenericBlockCreation.GenerateOB_Main(dbFromMasterCopy.Name,
this,
210 tiaTemplateContext.TiaProject.GetEditingLanguage(),
_plcDevice);
212 GenericBlockCreation.GenerateOBWithMultipleCalls(
"myOB", 10,
213 tiaTemplateContext.TiaProject.GetEditingLanguage(),
_plcDevice,
this);
215 GenericBlockCreation.CreateFunctionBlock($
"{NameOfMyFb}_FBD", dbFromMasterCopy.Name,
216 ProgrammingLanguage.FBD,
218 GenericBlockCreation.CreateFunctionBlock($
"{NameOfMyFb}_LAD", dbFromMasterCopy.Name,
219 ProgrammingLanguage.LAD,
221 GenericBlockCreation.CreateFunctionBlock($
"{NameOfMyFb}_SCL", dbFromMasterCopy.Name,
222 ProgrammingLanguage.SCL,
225 var dbFromFailSafeFbMasterCopy = IntegrateLibraries.CreateInstanceDataBlock(
this,
226 ResourceManagement.MyFunctionBlock_FailSafe,
227 $
"{nameof(ResourceManagement.MyFunctionBlock_FailSafe)}Db",
228 ResourceManagement.ModuleBlocksRootGroup);
230 if (IsGenerateSafetyBlockChecked)
232 GenericBlockCreation.CreateFailSafeFunctionBlock($
"{NameOfMyFailSafeFb}_F_LAD",
233 dbFromFailSafeFbMasterCopy.Name,
234 ProgrammingLanguage.F_LAD,
237 GenericBlockCreation.CreateFunctionBlockInSoftwareUnit(_softwareUnit,
"MyFb_FBD",
239 GenericBlockCreation.CreateFunctionBlockInSoftwareUnit(_softwareUnit,
"MyFb_LAD",
241 GenericBlockCreation.CreateFunctionBlockInSoftwareUnit(_softwareUnit,
"MyFb_SCL", ProgrammingLanguage.SCL,
_plcDevice);
243 var dbFromTypedMasterCopy = IntegrateLibraries.CreateInstanceDataBlock(
this,
244 ResourceManagement.MyFunctionBlock_Typed,
245 $
"{nameof(ResourceManagement.MyFunctionBlock_Typed)}Db", ResourceManagement.ModuleBlocksRootGroup);
247 GenericBlockCreation.CreateFunctionBlock($
"{nameof(ResourceManagement.MyFunctionBlock_Typed)}_FBD",
248 dbFromTypedMasterCopy.Name,
249 ProgrammingLanguage.FBD,
252 var myTagTable = CreateVariables.CreateTagTable(
_plcDevice,
"myTagTable");
253 var mySoftwareUnitTagTable = CreateVariables.CreateTagTable(_softwareUnit,
"mySoftwareUnitTagTable");
255 CreateVariables.CreateTagInTagTable(myTagTable,
"%I",
"187",
"0",
"myTag_0",
"Bool",
"myTagComment");
256 CreateVariables.CreateTagInTagTable(mySoftwareUnitTagTable,
"%I",
"188",
"0",
"myTag_1",
"Bool",
260 .TechObjectInfo,
this);
262 if (IsGenerateHardwareChecked)
264 var hmiSoftware = HardwareGeneration.GetOrCreateHMISoftware(opennessTiaPortalProject,
"HMI_1");
265 IntegrateLibraries.GenerateScreenFromMastercopy(hmiSoftware,
266 ResourceManagement.Lib_MAC_use_cases.Lib_Screen_1);
269 provider.CollectAttributes(Attributes);