Modular Application Creator Use Case Based Documentation
Loading...
Searching...
No Matches
HardwareGeneration.cs
1using System;
2using System.Linq;
3using Siemens.Automation.ModularApplicationCreator.MacPublishedObjects.Subnet;
4using Siemens.Automation.ModularApplicationCreator.Tia.Helper.TypeIdentifier;
5using Siemens.Automation.ModularApplicationCreator.Tia.Helper.TypeIdentifier.Enums;
6using Siemens.Automation.ModularApplicationCreator.Tia.Openness.DO;
7using Siemens.Engineering;
8using Siemens.Engineering.Hmi;
9using Siemens.Engineering.HW;
10using Siemens.Engineering.HW.Features;
11
13
18{
28 public static S120PNDriveInfo GenerateS120(MAC_use_casesEM module, string name, string deviceName,
29 string path = null, string comment = null)
30 {
31 if (!module.SynchronizedCollection.HardwareInterfaces.OfType<ProfiDriveObjectInfo>()
32 .Any(x => x.DriveDevice.Equals(name)))
33 {
34 var info = HardwareBlueprintFactory.CreateDrive(S120PNOrderNumbers.S120_CU_320_2_PN).LatestFirmware()
35 .CreateBlueprint(name, deviceName);
36
37 info.DevicePath = path;
38 info.Comment = comment;
39 info.PlcName = module.ParentDevice.Name;
40 info.CreateSingleAxis("SingleAxis", "OrderNumber:6SL3310-1TE32-1AAx", out _,
41 AxisDriveObjectType.Vector);
42
43 info.GetAxis("SingleAxis").PlcName = module.ParentDevice.Name;
44
45 module.SynchronizedCollection.HardwareInterfaces.Add(info);
46
47 return info;
48 }
49
50 return null;
51 }
52
62 public static S210DriveInfo GenerateS210(MAC_use_casesEM module, string name, string deviceName,
63 string path = null, string comment = null)
64 {
65 if (!module.SynchronizedCollection.HardwareInterfaces.OfType<ProfiDriveObjectInfo>()
66 .Any(x => x.DriveDevice.Equals(name)))
67 {
68 var info = HardwareBlueprintFactory.CreateDrive(S210OrderNumbers.S210_PN_3AC_7_kW).LatestFirmware()
69 .CreateBlueprint(name, deviceName);
70
71 info.DevicePath = path;
72 info.Comment = comment;
73 info.PlcName = module.ParentDevice.Name;
74
75 module.SynchronizedCollection.HardwareInterfaces.Add(info);
76
77 return info;
78 }
79
80 return null;
81 }
82
98 public static HmiTarget GetOrCreateHMISoftware(Project project, string name)
99 {
100 var hmiDevice = project.Devices.FirstOrDefault(x => x.Name == name) ??
101 project.Devices.CreateWithItem("OrderNumber:6AV2 125-2JB23-0AX0/17.0.0.0", name, name);
102 var hmiSoftwareContainer = hmiDevice.DeviceItems.FirstOrDefault(x => x.Name.Contains("HMI_RT"))
103 .GetService<SoftwareContainer>();
104 return hmiSoftwareContainer.Software as HmiTarget;
105 }
106
123 public static Device GetOrCreateDevice(Project project, string typeIdentifier, string name, string deviceName)
124 {
125 var device = project.Devices.FirstOrDefault(x => x.Name == name) ??
126 project.Devices.CreateWithItem(typeIdentifier, name, deviceName);
127 return device;
128 }
129
136 public static ISubnetInfo GetOrCreateSubnet(ISubnetsManager subnetsManager, string name)
137 {
138 return subnetsManager.GetOrCreateProfinet(name);
139 }
140
148 public static void ConnectDriveToSubnet(ProfiDriveObjectInfo drive, ISubnetInfo subnet, MAC_use_casesEM module)
149 {
150 var device = module.SynchronizedCollection.HardwareInterfaces.OfType<ProfiDriveObjectInfo>()
151 .FirstOrDefault(x => x.Name.Equals(drive.Name));
152
153 var plcNwItf = module.ParentDeviceAsHardwareInfo.ControllerProfinetInterfaces.First();
154 plcNwItf.ConnectedSubnetInfo = subnet;
155
156 var ioSystem = plcNwItf.ConnectedSubnetInfo.GetOrCreateIoSystem(plcNwItf, "PROFINET IO-System");
157
158 if (device.GetType() == typeof(S120PNDriveInfo))
159 {
160 (device as S120PNDriveInfo).ProfinetInterface.ConnectedSubnetInfo = subnet;
161 ioSystem.ConnectIoDevice((device as S120PNDriveInfo).ProfinetInterface.IoConnectors.First().Value);
162 plcNwItf.Ports.First().Connect((device as S120PNDriveInfo).ProfinetInterface.Ports.First());
163 }
164
165 if (device.GetType() == typeof(S210DriveInfo))
166 {
167 (device as S210DriveInfo).ProfinetInterface.ConnectedSubnetInfo = subnet;
168 ioSystem.ConnectIoDevice((device as S210DriveInfo).ProfinetInterface.IoConnectors.First().Value);
169 plcNwItf.Ports.First().Connect((device as S210DriveInfo).ProfinetInterface.Ports.First());
170 }
171 }
172}
This is the main class in which the workflow starts. Here are all sections for creating or generating...
All the functions to configure and generate Hardware are defined here.
static Device GetOrCreateDevice(Project project, string typeIdentifier, string name, string deviceName)
Creates or retrieves a device in the TIA Portal project based on the specified parameters.
static S210DriveInfo GenerateS210(MAC_use_casesEM module, string name, string deviceName, string path=null, string comment=null)
This function generates an S210 Drive based on a MasterCopy.
static S120PNDriveInfo GenerateS120(MAC_use_casesEM module, string name, string deviceName, string path=null, string comment=null)
This function generates an S120 Drive based on a MasterCopy.
static void ConnectDriveToSubnet(ProfiDriveObjectInfo drive, ISubnetInfo subnet, MAC_use_casesEM module)
Connects the desired drive to the desired subnet.
static ISubnetInfo GetOrCreateSubnet(ISubnetsManager subnetsManager, string name)
Gets or creates a subnet with the desired name.
static HmiTarget GetOrCreateHMISoftware(Project project, string name)
Creates or retrieves an HMI device in the TIA Portal project.