|
1 |
| -using Siemens.Automation.ModularApplicationCreator.Tia.Openness; |
| 1 | +using Siemens.Automation.ModularApplicationCreator.Tia.Openness; |
| 2 | +using Siemens.Automation.ModularApplicationCreator.Tia.Openness.SoftwareUnit; |
2 | 3 |
|
| 4 | +namespace MAC_use_cases.Model.UseCases; |
3 | 5 |
|
4 |
| -namespace MAC_use_cases.Model.UseCases |
| 6 | +/// <summary> |
| 7 | +/// All the functions to configure and generate Tags and Tag Tables are defined here. |
| 8 | +/// </summary> |
| 9 | +public class CreateVariables |
5 | 10 | {
|
6 | 11 | /// <summary>
|
7 |
| - /// All the functions to configure and generate Tags and Tag Tables are defined here. |
| 12 | + /// Creates a new tag table or retrieves an existing one in the specified PLC device. |
| 13 | + /// \image html CreateTagTable.png |
8 | 14 | /// </summary>
|
9 |
| - public class CreateVariables |
| 15 | + /// <param name="plcDevice">The PLC device where the tag table should be created or retrieved</param> |
| 16 | + /// <param name="tableName">The name for the tag table</param> |
| 17 | + /// <returns>A ControllerTags object representing the new or existing tag table</returns> |
| 18 | + /// <remarks> |
| 19 | + /// If a tag table with the specified name already exists, it will be returned instead of creating a new one. |
| 20 | + /// The returned tag table can be used to add, modify, or remove tags. |
| 21 | + /// </remarks> |
| 22 | + /// <example> |
| 23 | + /// <code> |
| 24 | + /// var tagTable = CreateTagTable(myPlcDevice, "ProcessTags"); |
| 25 | + /// </code> |
| 26 | + /// </example> |
| 27 | + public static ControllerTags CreateTagTable(PlcDevice plcDevice, string tableName) |
10 | 28 | {
|
11 |
| - /// <summary> |
12 |
| - /// This Function creates a Tag Table |
13 |
| - /// \image html CreateTagTable.png |
14 |
| - /// </summary> |
15 |
| - /// <param name="plcDevice">The PLC on which the equipment module is implemented</param> |
16 |
| - /// <param name="tableName">The Name of the tag table</param> |
17 |
| - /// <returns>newTable -> the created tag table (empty)</returns> |
18 |
| - /// |
19 |
| - |
20 |
| - public static ControllerTags CreateTagTable(PlcDevice plcDevice, string tableName) |
21 |
| - { |
22 |
| - var newTable = plcDevice.Tags.GetOrCreateGlobalTagTable(tableName); |
23 |
| - |
24 |
| - return newTable; |
25 |
| - } |
26 |
| - |
27 |
| - |
28 |
| - /// <summary> |
29 |
| - /// This Function creates a Tag in a Tag Table |
30 |
| - /// \image html CreateTag.png |
31 |
| - /// </summary> |
32 |
| - /// <param name="tagTable">An existing tag table in which you want to create a tag</param> |
33 |
| - /// <param name="addressType">Type of the address. (Input, Output)</param> |
34 |
| - /// <param name="addressByte">The Byte of the address</param> |
35 |
| - /// <param name="addressBit">The Bit of the address</param> |
36 |
| - /// <param name="tagName">Name of the tag</param> |
37 |
| - /// <param name="dataType">Date type of the tag</param> |
38 |
| - /// <param name="tagComment">Comment of the tag</param> |
39 |
| - public static void CreateTagInTagTable(ControllerTags tagTable, string addressType, string addressByte, string addressBit, string tagName, string dataType, string tagComment) |
40 |
| - { |
41 |
| - string tagAddress = addressType + addressByte.ToString() + "." + addressBit.ToString(); |
42 |
| - |
43 |
| - var tag = tagTable[tagName]; |
44 |
| - |
45 |
| - if (tag != null) |
46 |
| - { |
47 |
| - tag.Delete(); |
48 |
| - } |
49 |
| - |
50 |
| - tag = tagTable.AddTag(tagName, dataType, tagAddress); |
51 |
| - tag.SetComment("en-EN", tagComment); |
52 |
| - } |
| 29 | + return plcDevice.Tags.GetOrCreateGlobalTagTable(tableName); |
| 30 | + } |
| 31 | + |
| 32 | + /// <summary> |
| 33 | + /// Creates a new tag table or retrieves an existing one in the specified software unit. |
| 34 | + /// </summary> |
| 35 | + /// <param name="softwareUnit">The software unit where the tag table should be created or retrieved</param> |
| 36 | + /// <param name="tableName">The name for the tag table</param> |
| 37 | + /// <returns>A ControllerTags object representing the new or existing tag table</returns> |
| 38 | + /// <remarks> |
| 39 | + /// This overload creates/retrieves a tag table within a specific software unit rather than at the PLC device level. |
| 40 | + /// If a tag table with the specified name already exists in the software unit, it will be returned instead of creating |
| 41 | + /// a new one. |
| 42 | + /// </remarks> |
| 43 | + /// <example> |
| 44 | + /// <code> |
| 45 | + /// var tagTable = CreateTagTable(mySoftwareUnit, "ModuleSpecificTags"); |
| 46 | + /// </code> |
| 47 | + /// </example> |
| 48 | + public static ControllerTags CreateTagTable(ISoftwareUnitBase softwareUnit, string tableName) |
| 49 | + { |
| 50 | + return softwareUnit.Tags.GetOrCreateGlobalTagTable(tableName); |
| 51 | + } |
| 52 | + |
| 53 | + |
| 54 | + /// <summary> |
| 55 | + /// This Function creates a Tag in a Tag Table |
| 56 | + /// \image html CreateTag.png |
| 57 | + /// </summary> |
| 58 | + /// <param name="tagTable">An existing tag table in which you want to create a tag</param> |
| 59 | + /// <param name="addressType">Type of the address. (Input, Output)</param> |
| 60 | + /// <param name="addressByte">The Byte of the address</param> |
| 61 | + /// <param name="addressBit">The Bit of the address</param> |
| 62 | + /// <param name="tagName">Name of the tag</param> |
| 63 | + /// <param name="dataType">Date type of the tag</param> |
| 64 | + /// <param name="tagComment">Comment of the tag</param> |
| 65 | + public static void CreateTagInTagTable(ControllerTags tagTable, string addressType, string addressByte, |
| 66 | + string addressBit, string tagName, string dataType, string tagComment) |
| 67 | + { |
| 68 | + var tagAddress = addressType + addressByte + "." + addressBit; |
| 69 | + |
| 70 | + var tag = tagTable[tagName]; |
| 71 | + |
| 72 | + tag?.Delete(); |
53 | 73 |
|
| 74 | + tag = tagTable.AddTag(tagName, dataType, tagAddress); |
| 75 | + tag.SetComment("en-EN", tagComment); |
54 | 76 | }
|
55 | 77 | }
|
0 commit comments