Attention

IronPLC implements many parts of the IEC 61131-3 standard and is working toward full Structured Text support. Key features still missing include arrays and structures. Try it out in the IronPLC Playground.

Hello, World!

Now that you’ve installed IronPLC, it’s time to write your first program.

In most programming languages, “Hello, World” prints text to the screen. IEC 61131-3 is designed for real-time automation controllers that often do not have a display, so our “Hello, World” will look a little different. In this chapter, we write the simplest possible program and use IronPLC to check it for correctness.

Create a Project Directory

In a Terminal, create a new folder and open it in Visual Studio Code:

Create Project Directory
mkdir helloworld
cd helloworld
code .

Write Your First Program

In Visual Studio Code:

  1. In the main menu, select File ‣ New File….

  2. In the New File… dialog, select the Structured Text File option.

  3. Enter the following code into the Editor:

    Hello World
    PROGRAM main
       VAR
          Counter : INT := 0;
       END_VAR
    
       Counter := Counter + 1;
    
    END_PROGRAM
    
  4. Save the file with the name main.st.

That’s it — you have written a valid IEC 61131-3 program. If IronPLC’s VS Code extension is installed, you should see no errors highlighted in the editor.

What This Program Does

Let’s break it down:

  • PROGRAM mainEND_PROGRAM defines a program named main. A program is the basic unit of control logic in IEC 61131-3, similar to a main function in other languages.

  • VAREND_VAR declares a variable named Counter of type INT (a 16-bit signed integer), initialized to 0.

  • Counter := Counter + 1; is an assignment statement. The := operator assigns the value on the right to the variable on the left.

This program increments a counter by one each time it runs. On a real PLC, this would happen on every scan cycle — but we have not configured that yet. We will add that in Configuring Your Application.

Tip

For a deeper look at Structured Text syntax, see Structured Text Basics.

Next Steps

In the next chapter, we will make the program more interesting by connecting it to inputs and outputs using a doorbell example.

Continue to The Sense-Control-Actuate Cycle.