Attention

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

Working with Multiple Files

As your IEC 61131-3 application grows, you will want to organize your code across multiple files. IronPLC combines all files into a single unit, so you can split your application however you like.

Split the Application

Right now, main.st contains both the program and the configuration. Let’s separate them.

First, edit main.st so it contains only the program:

main.st — Program only
PROGRAM main
   VAR
      Button AT %IX1: BOOL;
      Buzzer AT %QX1: BOOL;
   END_VAR

   Buzzer := NOT Button;

END_PROGRAM

Next, create a new file for the configuration:

  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:

    config.st — Configuration only
    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
    
  4. Save the file with the name config.st.

The IronPLC extension checks all .st files in the workspace together, so it will still validate that the configuration references a valid program.

Why Split Files?

For a small example like this, splitting may seem unnecessary. But in real-world projects, separating programs from configuration has clear benefits:

  • Reuse — the same program can be referenced from different configurations (for example, testing vs. production).

  • Organization — each file has a single responsibility.

  • Collaboration — different team members can work on different files.

IronPLC does not impose any naming conventions on your files. Use whatever structure makes sense for your project.

Next Steps

You now have a complete, multi-file IEC 61131-3 application. In the final chapter, you will compile it into a bytecode container and run it.

Continue to Compiling and Running.