Attention

IronPLC can only run very simple programs. The steps described are accurate but many language features are not yet supported.

Overview

You can use the command line interface to check a file (and sets of files) for correctness.

Note

This guide assumes you have installed the IronPLC Compiler. See Installation if you have not already installed it.

Create a Project Directory

You’ll start by making a directory to store your IEC 61131-3 code. ironplcc doesn’t care where your code lives (and your code can be in multiple directories), but creating a directory will make it easy to work with your code.

Open a terminal and enter the commands in Create Project Directory to make the ironplc-hello-world directory.

Create Project Directory
mkdir ~/ironplc-hello-world
cd ~/ironplc-hello-world

Create an IEC 61131-3 Program

The next step is to create a source file for your IEC 61131-3 program. ironplcc doesn’t care what your call your file(s), but it will automatically detect file names with the .st extension as IEC 61131-3 programs.

See also

IronPLC also supports PLCopen XML and TwinCAT formats. See Source Formats for all supported formats.

In the same terminal, enter the commands in Create Hello World Program to create a program.

Create Hello World Program
echo "PROGRAM main
   VAR
      Button AT %IX1: BOOL;
      Buzzer AT %QX1: BOOL;
   END_VAR

   Buzzer := NOT Button;

END_PROGRAM

CONFIGURATION config
   RESOURCE res ON PLC
      TASK plc_task(INTERVAL := T#100ms, PRIORITY := 1);
      PROGRAM plc_task_instance WITH plc_task : main;
   END_RESOURCE
END_CONFIGURATION" > main.st

Check the Program for Correctness

Finally, in the same terminal, run the commands in Check Syntax to check your program’s syntax.

Check Syntax
ironplcc check main.st

On success, the command produces no output.

Compile the Program

Warning

The compile command currently supports only trivial programs. Supported features include: PROGRAM declarations, INT variable declarations, assignment statements, integer literal constants, and the + (add) operator. Programs using other features will produce a code generation error.

You can compile a source file into a bytecode container (.iplc) file using the compile command. Run the commands in Compile Program to compile your program.

Compile Program
ironplcc compile main.st --output main.iplc

On success, the command produces no output and creates the .iplc file at the specified output path.

You can also use the short form -o for the output flag:

ironplcc compile main.st -o main.iplc

Execute the .iplc File

To run a compiled .iplc file, use the IronPLC virtual machine runtime ironplcvm:

ironplcvm run main.iplc

You can inspect variable values after execution by specifying a dump file:

ironplcvm run main.iplc --dump-vars output.txt