Accessing PLC tags - TIAPortal

TIA Portal Openness: API for automation of engineering workflows

ft:publication_title
TIA Portal Openness: API for automation of engineering workflows
Product
TIAPortal
Version
V21
Publication date
03/2026
Language
en-US
Accessing PLC tags

Requirement

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.

Copies the following program code to clipboard.

//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:

Copies the following program code to clipboard.

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:

Copies the following program code to clipboard.

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:

Copies the following program code to clipboard.

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();

    }

}