TwinCAT 3 course

When I started out with TwinCAT programming some time ago, I had basically not heard about PLCs. My background was not even close to automation, mostly doing C/C++ on various Linux-based systems. I had two friends which previously were doing a little automation, and both of them said “Don’t start working with PLCs. It’s boring“. Now that I’ve dabbled in “traditional IT” software development and industrial automation software development, I definitely don’t agree with the latter being boring. Industrial automation using PC-based control is insanely fun! At my first job where they used “this thing called TwinCAT” (which was unknown to me at that time), I did what I usually do: I started googling stuff like “free TwinCAT tutorial, how to program with TwinCAT, free TwinCAT course, TwinCAT open source” and so forth. I didn’t find much on Google or in any other of the places I usually used to learn a new programming language (forums, stack overflow, open source projects, etc). The amount of free resources was very limited. After having my TwinCAT blog for a few years, I even got an (anonymous) message via the contact form on my blog from someone saying that I’m an idiot that shares information and knowledge for free, and that nothing should be done for free and that I should basically stop writing my blog. For these reasons, I decided to do a free TwinCAT 3 course.

When I started out and was trying to look for resources to get me a kick-start, I quickly found out that the learning material ecosystem for PLCs/automation mostly had these limitations:

  • you have to register on a website to get access to the courseor
  • the courses are available only in a specific country/region or
  • the courses are costly

Or a combination of all above. This means that the learning curve will be slightly steeper for learning TwinCAT. If I want to learn Python, C++, C#/.NET, windows batch-scripting ( 🙂 ) or any “conventional IT” programming language, there are tons of free information on the Internet available. If I want to learn a new programming language, I’d like to be able to start quickly (kudos to Beckhoff for having a cost-free development environment and runtime making this possible) and just start to hack. When creating the content of this course, the ambition was that it should be the course that I wish I had when I started with TwinCAT 3 development. It’s available on YouTube, so no registration, no region limitations, and zero cost. All you need is a computer with the TwinCAT 3 development environment and runtime (free from Beckhoff, although unfortunately you have to register at their website to download it), then you can start to watch, listen & learn.

This course has taken me 720 (!) hours of my spare-time to create, and if you find ut useful, please consider making a donation. Know anyone that wants to learn PLC programming? Please share the course among your friends!

The course consists of a total of 18 parts, covering various aspects of TwinCAT 3. The 18 parts are divided into two main groups, basic and advanced.

Each part has English and German subtitles, which are enabled by clicking the following icon on a PC/Mac:

or this icon on Android/iPhone/Mobile:

If you like the course, please consider supporting making a donation or by becoming a Patron.

Content of the course

Basic group

Part 1 – Introduction

The first part will be an introduction to why this course was created, the scope and an overview of the content of this course.

 

Part 2 – Basics & installation

Here I will give some background information to PLCs and TwinCAT 3, and describe the difference between the development environment and the runtime. We will also download and install the TwinCAT 3 development environment (XAE) so that we have everything up and set for our first program.

 

Part 3 – Tasks, programs & “Hello world”

In this part we will go through some basics regarding why a standard operating system is not suitable for many of the industrial automation tasks, and why you need something like TwinCAT for certain applications. We will look into how TwinCAT is co-existing next to the operating system and how they co-operate. Next, we will create our first TwinCAT 3 solution and learn how to configure the real-time properties of our project. In order to run any TwinCAT software, we will also need to enable virtualization in the BIOS of the computer, which will be shown. We will briefly look at how licensing works in TwinCAT 3, and after that we will create the classical “Hello world” program, although it will probably be different compared to the conventional programming languages you might have worked with previously.

 

Part 4 – Data types & arrays

In this video we will look into the various data types that are available in the IEC 61131-3 standard, pointers & references and how to work with arrays. We will cover why pointers can be dangerous and why you generally want to prefer to use references instead. Then we will finish the course by looking at how we can convert between different data types.

 

Part 5 – Structures & functions

Arrays allow us to define types of variables that can hold several data items of the same kind. In this part of the course we will look at a data unit type that allows us to hold several data items of different kind. We will also look at one of the basis of modularization and re-use in software development called functions. We will look at how we can get data in and out of functions, and we will also look at the difference between passing parameters by value and by reference. We will finish this part by writing our very first function!

 

Part 6a – Function blocks & interfaces

In this part we will start to look into the object oriented programming parts of structured text and IEC 61131-3 called function blocks. For those that are Java, C, C++ or just “traditional” programmers, going into the realm of function blocks is like going from C-style structures and functions, and into classes in C++. With function blocks we can go from working in a procedural style programming into objected oriented style programming.

 

Part 6b – Function blocks & interfaces

In this part we will continue our journey of the object oriented features of IEC 61131-3 and look into something called interfaces. Interfaces provide a layer of abstraction so that you can write code that is ignorant of unnecessary details. Interfaces aid you in designing more modular and robust software. With interfaces it’s possible to decouple direct dependencies between objects in your software.

 

Part 7 – Instructions

Here we will cover if/else, case-switches, for/while-loops and some other basic instructions. We will utilize our knowledge to write a CSV (comma separate value) event logger by using a state machine.

 

Part 8 – Tc2_Standard

As TwinCAT 3 conforms to the IEC61131-3 standard, there are certain things it has to be able to do. The Tc2_Standard library has many of the standard IEC functions such as timers and triggers, which we will look into in this chapter.

 

Part 9 – TwinCAT utilities

In this part we’ll learn how to use one of the most used Beckhoff libraries for various purposes. We’ll learn how to measure execution time of PLC code, how to use a FIFO buffer and how to combine the power of using a TwinCAT real-time program with an application running in user-space (Windows).

 

Part 10 – I/O

When designing and building a control system you will eventually want the control system to actuate something, be it a relay, a mixer, a boiler or maybe a pneumatic system. To get feedback of the actuation, sensors are needed. In this part we will cover how we communicate with the environment using inputs and outputs.

 

Part 11 – Libraries

Once the complexity of your software gets to a certain level it might be a good idea to start to think about splitting the software into different libraries. This part will go through how this is accomplished and what you need to think of.

 

Part 12 – TwinCAT functions

When installing the TwinCAT development environment and runtime you get access the core functionality, but sometimes you might want to extend this with additional functionality as for example adding an SQL database connection. In this chapter we will investigate some TwinCAT functions that can be added.

 

Advanced group

Part 13 – Version control

Version control in the world of automation has historically not been the highest priority, but with TwinCAT 3 this is entirely possible using standard version control software. In this part we will go through how we can do proper version control using the Git version control system.

 

Part 14 – Handling of different TwinCAT versions

When developing TwinCAT software over time you will most likely end up in a position where you must be able to develop and maintain software for various versions of TwinCAT. This chapter will go through how this is done.

 

Part 15 – ADS

The Automation Device Specification is Beckhoffs middleware to communicate with Beckhoff PLCs. It’s used for all kinds of use cases, as software deployment, reading/writing of variables and for internal communication of software modules. In this part we’ll go through the theory and also write some C# software to communicate with a PLC. We’ll also do a simple C++ program running under Linux that talks to the PLC!

 

Part 16 – TwinCAT automation interface

With the TwinCAT automation interface it’s possible to automate certain parts of the configuration, development and deployment process of your PLC software. In this chapter we will look into the possibilities with the TwinCAT automation interface and look at one example.

 

Part 17a – Test driven development

TDD is the practice of writing tests before writing the implementation code. Writing software using the practice of TDD is something that has been around in the traditional software development industry for a while, but only recently has gained attention in industrial automation. In this video, we will look at the theory of TDD, and then see how it’s done in practice.

 

Part 17b – Test driven development

This episode continues on the topic of test driven development (TDD). In this episode, we will implement the code that we wrote tests for in episode 17a.

 

Part 18 – Final words

So we’ve come to an end. For the last two years all my weekends, holidays, summer/winter vacations and basically every free-moment I’ve had, went into the creation of the free “PLC programming using TwinCAT 3” course on YouTube. It’s been the biggest hobby-project I’ve ever commited myself to, and I together with my wife would like to finish by saying a few words.

66 Comments, RSS

  1. ypi

    Hello,

    Im looking for a way to programatically activate the free-run state of a TwinCAT3 project. Do you know any way to do this?

    Thanks and super great blog!

    -A

      • Swapneel Mehta

        Hi jakob, your videos are awesome and so helpful. I am actually trying to install Visual Studio 2015 environment on a Beckhoff IPC and it seems like I need to install Visual studio before Twincat 3 to get integration done, But, i was nervous to uninstall Twincat 3 from the IPC, do you think it is risky? PLC is running and I don’t want to lose routes and connection to the PLC. Please suggest any ideas on how I can get Twincat 3 integrated in visual studio environment on the IPC itself? Thank you!

    • BusaRider1

      Yes, TC Automation Interface is what you should look at. I’ve been dabbling with it for programmatically configuring measurement channels in the PLC.

    • Innocent

      Hi everyone, I am looking to interface a Datalogic scanner with
      Twincat3 has anyone ever done it? I am thinking of Editing the sample code data logic wrote for Controllogix and reusing it.

  2. sumith

    I have been watching your tutorial for the last few days and it’s very useful for me, keep going.
    It would be a great help for those who interested in twincat .
    Thank a lot

  3. BusaRider1

    Love it!! Keep up the great work Jacob! AWESOME!!! Trust me, it’s very well appreciated from all of us using TwinCAT.

  4. Pick

    Hello, I’am training on my computer and waiting for the next tutorial I try to give back 1 core to windows, because even if the twincat programm is not running the core is not free. But if I change to share core does that mean twincat still own a piece of the core? And if I let a programme (running or not) and delete the folder? To cut short, how to be sure windows get back all the ressources after a dummy played with twincat?

  5. Mykhailo

    Bardzo dziękuję za szkolenie, bardzo chciałbym nauczyć programowaniu ruchu i bezpieczeństwa, ale to prawdopodobnie będzie w przyszłości, mam wielką nadzieję.

  6. Shun-Fa

    Hi,
    Those tutorials are great! And they are very useful when I am starting to use TwinCAT3. Please help to keep the great work for us who using TwinCAT3. Really Appreciated !!

    Thank you very much.

  7. David Vrabec

    Thank you Jakob, I have only watched the first video but it already looks like it has great production quality.
    I come mostly from Siemens HW PLCs, so having everything run on a PC is quite unusual, it will be interesting to learn how Beckhoff does things, even though I won’t use the brand at my current position. It seems like there is an extreme number of components and possibilities you can use in TwinCAT compared to TIA Portal.

    Did you think about setting a patreon or “Coffee tip” button, I am sure a lot of people would like to give back for your effort on this blog and on youtube.

    • Hi David! Thanks for your response. I’ve only very briefly used Siemens, and yes it’s a big difference in the philosophy between the two companies in how to do PLC-programming.
      I’m thinking of setting up some form of membership on YouTube or Patreon, for “coffee-level” money at some point, not sure when (if ever). Right now my focus is to finish the remaining parts of the tutorial. My ambition is to share some of my knowledge, and my hope is of course that the TwinCAT3-software community will do the same. Cheers!

  8. Devashish Patel

    Hi Jacob, I just landed a job that requires me to work extensively on PLCs, specifically TwinCAT3 and for a person who has no background in PLC programming, your videos are a real blessing. Cannot wait for all the upcoming parts.

  9. Dan

    Hey Jakob,

    Thanks for these tutorials man. Gone through them all so far and can’t wait for the next ones to come out. Been trying to figure out the right PLC standard for the company I work at and will be getting my hands on some Beckhoff hardware soon. In school I did Mechanical Engineering with a focus in Mechatronics and then was at Siemens for 2 years working with their PLCs which are good but definitely in the past as far as actual hardware and an IDE goes. I am excited to work with something much more dedicated to development and with so many possibilities.

    Keep up the awesome work!

  10. Scott Olson

    Hi Jakob,
    Your tutorials are amazing, my small team is all using them as training for the new hires.

    I have a Windows 10 vm running TwinCAT 3 in Parallels on an M1 Macbook pro and am unable to change the state of the TwinCAT system (change from Start to Config mode) and therefor cannot run any programs. Whenever I try to change it, I get the error “Error 0x426 starting TwinCAT system!”

    Do you know if this is a limitation of Parallels/ARM or did I not configure something correctly?

    I haven’t found a good answer online yet and VirtualBox doesn’t support ARM yet. Any help would be greatly appreciated!

    • Hi Scott! Sorry I don’t have any experience with MacBooks and TwinCAT. Have you enabled virtualization in the BIOS, and also done core isolation like I showed in the tutorial? I don’t own a Mac so I can’t test it myself unfortunately. I have found this thread. It’s not clear but it seems there are people that have managed to get TwinCAT 3 working on a MacBook in a virtual environment.

      Happy that you find my tutorials useful! If your company likes my tutorials, please consider becoming a member to support the work I put into them!

  11. arif

    Thanks for these tutorials. Rn Im working on projects that required me to use Twincat3 and beckhoff controller but for the communication part, I need to use DNP 3 as a protocol. Im stucked and don’t know how to use DNP 3 with Twincat3

  12. Sebastian

    Hello,
    I’m using the static code analysis to find “unused variables”.
    It’s showing variables I have in Unions as placeholders (for example I’m using a DWORD and underneath it a 32Bits for communication).
    Is there a posiibility to hide those from that feature?

    Best regards

  13. Jeff Varghese

    Love your tutorials. I have been sharing it with my friends who are also starting out on beckhoff controllers.

  14. Piotr M

    Hello Jakob, I just came back to your course after few months of brake and I see you’re still going strong with the course. Big thanks and best wishes in 2022!

  15. Hello Jakob,
    I just continued my PLC learning course by watching your latest post about IO.
    Thank you very much for these very good and useful materials. It’s a lot of work to create these tutorials / trainings I know from experience but it’s very much appreciated though.
    Whish you all the best for 2022!

  16. Minh Nguyen

    Hello Jakob! Thanks for your useful and knowledgeable tutorials. I’ve been working with other PLCs and now start with TwinCAT. I totally agree that the world of PLC is not really open and it has been hard to find information from time to time. It was very interesting for me to get knowledge about implementing interface and dependency injection in TwinCAT. I’ve never thought that they’re available in the PLC world as well (I’ve worked with C# so I know about them :)). Keep going and hope to see more posts from you soon!

  17. Jan F

    Thank you for this website. I found it today and I am really thankful for such a nice source of knowledge and experience for Beckhoff enviroment.

  18. Roy

    This twincat tutorial and your blog in general has been of tremendous help. Like you said, starting out with PLC programming is hard because the resources out there are always lacking in some way.
    Really glad you decided to do this and share it with the world for free, thank you so much Jakob!!

  19. Alex

    Thank you for what you are doing! I watched a video about a real PLC and ETHERCAT, it’s cool. But what if there are no slave devices. In the Instructions there is an opt-in for working with EtherCAT Simulation, but it seems to me this topic is not disclosed. Make a similar video, open the topic.

  20. Reza

    Hi Dear Jakob
    I begin to learn twinCAT FC5101 PC card. I haven’t found any good tutorial for that, and I have some questions on how to use it. Would you please help me to start working on it?

  21. Pete

    Hi Jakob,

    When are you going to launch Part 15 – ADS? 🙂 Waiting forward to see, how you make C++ program to communicate with PLC 🙂

  22. Alan

    Hi Jakob.

    Thanks for all the great work you’re doing with this tutorial series.

    Is the source code for the example program available anywhere (the PLC program that you’re writing throughout the tutorial series)?

  23. chunpeng zheng

    Hi Jakob,
    I am chunpeng,First of all I really appreciate the tutorial you made. I worked . I have been as an electrical engineer in China for almost 10 years, but my programming level has not been able to improve,you ignited my interest!

  24. chunpeng zheng

    Hi Jakob,
    Thanks for your the great work. I’ve lost interest in automation programming in the past, but now seeing your tutorials, I’ve rekindled my interest in automation programming.

    Thank you so much for everything you give

  25. Jakob,

    I am halfway through your third tutorial, and I find them to be truly excellent.

    However, the video quality is so bad, that the text on your screen shot clips is effectively unreadable. This is especially a problem with tutorial three, which is demo screen intensive.

    Is this issue in the video itself, or is it a YouTube problem.
    Is there another way to watch them?

    Thanks!
    Mike

  26. Yassine Cherragi

    Servus Jakob,
    hat jemand Idee über ADS-DLL C++
    und wie funktioniert den Befehl (ADS-sum command: Read or Write a list of variables with one single ADS-command).
    ich habe ein TwinCAT3 projekt mit 300 Variablen und muss sie mit ADS-Command innerhalb von 1-2 ms aufrufen.
    ich freue mich für Vorschläge und Ideen.
    LG
    Yassine

  27. Tiis

    Hi Jakob,

    thanks for these helpful videos. I am looking into a way to create an CI/CD for TwinCat 3 with Gitlab. I have been able to create a new TwinCat project that includes the project as a library and then does the tests. (This keeps the tests and the main program separated). However I want to automate this using Gitlab. Do you know if there is any documentation to be found on the internet?

    With kind regards,
    Tiis

  28. Hany

    Hii ,thanks for all the video there are very helfull,i have ro ask you how can i programm a PLC with visualisation without any beckhoff or other devices ,i nean only programing and visualisation as simulation and without using any other device.
    Only my laptop and windows on it and twincat 3 .
    Thanks and please if you can make a video about canbus programing on twincat3 .,too without devices only virtuelle .
    Is that possible ?

  29. David

    Thank you for your tutorials. It has been very helpful to me in learning Twincat 3. I am new in to PLC programming but the 3rd video is not clear and I have been having difficulties with the Hello World programme.

  30. Florim

    Hej Jakob, jag är väldigt intreserad om Beckhoff och Twincat , men hur är framtiden liksom utan riktigt utbildning är det något som jag kan lära mig på nätet för att kunna söka jobb sedan som PLC programerare eller förlurar jag tid bara på den här

    Hälsningar Florim

  31. Erik

    Hi Jacob

    It is really fantastic work you did. I really believe you should sell your material to schools.
    Even today again a student, programing Siemens in a very traditional way, violating many good practices of software development. Such a shame that the new generation start learning PLC programming in a bad way.

    What I myself struggle with is the new Event class system of Beckhoff for eventhandling.
    I want to work modular using libraries for control modules. These should include all event classes which should be added automatically.

    I find little to no information about it or any API to handle this
    May I ask how you are handling events, or do you have perhaps a reference for me, or a contact at Beckhoff who can explain the architecture ideas of their concept to me, Because I am really lost about their concept. I do not see how i can combine this with modular or functional programming. Now i created my own event handler, but there I struggle with localization

Your email address will not be published. Required fields are marked *

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.