Requirement
-
The TIA Portal Openness application is connected to the TIA Portal.
See Connecting to the TIA Portal -
A project is open.
See Opening a project
Application
The type PlcTagComposition represents a collection of plc tags.
Program code: Accessing a specific PLC tag
Modify the following program code to access the required PLC tag. You have access to the following attributes:
|
Attribute name |
Data type |
Access |
|---|---|---|
|
DataTypeName |
string |
Read and Write |
|
ExternalAccessible |
bool |
Read and Write |
|
ExternalVisible |
bool |
Read and Write |
|
ExternalWritable |
bool |
Read and Write |
|
LogicalAddress |
string |
Read and Write |
|
Name1 |
string |
Read and Write |
|
IsSafety |
bool |
Read and Write |
|
Note In TIA Portal Openness version 20 and above, the Name attribute has write access. In versions earlier than 20, the Name attribute does not have write access. |
|
//Gives individual access to a specific plc tag private static void AccessPlcTag(PlcTagTable tagTable) { PlcTag tag = tagTable.Tags.Find("Tag XYZ"); // The parameter specifies the name of the tag } |
Program code: Creating tags
Modify the following program code:
|
private static void CreateTagInPLCTagtable(PlcSoftware plcsoftware) // Create a tag in a tag table with default attributes { string tagName = "MyTag"; PlcTagTable table = plcsoftware.TagTableGroup.TagTables.Find("myTagTable"); PlcTagComposition tagComposition = table.Tags; PlcTag tag = tagComposition.Create(tagName); } |
Modify the following program code:
|
private static void CreateTagInPLCTagtable(PlcSoftware plcsoftware) // Create a tag of data type bool and logical address not set { string tagName = "MyTag"; string dataType = "Bool"; string logicalAddress =""; PlcTagTable table = plcsoftware.TagTableGroup.TagTables.Find("myTagTable"); PlcTagComposition tagComposition = table.Tags; PlcTag tag = tagComposition.Create(tagName, dataType, logicalAddress); } |
Program code: Deleting tags
Modify the following program code:
|
private static void DeleteTagFromPLCTagtable(PlcSoftware plcsoftware) // Deletes a single tag of a tag table { string tagName = "MyTag"; PlcTagTable table = plcsoftware.TagTableGroup.TagTables.Find("myTagTable"); PlcTagComposition tagComposition = table.Tags; PlcTag tag = tagComposition.Find(tagName); if (tag != null) { tag.Delete(); } } |