Part 2 - Basics and installation

Video

#PLC #TwinCAT3 #Beckhoff #IEC_61131-3

🔙 Previous Part | Next Part 🔜

↩️ Go Back

Table of Contents:


A) A bit of history of Industrial Automation

Industrial automation has been around long before PLCs were invented. Before PLCs, it was possible to automate a process using relay based control systems.

|350

This approach however required huge amounts of relays, cabling and space and it was difficult to maintain for these reasons. A small change in the system would require rewiring, and a single wire breakage could mean that the whole system would not work.

In the 1960s the first ideas for a replacement of these hard-wired relay systems arose. During the 1960's, independently of each other the companies Allen-Bradley and General Motors investigated the electronic replacement of the hard-wired relay systems and both created the first PLCs.

|320

The first PLC was the Modicon Model 084 and this was delivered in 1969.
This PLC consisted of:

The Modicon 084 was not a success for various reasons such as it being slow and lacked some useful features.
|400

In 1973, the Modicon 184 was released, which is recognized as being the first mass-market PLC to achieve success.

|250

Now, let's fast forward a few decades to the theme for this tutorial, TwinCAT.


B) The Dawn of TwinCAT

TwinCAT stands for "The Windows Control and Automation Technology"
|330

Beckhoff, the company behind TwinCAT, was founded in 1980 in Verl, Germany and have been active in the field of automation since the start.

One of Beckhoff's main business ideas is PC-based control. Starting in the 80s Beckhoff started with PC-based control, running on a standard PC in DOS.

|400

This was a big shift in the PLC market, as the other manufacturers much more relied on proprietary hardware and software.


B.1) TwinCAT2

In 1996 Beckhoff released TwinCAT 2, in where it was possible to turn a standard PC-based computer running Windows into a real-time capable controller.

|200

This is accomplished by having the TwinCAT kernel having direct access to the hardware for all real-time critical tasks and using Windows for all user-space applications.

Beckhoff did as most PLC developers do even until this day by creating their own integrated development environment (IDE) in where you could do your PLC software coding.

|400

Next to the IDE there was a system manager installed, in which all the configuration of the PLC was done.

|400


B.2) TwinCAT3

In 2012 TwinCAT 3 was released to the public.

|200

With TwinCAT 3 Beckhoff integrated both the development environment (IDE) and the functionality of the system manager into Microsoft Visual Studio (VS)
|300

Now everything related to:

could be done from this single IDE.
Visual Studio is a modern and very popular development environment.

Until 2020 both the development environment and runtime was running in Windows.
|300
Nowadays there is a TwinCAT runtime for both Windows and for Beckhoffs FreeBSD-derivate called Tc/BSD
|300

Note: All PLC-software development is however still made in a Windows environment.

By using a modern and popular IDE as VS, it was also easier for people that were already acquainted with IT-software development to start with PLC software development.

|300

To be able to do PLC software in visual studio, Beckhoff relies on a compiler made by CODESYS (which is a German manufacturer of IEC61131-3 automation software).

|180

CODESYS development tools are not only used by Beckhoff but by a big variety of PLC manufacturers.

|450

Note: CODESYS even provide a runtime for the Raspberry Pi

Beckhoff are using the CODESYS compiler and parts of the development tools made by CODESYS and then integrates them into VS. Fact is, if you download the CODESYS "vanilla" development environment, you will find many similarities between it and TwinCAT 3. If you've worked with CODESYS prior to TwinCAT3, you will have plenty of moments where you'll recognize yourself.

|650


C) The two main parts of TwinCAT3 (XAE & XAR)

TwinCAT 3 consists of two main parts:

How are these two parts related?


C.1) the eXtended Automation Engineering (XAE)

|300

First we have the XAE, this is the development environment for TwinCAT 3 software.

It includes amongst many other things the IDE based on Visual Studio.

|650

It also includes libraries for various functionality and the (IEC61131-3) compiler itself.

It's with the XAE that you:

The XAE is always installed on a windows machine (so you can't run this on any other operating system such as Linux).
|200


C.2) the eXtended Automation Runtime (XAR)

|300

In the XAR we find amongst many other things the TwinCAT realtime kernel, which provides the deterministic properties of our PLC software.

We also find drivers for the industrial fieldbus protocols, such as EtherCAT.

|550

|550

The XAR can be installed both on a Windows machine and Beckhoffs own operating system Tc/BSD.
|230


C.3) ADS Communication Protocol

The XAE and XAR communicate with each other using a protocol called ADS.
|600

With ADS protocol you can:

Beckhoff provides this interface between XAE and XAR.


C.4) Fieldbus interfaces (sensors & actuators)

|700

Through fieldbus interfaces TwinCAT can communicate with various sensors such as:

MORE INFO ABOUT SENSORS

And actuate actuators such as:

MORE INFO ABOUT ACTUATORS


C.5) The Compiler

When you have successfully compiled a TwinCAT 3 project on your XAE development machine, it will create an executable binary.
|700

Through the IDE we can transfer this program to the XAR and execute it so that it's running in the real-time environment of TwinCAT 3.
|700


C.6) Develop and Run your Software

To complicate things slightly, a download of the XAE also includes the XAR. Which means that if you install the XAE you will be able to run your TwinCAT software locally on your development machine, so you don't need a separate PLC to try your software.

|180

This is one of the key points of TwinCAT 3.The Beckhoff PLCs are just ordinary PCs with some optimized BIOS-settings for real-time behavior. And the hardware is also industrialized so you can (for example) connect a 24V power supply to it.

|500

The possibility to run all your TwinCAT software during the development phase on your local computer is just such a great advantage. You don’t need to buy any special hardware to test your TwinCAT software.

Fact is, we’re going to even go one step further in this tutorial and do most of the development on a virtual machine using VirtualBox. For this tutorial we don't care about low jitter and proper realtime behaviour, as we are not going to run our code in a production environment.

|160

Another great advantage with TwinCAT 3 compared with most other PLC runtimes is that you can develop and run your software without any cost. Every seven days you only need to enter a CAPTCHA, and then you can run your TwinCAT software without interruptions during this time.


D) XAE & Visual Studio (IDE)

When you download the TwinCAT 3 XAE, you'll get the TwinCAT XAE Shell development environment, which is based on Visual Studio.

|280

It's basically a version of Visual Studio where the possibility for all other languages such as C#/C++ have been removed, but all the other functionality of Visual Studio is left intact.

This functionality is for example:

All of that is still left intact. If your only intention is to do TwinCAT software development, the TcXaeShell works perfectly fine.

If you happen to have any Visual Studio already installed on your computer, the TwinCAT XAE installer will give you the possibility to integrate TwinCAT into them. Beckhoff continously adds support for newer versions of Visual Studio when releasing new versions of TwinCAT.

|200

Here is an example screenshot of how it can look like when we are installing the TwinCAT 3 XAE into a computer that already has a couple of versions of Visual Studio installed:
|350

And also we can see that the installer allows us to integrate TwinCAT into these versions of Visual Studio.


E) TwinCAT installation

Now it's time to download the TwinCAT XAE, and for this tutorial I will be using VirtualBox to use a virtual machine for our TwinCAT development.

|650

Note: You don't need to do this, you don't have to use VirtualBox, you don't have to use a virtual machine at all. You can install the development environment directly on your computer. But again, VirtualBox is for free so you can just download it and the advantage of this is that we can create a completely isolated environment for all our TwinCAT software.

And I've created a VM here that has 8GB of RAM
|430

and 4 cores (recommended settings).
|430

And first you have to download the actual software from www.beckhoff.com
Then you go to "Download Finder",

|650

then you go down to "Software and tools"

|650

Then as the first download here you have the XAE.
Then you go to "Downloads"

|650

At this moment in time, the latest version of the XAE is 3.1.4024.12. This is the version we are going to use for the complete tutorial.

Press "Start download"
|650

You need to have an account at Beckhoff, it's completely free.
|650

And you can download it from this link:
|650

This includes the runtime and everything we actually need to run the software.
We are going to run all the software directly on the virtual machine.

|350

Extract and start the installation.
|650

"Do you want to allow this app to make changes to your device?" Select YES
|300

And the installer is starting...
|270

Go through the Installer
|350

Accept 3rd Party Software to use the Git functionality
|350

Select the Complete installation
|350

And install TwinCAT XAE Shell
|350

Note.

This VM also has four installations of Visual Studio. We have Visual Studio 2013, 2015, 2017 and 2019 installed. All of these are the community versions of Visual Studio.

You don't need to download any Visual Studio for this, you can just use the Visual Studio that is included with TwinCAT. And that is what we are going to use for the rest of the tutorial. We will use the TcXaeShell.

The only reason I've installed these is to just show you that they come up as alternatives for TwinCAT to integrate into. If you don't have any Visual Studio installed already, TwinCAT will install TwinCAT XAE shell as a default.

Finish installing XAE, XAR and other packages and drivers in your computer.
|350

Press Finish and restart your machine
|350


F) Using TwinCAT (Routes & Modes)

Once the machine is rebooted, you will have a new icon in the taskbar.
|250

And here we can see that we can open all the different versions of Visual Studio and the development environment TwinCAT XAE.
|260

From this icon |30 you can do various tasks, which include (but is not limited to):


F.1) TwinCAT ADS/AMS Routes

The routes are used to communicate with other devices running TwinCAT, such as a target PLC that will run the software that you will develop

|300

As we will be running all PLC code locally in our runtime that we have on our development machine, we won't be creating any routes as the development machine always has a default route to the localhost.
|200


F.2) TwinCAT Modes

TwinCAT can be in three different modes, which are indicated by different colors of the TwinCAT icon in the task bar (this dictates what state the TwinCAT runtime (XAR) is at):

  1. CONFIG mode
    Which is indicated by a blue color
    |200
    You want to be in CONFIG mode every time you do any changes to the system which might affect the PLC software that is being executed. This might be for example that you want to do changes in the PLC software, adding supplements (such as a database connectivity) or upgrading TwinCAT.

  2. RUN mode
    Which is indicated by a green color.
    |200
    When you want to run the actual TwinCAT PLC software, the XAR should be in run-mode. In this mode TwinCAT will run all your tasks and programs.

  3. STOP/EXCEPTION mode
    Which is indicated by a yellow color
    |200
    You normally never want to be in the stop/exception mode, which you can end up in if you for example get an exception, such as a null pointer exception or a stack overflow

Because an XAR is included with the XAE, it means that you control the TwinCAT state on your local machine through this.

Switching TwinCAT between CONFIG and RUN-mode is done by right-clicking on the taskbar and selecting

"System" → "Start/Restart" or "Config"

This can also be accomplished through the development environment, which we will do in the next part.

Now we have our development environment configured. :)

In the next video we will configure our machine so that it can run TwinCAT 3 programs, and then we will create our very first program.


🔙 Previous Part | Next Part 🔜

↩️ Go Back


Z) Glossary


File Definition