Today we will look at a tool that is widely used in software development, but is very difficult to apply in industry as we usually work with binary files.
The definition of Git is as follows:
Git is a distributed version control system that records changes made to
files over time. It allows multiple people to collaborate on software projects
efficiently by tracking changes, merging the work of different people, and reverting to previous
versions if necessary.
It will help us with:
- Software version control.
- Comparison of blocks with previous versions.
- Restoration of blocks with previous versions.
Although this can currently be achieved in more rudimentary ways, you will soon see the
potential of recording our changes in Workstation and GIT.
Required software:
- TIA Portal (version 16 or higher)
- Git (latest version recommended)
- TIA Portal Add-in *An add-in is a computer program that adds functions or additional features to an existing program
To carry out version control, we will use a tool integrated into TIA Portal called WorkStation, which essentially exports all our blocks (FCs, FBs, DBs, data structures, and variable tables) in XML format or some other type of plain text file. *This can be configured from the TIA Portal settings.
Setting Up Our Workstation in TIA Portal
- First of all, we need to create a folder where we will store our programming and the necessary GIT files.
- We open a project in TIA Portal.
- At the bottom, we expand a section called VCI “Version Control Interface”.
- We add a new Workstation and open it (When opened, we will see the PLCs we have and their offline programming).
- Here we configure our Workstation as shown in the following image. We need to add the path of the folder we created in step "1".
- We will have our Workstation ready to use; now we just need to start adding the blocks we want to save.
- This is done by dragging and dropping from the right side to the left. (I usually drag the entire PLC). Keep in mind:
- Blocks containing special characters will not be exported.
- We must be offline with all devices.
- We must have unlocked the PLC to work with safety blocks.
Configuring GIT to Track Changes
- We need to open PowerShell on the computer where we have git installed.
- First of all, we will need to configure our git, for that we will need a username and an email.
- We configure our email with the command:
git config --global user.email “you@example.com”. - We configure our name with the command:
git config --global user.name "Your Name".
- We configure our email with the command:
git init “path to our folder”. After executing the command, check that no errors occurred and/or verify that a folder named .git has been generated in our path.
- If we had no errors, the next step will be to access our directory via console commands, for that we enter the following command -> cd “path to our folder”.
- After that, we will execute the command to add our exported files from TIA Portal to tracking:
git add -A.
- Finally, we make a commit; this is what we will normally do to save
our changes in git, this saves a point in the history of
changes of our files, which we will use later to compare and/or
recover our old programming. - To execute the commit, we use the following command:
git commit -m “Descriptive message of the changes made”.
- Now we will have our tracking declared and the first commit made; we could perform step “g” from the console every time we export our changes, but we will go further.
Integrating Git into TIA Portal
- We need to download the software from the official Siemens page.
- We extract the zip file we downloaded and copy the file that ends in .addin to the following path -> “C:\Program Files\Siemens\Automation\Portal V16\AddIns\”.
- To have it available in TIA Portal, we go to the right side in add-ons and we will need to activate the Add-in.
- Finally, we go to our WorkSpace and in the WorkSpace configuration, we add the add-in.
- Now every time we export changes in our project, it will automatically make a commit from TIA Portal without having to do it via PowerShell.
With this, we have finished configuring our environment to have version control over a project.
In another post, we will see how to make commits, how to restore commits, and how to make use of
tools to get the most out of git in TIA Portal.