|
| 1 | +using System.Linq; |
| 2 | +using Siemens.Automation.ModularApplicationCreator.MacPublishedObjects.Subnet; |
1 | 3 | using Siemens.Automation.ModularApplicationCreator.Tia.Helper.TypeIdentifier;
|
2 | 4 | using Siemens.Automation.ModularApplicationCreator.Tia.Helper.TypeIdentifier.Enums;
|
3 | 5 | using Siemens.Automation.ModularApplicationCreator.Tia.Openness.DO;
|
| 6 | +using Siemens.Engineering; |
4 | 7 | using Siemens.Engineering.Hmi;
|
5 | 8 | using Siemens.Engineering.HW.Features;
|
6 |
| -using System.Linq; |
7 |
| -using Siemens.Automation.ModularApplicationCreator.MacPublishedObjects.Subnet; |
8 |
| -using Siemens.Engineering; |
9 | 9 |
|
10 |
| -namespace MAC_use_cases.Model.UseCases |
| 10 | +namespace MAC_use_cases.Model.UseCases; |
| 11 | + |
| 12 | +/// <summary> |
| 13 | +/// All the functions to configure and generate Hardware are defined here. |
| 14 | +/// </summary> |
| 15 | +public class HardwareGeneration |
11 | 16 | {
|
12 | 17 | /// <summary>
|
13 |
| - /// All the functions to configure and generate Hardware are defined here. |
| 18 | + /// This function generates an S120 Drive based on a MasterCopy |
| 19 | + /// \image html GenerateS120.png |
14 | 20 | /// </summary>
|
15 |
| - public class HardwareGeneration |
| 21 | + /// <param name="module">The Module</param> |
| 22 | + /// <param name="name">The name of the drive</param> |
| 23 | + /// <param name="deviceName">The name of the device</param> |
| 24 | + /// <param name="path">Path if necessary</param> |
| 25 | + /// <param name="comment">Comment if necessary</param> |
| 26 | + public static S120PNDriveInfo GenerateS120(MAC_use_casesEM module, string name, string deviceName, |
| 27 | + string path = null, string comment = null) |
16 | 28 | {
|
17 |
| - /// <summary> |
18 |
| - /// This function generates an S120 Drive based on a MasterCopy |
19 |
| - /// \image html GenerateS120.png |
20 |
| - /// </summary> |
21 |
| - /// <param name="module">The Module</param> |
22 |
| - /// <param name="name">The name of the drive</param> |
23 |
| - /// <param name="deviceName">The name of the device</param> |
24 |
| - /// <param name="path">Path if necessary</param> |
25 |
| - /// <param name="comment">Comment if necessary</param> |
26 |
| - public static S120PNDriveInfo GenerateS120(MAC_use_casesEM module, string name, string deviceName, |
27 |
| - string path = null, string comment = null) |
| 29 | + if (!module.SynchronizedCollection.HardwareInterfaces.OfType<ProfiDriveObjectInfo>() |
| 30 | + .Any(x => x.DriveDevice.Equals(name))) |
28 | 31 | {
|
29 |
| - if (!module.SynchronizedCollection.HardwareInterfaces.OfType<ProfiDriveObjectInfo>() |
30 |
| - .Any(x => x.DriveDevice.Equals(name))) |
31 |
| - { |
32 |
| - var info = HardwareBlueprintFactory.CreateDrive(S120PNOrderNumbers.S120_CU_320_2_PN).LatestFirmware() |
33 |
| - .CreateBlueprint(name, deviceName); |
| 32 | + var info = HardwareBlueprintFactory.CreateDrive(S120PNOrderNumbers.S120_CU_320_2_PN).LatestFirmware() |
| 33 | + .CreateBlueprint(name, deviceName); |
34 | 34 |
|
35 |
| - info.DevicePath = path; |
36 |
| - info.Comment = comment; |
37 |
| - info.PlcName = module.ParentDevice.Name; |
38 |
| - info.CreateSingleAxis("SingleAxis", "OrderNumber:6SL3310-1TE32-1AAx", out _, |
39 |
| - AxisDriveObjectType.Vector); |
| 35 | + info.DevicePath = path; |
| 36 | + info.Comment = comment; |
| 37 | + info.PlcName = module.ParentDevice.Name; |
| 38 | + info.CreateSingleAxis("SingleAxis", "OrderNumber:6SL3310-1TE32-1AAx", out _, |
| 39 | + AxisDriveObjectType.Vector); |
40 | 40 |
|
41 |
| - info.GetAxis("SingleAxis").PlcName = module.ParentDevice.Name; |
| 41 | + info.GetAxis("SingleAxis").PlcName = module.ParentDevice.Name; |
42 | 42 |
|
43 |
| - module.SynchronizedCollection.HardwareInterfaces.Add(info); |
| 43 | + module.SynchronizedCollection.HardwareInterfaces.Add(info); |
44 | 44 |
|
45 |
| - return info; |
46 |
| - } |
47 |
| - |
48 |
| - return null; |
| 45 | + return info; |
49 | 46 | }
|
50 | 47 |
|
51 |
| - /// <summary> |
52 |
| - /// This function generates an S210 Drive based on a MasterCopy |
53 |
| - /// \image html GenerateS210.png |
54 |
| - /// </summary> |
55 |
| - /// <param name="module">The Module</param> |
56 |
| - /// <param name="name">The name of the drive</param> |
57 |
| - /// <param name="deviceName">The name of the device</param> |
58 |
| - /// <param name="path">Path if necessary</param> |
59 |
| - /// <param name="comment">Comment if necessary</param> |
60 |
| - public static S210DriveInfo GenerateS210(MAC_use_casesEM module, string name, string deviceName, |
61 |
| - string path = null, string comment = null) |
| 48 | + return null; |
| 49 | + } |
| 50 | + |
| 51 | + /// <summary> |
| 52 | + /// This function generates an S210 Drive based on a MasterCopy |
| 53 | + /// \image html GenerateS210.png |
| 54 | + /// </summary> |
| 55 | + /// <param name="module">The Module</param> |
| 56 | + /// <param name="name">The name of the drive</param> |
| 57 | + /// <param name="deviceName">The name of the device</param> |
| 58 | + /// <param name="path">Path if necessary</param> |
| 59 | + /// <param name="comment">Comment if necessary</param> |
| 60 | + public static S210DriveInfo GenerateS210(MAC_use_casesEM module, string name, string deviceName, |
| 61 | + string path = null, string comment = null) |
| 62 | + { |
| 63 | + if (!module.SynchronizedCollection.HardwareInterfaces.OfType<ProfiDriveObjectInfo>() |
| 64 | + .Any(x => x.DriveDevice.Equals(name))) |
62 | 65 | {
|
63 |
| - if (!module.SynchronizedCollection.HardwareInterfaces.OfType<ProfiDriveObjectInfo>() |
64 |
| - .Any(x => x.DriveDevice.Equals(name))) |
65 |
| - { |
66 |
| - var info = HardwareBlueprintFactory.CreateDrive(S210OrderNumbers.S210_PN_3AC_7_kW).LatestFirmware() |
67 |
| - .CreateBlueprint(name, deviceName); |
| 66 | + var info = HardwareBlueprintFactory.CreateDrive(S210OrderNumbers.S210_PN_3AC_7_kW).LatestFirmware() |
| 67 | + .CreateBlueprint(name, deviceName); |
68 | 68 |
|
69 |
| - info.DevicePath = path; |
70 |
| - info.Comment = comment; |
71 |
| - info.PlcName = module.ParentDevice.Name; |
| 69 | + info.DevicePath = path; |
| 70 | + info.Comment = comment; |
| 71 | + info.PlcName = module.ParentDevice.Name; |
72 | 72 |
|
73 |
| - module.SynchronizedCollection.HardwareInterfaces.Add(info); |
| 73 | + module.SynchronizedCollection.HardwareInterfaces.Add(info); |
74 | 74 |
|
75 |
| - return info; |
76 |
| - } |
77 |
| - return null; |
| 75 | + return info; |
78 | 76 | }
|
79 | 77 |
|
80 |
| - /// <summary> |
81 |
| - /// This call returns the openness object of an HMI with the desired name. If it exists, it will be returned. If not, it will create a new one. |
82 |
| - /// \image html GetOrCreateHMI.png |
83 |
| - /// </summary> |
84 |
| - /// <param name="project">This object is the openness object of the TIA Portal project</param> |
85 |
| - /// <param name="name">Thats the desired name of the HMI Device</param> |
86 |
| - public static HmiTarget GetOrCreateHMISoftware(Project project, string name) |
87 |
| - { |
88 |
| - var hmiDevice = project.Devices.FirstOrDefault(x => x.Name == name); |
89 |
| - if (hmiDevice == null) |
90 |
| - { |
91 |
| - hmiDevice = project.Devices.CreateWithItem("OrderNumber:6AV2 125-2JB23-0AX0/17.0.0.0", name, name); |
92 |
| - } |
93 |
| - var hmiSoftwareContainer = hmiDevice.DeviceItems.FirstOrDefault(x => x.Name.Contains("HMI_RT")).GetService<SoftwareContainer>(); |
94 |
| - return hmiSoftwareContainer.Software as HmiTarget; |
95 |
| - } |
| 78 | + return null; |
| 79 | + } |
96 | 80 |
|
97 |
| - /// <summary> |
98 |
| - /// Gets or creates a subnet with the desired name |
99 |
| - /// \image html GetOrCreateSubnet.png |
100 |
| - /// </summary> |
101 |
| - /// <param name="subnetsManager">The Modular Application Creator helper object</param> |
102 |
| - /// <param name="name">The name of the subnet</param> |
103 |
| - public static ISubnetInfo GetOrCreateSubnet(ISubnetsManager subnetsManager, string name) |
104 |
| - { |
105 |
| - return subnetsManager.GetOrCreateProfinet(name); |
106 |
| - } |
| 81 | + /// <summary> |
| 82 | + /// This call returns the openness object of an HMI with the desired name. If it exists, it will be returned. If not, |
| 83 | + /// it will create a new one. |
| 84 | + /// \image html GetOrCreateHMI.png |
| 85 | + /// </summary> |
| 86 | + /// <param name="project">This object is the openness object of the TIA Portal project</param> |
| 87 | + /// <param name="name">That's the desired name of the HMI Device</param> |
| 88 | + public static HmiTarget GetOrCreateHMISoftware(Project project, string name) |
| 89 | + { |
| 90 | + var hmiDevice = project.Devices.FirstOrDefault(x => x.Name == name); |
| 91 | + if (hmiDevice == null) |
| 92 | + hmiDevice = project.Devices.CreateWithItem("OrderNumber:6AV2 125-2JB23-0AX0/17.0.0.0", name, name); |
| 93 | + var hmiSoftwareContainer = hmiDevice.DeviceItems.FirstOrDefault(x => x.Name.Contains("HMI_RT")) |
| 94 | + .GetService<SoftwareContainer>(); |
| 95 | + return hmiSoftwareContainer.Software as HmiTarget; |
| 96 | + } |
107 | 97 |
|
108 |
| - /// <summary> |
109 |
| - /// Connectes the desired drive to the desired subnet |
110 |
| - /// \image html ConnectDriveToSubnet.png |
111 |
| - /// </summary> |
112 |
| - /// <param name="drive">The desired drive</param> |
113 |
| - /// <param name="subnet">The desired subnet</param> |
114 |
| - /// <param name="module">The module</param> |
115 |
| - public static void ConnectDriveToSubnet(ProfiDriveObjectInfo drive, ISubnetInfo subnet, MAC_use_casesEM module) |
116 |
| - { |
117 |
| - var device = module.SynchronizedCollection.HardwareInterfaces.OfType<ProfiDriveObjectInfo>().FirstOrDefault(x => x.Name.Equals(drive.Name)); |
| 98 | + /// <summary> |
| 99 | + /// Gets or creates a subnet with the desired name |
| 100 | + /// \image html GetOrCreateSubnet.png |
| 101 | + /// </summary> |
| 102 | + /// <param name="subnetsManager">The Modular Application Creator helper object</param> |
| 103 | + /// <param name="name">The name of the subnet</param> |
| 104 | + public static ISubnetInfo GetOrCreateSubnet(ISubnetsManager subnetsManager, string name) |
| 105 | + { |
| 106 | + return subnetsManager.GetOrCreateProfinet(name); |
| 107 | + } |
118 | 108 |
|
119 |
| - var plcNwItf = module.ParentDeviceAsHardwareInfo.ControllerProfinetInterfaces.First(); |
120 |
| - plcNwItf.ConnectedSubnetInfo = subnet; |
| 109 | + /// <summary> |
| 110 | + /// Connects the desired drive to the desired subnet |
| 111 | + /// \image html ConnectDriveToSubnet.png |
| 112 | + /// </summary> |
| 113 | + /// <param name="drive">The desired drive</param> |
| 114 | + /// <param name="subnet">The desired subnet</param> |
| 115 | + /// <param name="module">The module</param> |
| 116 | + public static void ConnectDriveToSubnet(ProfiDriveObjectInfo drive, ISubnetInfo subnet, MAC_use_casesEM module) |
| 117 | + { |
| 118 | + var device = module.SynchronizedCollection.HardwareInterfaces.OfType<ProfiDriveObjectInfo>() |
| 119 | + .FirstOrDefault(x => x.Name.Equals(drive.Name)); |
121 | 120 |
|
122 |
| - var ioSystem = plcNwItf.ConnectedSubnetInfo.GetOrCreateIoSystem(plcNwItf, "PROFINET IO-System"); |
| 121 | + var plcNwItf = module.ParentDeviceAsHardwareInfo.ControllerProfinetInterfaces.First(); |
| 122 | + plcNwItf.ConnectedSubnetInfo = subnet; |
123 | 123 |
|
124 |
| - if (device.GetType() == typeof(S120PNDriveInfo)) |
125 |
| - { |
126 |
| - (device as S120PNDriveInfo).ProfinetInterface.ConnectedSubnetInfo = subnet; |
127 |
| - ioSystem.ConnectIoDevice((device as S120PNDriveInfo).ProfinetInterface.IoConnectors.First().Value); |
128 |
| - plcNwItf.Ports.First().Connect((device as S120PNDriveInfo).ProfinetInterface.Ports.First()); |
129 |
| - } |
130 |
| - if (device.GetType() == typeof(S210DriveInfo)) |
131 |
| - { |
132 |
| - (device as S210DriveInfo).ProfinetInterface.ConnectedSubnetInfo = subnet; |
133 |
| - ioSystem.ConnectIoDevice((device as S210DriveInfo).ProfinetInterface.IoConnectors.First().Value); |
134 |
| - plcNwItf.Ports.First().Connect((device as S210DriveInfo).ProfinetInterface.Ports.First()); |
135 |
| - } |
| 124 | + var ioSystem = plcNwItf.ConnectedSubnetInfo.GetOrCreateIoSystem(plcNwItf, "PROFINET IO-System"); |
136 | 125 |
|
| 126 | + if (device.GetType() == typeof(S120PNDriveInfo)) |
| 127 | + { |
| 128 | + (device as S120PNDriveInfo).ProfinetInterface.ConnectedSubnetInfo = subnet; |
| 129 | + ioSystem.ConnectIoDevice((device as S120PNDriveInfo).ProfinetInterface.IoConnectors.First().Value); |
| 130 | + plcNwItf.Ports.First().Connect((device as S120PNDriveInfo).ProfinetInterface.Ports.First()); |
| 131 | + } |
137 | 132 |
|
| 133 | + if (device.GetType() == typeof(S210DriveInfo)) |
| 134 | + { |
| 135 | + (device as S210DriveInfo).ProfinetInterface.ConnectedSubnetInfo = subnet; |
| 136 | + ioSystem.ConnectIoDevice((device as S210DriveInfo).ProfinetInterface.IoConnectors.First().Value); |
| 137 | + plcNwItf.Ports.First().Connect((device as S210DriveInfo).ProfinetInterface.Ports.First()); |
138 | 138 | }
|
139 | 139 | }
|
140 | 140 | }
|
0 commit comments