In this tips and tricks post I will demonstrate the usage of the attribute: ‘instance-path’. The instance path attribute allows you to get the instance path of the containing POU in a string variable. Something I find particularly useful for error-logs and debug messages. How to use it 1. We need a string variable which […]
TwinCAT meets Project Euler
During the latest COVID lock down, scrolling randomly through the internet, I stumbled on Project Euler, a series of mathematical/computer programming problems. So I thought it would be fun to try a few challenges with Structured Text. After completing the first 2 challenges it occurred to me that it might be fun to publish a repo on Github with this project, to see if I can get more people to solve challenges and on the fly creating a lot of mathematical Structured Text example code.
Invoking RPC methods with TwinCAT ADS .NET
RPC method are methods in TwinCAT which can called from outside the scope of your application. For example an OPC UA client or an ADS client. In this post I show how to invoke RPC methods in your TwinCAT PLC from a .NET application.
Tips and tricks: View whitespace
In this post I show to make the whitespace visible in Codesys and TwinCAT.
You should use AND_THEN. OR_ELSE?
In this post I’ll discuss the operators ‘AND_THEN’ and ‘OR_ELSE’. Operators which I find really useful from time to time.
Instance variables with VAR_INST
Instance variables are available for funtion block methods. Unlike ‘normal’ variable their values are preserved between method calls.
STweep – The formatter for Structured Text
STweep is a formatter for Structured Text integrated in Codesys and TwinCAT. STweep assists in enforcing a consisting code style!
VAR declarations: VAR_TEMP, VAR_STAT and VAR CONSTANT
Most of you know the most variable sections, VAR, VAR_INPUT, VAR_OUTPUT, VAR_IN_OUT and VAR_PUBLIC. However in TwinCAT we have some more variable sections available. In this post I will discuss and explain the usage of VAR_TEMP, VAR_STAT and VAR CONSTANT. Variable section which I find very use full from time to time.
Communicating between Beckhoff controllers part 2: ADS
In part 2 of the series: “Communication between Beckhoff controllers” we discuss the protocol Automation Device Specification or ADS.
Tips and Tricks: Variable list declaration
In this post we discuss the feature variable list declaration.
A little known but valuable trick in TwinCAT!
Communicating between Beckhoff controllers part 1: EAP
In this posts we show an step by step tutorial for communication between Beckhoff controllers using the EtherCAT Automation Protocal (EAP).
Tips and Tricks: Arrays are value types!
In TwinCAT arrays are treated as value types. In this post I show an example of this behavior as well as some alternatives.
TwinCAT and MQTT – Part 2 JSON messages
In the previous post “TwinCAT and MQTT – Part 1 Getting started” We covered the basics for MQTT in TwinCAT. Using the Mosquitto broker and two PLC we were quickly able to exchange messages between the PLC, and later on we read the messages with a smartphone too.
In part 1 we published a simple string indicating the room temperature. However in real life we soon want to send more data and parameters in one message. Composing such strings is hard, but decompiling it back to actual data is even harder. Luckily we can make use of one of the world most popular data formats : ‘JSON’. In this post I show how publish and receive complete data structures using JSON.
TwinCAT and MQTT – Part 1 Getting started
MQTT is an extremely lightweight publish/subscribe messaging transport protocol. Because it is such a lightweight protocol MQTT is widely used in IOT devices. This series of posts show the basis of MQTT and TwinCAT together with some more advanced examples using JSON.
Tips and Tricks: How to configure an array monitoring range
Last week Andrew Patten posted an excellent trick in the TwinCAT forum which I was unaware of. So I thought it would be a good idea to share it here as well: In the online view of TwinCAT and CodeSys the range of monitored array member can be limited by double clicking the type cell […]
Getting started: Home Assistant and TwinCAT
In this Getting started: Home Assistant and TwinCAT I’ll show that basics of setting up communication between Home Assistant and TwinCAT.
Fluent interface in Structured Text
A popular programming design in high level languages as C# is the so-called ‘fluent code’ or ‘fluent interface’. But what is a fluent interface and how can we implement this in Structured Text? In this post I briefly explain what a fluent interface is and give an example of a fluent interface in Structured Text.
TwinCAT UML class diagram
When working with OOP concepts as discussed in the series “The three pillars of OOP” it might get hard to keep track of your program architecture when your program grows. As this is a common struggle in the world of the programming some smart people came up with the Unified Modeling Language. Or short UML. With UML we can visualize and develop our software graphically. In this post I’ll show how to generate an UML class diagram in TwinCAT.
The ABSTRACT keyword
It was already available in CODESYS, but with the release of TwinCAT 4024 it’s now available in TwinCAT as well: the ABSTRACT keyword. Abstraction and the use of the abstract keyword is common practice in OOP and many higher level languages as C# support this. It’s often considered as the fourth pillar of OOP. In this post i’ll explain how to use the ABSTRACT keyword in TwinCAT with some practical examples.
Keep your online view clean: The hiding attributes
In the post ‘How to use monitoring attributes’ I showed how to use the monitoring attributes: attribute ‘monitoring’ := ‘variable’ and attribute ‘monitoring’ := ‘call’. With these pragma attributes we can monitor and modify our function blocks properties. This comes however with a small drawback. As the online view now shows your properties and their backing fields your online view gets less clear. In this post I will show how to solve this with the hiding attributes.
The three pillars of OOP – Polymorphism
With the object orientated options we’ve got available with IEC 61131-3 last years the time has come to talk about design patterns and best practices in the world of PLC programming. In this series of three posts ‘The three pillars of OOP’ I will explain the concepts of: Encapsulation, Inheritance and Polymorphism with some examples in TwinCAT. This post is about the third pillar ‘Polymorphism’.
The three pillars of OOP – Inheritance
With the object orientated options we’ve got available with IEC 61131-3 last years the time has come to talk about design patterns and best practices in the world of PLC programming. In this series of three posts ‘The three pillars of OOP’ I will explain the concepts of: Encapsulation, Inheritance and Polymorphism with some examples in TwinCAT. This post is about the second pillar ‘Inheritance’.
The three pillars of OOP – Encapsulation
With the object orientated options we’ve got available with IEC 61131-3 last years the time has come to talk about design patterns and best practices in the world of PLC programming. In this series of three posts ‘The three pillars of OOP’ I will explain the concepts of: Encapsulation, Inheritance and Polymorphism with some examples in TwinCAT. This post is about the first pillar ‘Encapsulation’.
How to use monitoring attributes
Every programmer spends a considerable amount of time debugging their software. In the world of PLC programming it’s common to login to the PLC and monitor and write your variables. However, with the introduction of properties for your function blocks monitoring is not as plain as it used to be. In this post I’ll explain how to use monitoring attributes for your properties in TwinCAT.
A Code Jam challenge with Structured Text
Every year I participate in a number of online code challenges like Facebook Hacker Cup, Google Code Jam and Advent of Code. Although I never make it really far I quite enjoy the puzzles which I usually make in C#. Definitely not the fastest language out there, but LINQ makes life easy 🙂 . Since I spent every week a considerable amount of time PLC programming, I found myself wondering if I could solve A Code Jam challenge with Structured Text. Spoiler alert, yes you can, but it doesn’t come very easy.. So I decided to write a small post about it, pointing out the challenges I faced.