Working with Libraries in Siemens TIA Portal - PLC Programming
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.”
We can select any 1200 or 1500 CPU. Select the CPU of your choice. Here, we will be using a 1511-1 CPU.
We now have a 1500 station. Libraries can be accessed anytime by opening the “Libraries” tab on the left side of TIA Portal.
The libraries section is composed of two parts
- 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).
- 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.
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.”
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.
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.
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.
In the next window, select “Function block” and give a name to the 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.
Now we need to form the program by adding the elements to the workspace. Reproduce the diagram shown in the following figure.
Next, we need to add inputs and outputs to the FB. Create two boolean inputs (Start and Stop) and one boolean output (Motor).
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.
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.
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.”
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.
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.”
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.
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”.
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.
Then, add the interface elements to the diagram, as shown below.
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.”
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.
Now, we have a second version released.
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.
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.
Select “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.
The master copies are created in the project/global libraries.
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.
Click on “HMI” and select the HMI device of your choice. Here, we will use a TP900 Comfort 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.
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.
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.
Go to the folder where you created the global library and select the .a18 files and click on “Open.”
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.
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.
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.