Cookies are important for this site to function properly, to guarantee your safety, and to provide you with the best experience. By clicking OK, you accept all cookies. For more information, please access our Privacy Policy.
Table of Contents
Tutorials / 
Working with Libraries in Siemens TIA Portal - PLC Programming
Intermediate

Working with Libraries in Siemens TIA Portal - PLC Programming

PLC Programming
Siemens
TIA Portal

Introduction

In the complex realm of industrial automation, where efficiency and reliability are paramount, engineers often struggle with managing repetitive tasks, optimizing code reuse, and maintaining consistency across multiple projects. Libraries systematically organize, store, and share reusable program blocks and functions, streamlining the development process and promoting best practices.

In the context of Siemens TIA Portal, libraries are powerful tools that allow engineers to create, manage, and share code and other program elements across various projects. These libraries come in two main categories: project libraries and global libraries. Project libraries reside within individual projects, storing blocks that are used frequently or for versioning purposes. On the other hand, global libraries act as centralized repositories for a diverse array of program blocks, tag tables, complete stations, and more.

This tutorial teaches you how to create and manage libraries inside a TIA Portal project. We will first take a look at the basics of how libraries work. Then, we will shift the focus to the type of library elements (Types and master copies). Finally, we will see how to share elements from one project to another by creating a global library and then opening it in a different project. 

Prerequisites

To follow this tutorial, you will need an installation of TIA Portal. We will use the latest versions to date (v18), but you can use any other version. No additional hardware or software is required.

Basics of libraries in TIA Portal

Let’s start by creating a new project in TIA Portal. Once done, we must add a CPU. Click on “Add new device.”

Figure 1.1 - Siemens TIA Portal Libraries | Creating a new TIA Portal project
Figure 1.1 - Siemens TIA Portal Libraries | Creating a new TIA Portal project

We can select any 1200 or 1500 CPU. Select the CPU of your choice. Here, we will be using a 1511-1 CPU.

Figure 1.2 - Siemens TIA Portal Libraries | Selecting a 1511 CPU
Figure 1.2 - Siemens TIA Portal Libraries | Selecting a 1511 CPU

We now have a 1500 station. Libraries can be accessed anytime by opening the “Libraries” tab on the left side of TIA Portal. 

Figure 1.3 - Siemens TIA Portal Libraries | The station is added to the project
Figure 1.3 - Siemens TIA Portal Libraries | The station is added to the project

The libraries section is composed of two parts

  1. Project library: It is a library included in all TIA Projects which is used for storing blocks that are used multiple times or for block versioning (types).
  2. Global library: Global libraries in TIA Portal are centralized repositories of reusable program blocks and functions. It allows you to pack different types of software elements (blocks, tag tables, complete stations….etc) as files and share them between different projects.
Figure 1.4 - Siemens TIA Portal Libraries | Accessing the libraries section
Figure 1.4 - Siemens TIA Portal Libraries | Accessing the libraries section

Let’s create a new global library for later use during the tutorial. Click on the “New library” button.

Once done, a small window opens where you can define the library’s name, path, author, and comment. You can give a name to the library and finish by clicking on “Create.”

Figure 1.5 - Siemens TIA Portal Libraries | Setting the new library
Figure 1.5 - Siemens TIA Portal Libraries | Setting the new library

The new library appears in the global library section. Inside it, you can find all the components of a library. The two most relevant ones are the types and master copies folders. 

  • Types: Can contain only program blocs (OBs, FCs, and FBs). It allows you to version control your blocks. 
  • Master copies: Can contain any TIA Portal element such as program blocks, DBs, technology objects, tag tables, HMIs, PLC stations….etc.
Figure 1.6 - Siemens TIA Portal Libraries | The global library is created
Figure 1.6 - Siemens TIA Portal Libraries | The global library is created

You can find this library by browsing your files on the path specified in the library’s creation. Here, we created the library in the C local disk’s root. It will contain a folder with the same name as the library. By opening it, you will find all the files and folders of the library. 

Figure 1.7 - Siemens TIA Portal Libraries | Global library folder
Figure 1.7 - Siemens TIA Portal Libraries | Global library folder

Libraries -  Types

We have covered the basics of the libraries in TIA Portal. We will now approach the “types” elements. As mentioned, types are used to create multiple versions of your program blocks. This section will create a Function Block used to control a pump as an example. We will create a type of this block that will allow us to release new versions of this block each time we modify it. Let’s start by creating a new FB. Click on “Add new block” in the project tree.

Figure 2.1 - Siemens TIA Portal Libraries | Adding a new block
Figure 2.1 - Siemens TIA Portal Libraries | Adding a new block

In the next window, select “Function block” and give a name to the block.

Figure 2.2 - Siemens TIA Portal Libraries | Selecting Function block
Figure 2.2 - Siemens TIA Portal Libraries | Selecting Function block

The newly created FB appears in the project tree under the program blocks folder. We will now program a small program to start/stop the pump.

Figure 2.3 - Siemens TIA Portal Libraries | FB programming interface
Figure 2.3 - Siemens TIA Portal Libraries | FB programming interface

Now we need to form the program by adding the elements to the workspace. Reproduce the diagram shown in the following figure.

Figure 2.4 - Siemens TIA Portal Libraries | Program diagram
Figure 2.4 - Siemens TIA Portal Libraries | Program diagram

Next, we need to add inputs and outputs to the FB. Create two boolean inputs (Start and Stop) and one boolean output (Motor).

Figure 2.5 - Siemens TIA Portal Libraries | Creating I/Os
Figure 2.5 - Siemens TIA Portal Libraries | Creating I/Os

Then, add the inputs/outputs we created to the program by dragging and dropping them. Be sure to add them to the correct element in the program as shown below.

Figure 2.6 - Siemens TIA Portal Libraries | Adding the I/Os to the program
Figure 2.6 - Siemens TIA Portal Libraries | Adding the I/Os to the program

The program is now done, we can create a type of it. Open the libraries tab. After that, select the FB in the project tree, drag it to the types section of the project library, and then drop it.

Please note that types can only be created in the project library. You cannot create types directly in the global libraries.

Figure 2.7 - Siemens TIA Portal Libraries | Adding the FB to the types section of the project library
Figure 2.7 - Siemens TIA Portal Libraries | Adding the FB to the types section of the project library

A small window will open where you configure the name, version, author, and comment of the type. Since it is the first version, we will keep the 0.0.1 code. Once the configuration is done, click on “OK.”

Figure 2.8 - Siemens TIA Portal Libraries | First release settings
Figure 2.8 - Siemens TIA Portal Libraries | First release settings

The newly created type should appear in the project library’s types section. The only version available is the 0.0.1 version. Also, you can notice a warning message in FB’s programming interface telling you that types are writing protected. As it is now, you cannot edit versions that have been created. To allow edition, the only choice is to add new version releases.

Figure 2.9 - Siemens TIA Portal Libraries | The first type is created
Figure 2.9 - Siemens TIA Portal Libraries | The first type is created

Let’s make some modifications and release a new version. First, we need to access the edition mode. For this, you can either click “edit the type” in the warning message or right-click the version and select “Edit type.”

Figure 2.10 - Siemens TIA Portal Libraries | Editing the type
Figure 2.10 - Siemens TIA Portal Libraries | Editing the type

We are now in edition mode. You can notice that the warning message changed and a new version (0.0.2) has been created with an “In test” tag. We cannot modify an existing type; we have to create a new version each time we want to modify something.

Figure 2.11 - Siemens TIA Portal Libraries | In-test version
Figure 2.11 - Siemens TIA Portal Libraries | In-test version

Now we will modify the program. Let’s add security that prevents the pump from turning on for a minute after it has been stopped. First, add a boolean in the “Temp” section of the block’s interface and name it “Security”.

Figure 2.12 - Siemens TIA Portal Libraries | Adding a security temp boolean
Figure 2.12 - Siemens TIA Portal Libraries | Adding a security temp boolean

Next, add a second network in the program and reproduce the diagram in the following figure. Don’t forget to call the timer DB in multi-instance mode.

Figure 2.13 - Siemens TIA Portal Libraries | Adding modification to the program
Figure 2.13 - Siemens TIA Portal Libraries | Adding modification to the program

Then, add the interface elements to the diagram, as shown below. 

Figure 2.14 - Siemens TIA Portal Libraries | Adding I/Os to the modified program
Figure 2.14 - Siemens TIA Portal Libraries | Adding I/Os to the modified program

The modifications are done, and we can now release the new version. For this, you can either click “release the version” in the warning message or right-click on the in-test version and select “Release version.”

Figure 2.15 - Siemens TIA Portal Libraries | Releasing the new version
Figure 2.15 - Siemens TIA Portal Libraries | Releasing the new version

A small window will open where you can configure the type as we did before. Be sure that the version is set to 0.0.2.

Figure 2.16 - Siemens TIA Portal Libraries | Second release settings
Figure 2.16 - Siemens TIA Portal Libraries | Second release settings

Now, we have a second version released.

Figure 2.17 - Siemens TIA Portal Libraries | The second version is created
Figure 2.17 - Siemens TIA Portal Libraries | The second version is created

Then, to save this version and make them sharable a reusable, we can add them to the global library. To do this, select the type in the project library section and drag it to the type’s section of the global library. Then, drop it.

Figure 2.18 - Siemens TIA Portal Libraries | Adding the type from the project library to the global library
Figure 2.18 - Siemens TIA Portal Libraries | Adding the type from the project library to the global library

Libraries - Master copies

We looked at the types elements, we can shift our focus to the master copies. Master copies are snapshots of the original instances of a particular object, such as a PLC program or an HMI screen. These master copies can be centrally managed and updated inside a project or global library. You can add any type of TIA element as a master copy in a library and reuse it later in other projects as templates. Since program blocks are usually added into libraries as types, we will add other kinds of elements to the library’s master copies. Let’s start by creating and adding a DB to the project. Click on “Add new block” in the project tree.

Figure 3.1 - Siemens TIA Portal Libraries | Adding a new block
Figure 3.1 - Siemens TIA Portal Libraries | Adding a new block

Select “Data block.”

Figure 3.2 - Siemens TIA Portal Libraries | Selecting Data block
Figure 3.2 - Siemens TIA Portal Libraries | Selecting Data block

We can create master copies of the DB in the project/global libraries. Select it in the project tree and drag/drop it to the master copies folders of both the project and global libraries.

Figure 3.3 - Siemens TIA Portal Libraries | Adding the DB to the master copies folders
Figure 3.3 - Siemens TIA Portal Libraries | Adding the DB to the master copies folders

The master copies are created in the project/global libraries.

Figure 3.4 - Siemens TIA Portal Libraries | The DB master copy is created
Figure 3.4 - Siemens TIA Portal Libraries | The DB master copy is created

Program blocks are not the only elements you can add as master copies. You can also add HMI or PLC stations, for example. Let’s add an HMI device. Click on “Add new device” on the project tree.

Figure 3.5 - Siemens TIA Portal Libraries | Adding a new device
Figure 3.5 - Siemens TIA Portal Libraries | Adding a new device

Click on “HMI” and select the HMI device of your choice. Here, we will use a TP900 Comfort panel.

Figure 3.6 - Siemens TIA Portal Libraries | Selecting an HMI panel
Figure 3.6 - Siemens TIA Portal Libraries | Selecting an HMI panel

After that, select the HMI device in the project, drag it to the master copies section of the global library, and drop it. This will create a master copy of the whole HMI configuration.

Figure 3.7 - Siemens TIA Portal Libraries | Adding the HMI device to the master copies
Figure 3.7 - Siemens TIA Portal Libraries | Adding the HMI device to the master copies

You can also do the same for the PLC station. Select it in the project tree and send it to the master copy section of the global library.

Figure 3.8 - Siemens TIA Portal Libraries | Adding the PLC station to the master copies
Figure 3.8 - Siemens TIA Portal Libraries | Adding the PLC station to the master copies

Opening a global library in a new project

The main purpose of global libraries is to allow engineers to keep templates of program elements and share them between different projects. Previously, we created a global library and added types and master copies to it. We will now create a new TIA Portal project and open this library in it to retrieve the work we did before. Create a new TIA Portal project. Then, click on the “Open global library” button in the libraries section.

Figure 4.1 - Siemens TIA Portal Libraries | Creating a new TIA Portal project and opening the global library
Figure 4.1 - Siemens TIA Portal Libraries | Creating a new TIA Portal project and opening the global library

Go to the folder where you created the global library and select the .a18 files and click on “Open.”

Figure 4.2 - Siemens TIA Portal Libraries | Selecting the library file
Figure 4.2 - Siemens TIA Portal Libraries | Selecting the library file

The library opens in the global library section. You will find the FB type with its two versions in the type folder and the master copies we created just before. 

Figure 4.3 - Siemens TIA Portal Libraries | The global library is added to the new project
Figure 4.3 - Siemens TIA Portal Libraries | The global library is added to the new project

You can now select the elements you want to add from the global library to your new project by dragging/dropping them into the project tree. 

Figure 4.4 - Siemens TIA Portal Libraries | Adding master copies elements to the project
Figure 4.4 - Siemens TIA Portal Libraries | Adding master copies elements to the project

Conclusion

In this tutorial, you learned how to operate libraries inside TIA Portal projects. We first got a general view of the libraries' basics in TIA Portal. Then, we created a FB and released two versions of it using types. After that, we took a look at how to create master copies of different types of software elements in TIA Portal. And we concluded by sharing these elements between two projects using the global library.

Embracing libraries within industrial automation development can yield significant benefits. By incorporating these practices, engineers can seamlessly construct projects using reusable modules, ensuring a consistent approach and streamlined design process. The ability to iterate on designs while preserving established systems is a hallmark of library integration. Furthermore, the centralized resource management facilitated by global libraries paves the way for enhanced collaboration, encouraging the standardization of best practices and engendering robustness across a spectrum of automation projects.