agentleFS
SmailGSmailG/plc-programming/skills/iec-61131-3/SKILL.md

iec-61131-3

Skill0 starsChanged 37 days agoMITView on GitHub

Reference for IEC 61131-3 PLC programming (Ed.2 2003, Ed.3 2013, Ed.4 2025) and PLCopen conventions. Covers the five languages: Structured Text (ST), Instruction List (IL, deprecated in Ed.3 and removed in Ed.4), Ladder Diagram (LD), Function Block Diagram (FBD) and Sequential Function Chart (SFC). Also covers POUs (PROGRAM, FUNCTION_BLOCK, FUNCTION, CLASS, METHOD, INTERFACE, NAMESPACE), variable sections, data types, the standard functions and FBs (TON/TOF/TP, R_TRIG, CTU, SR/RS), configuration/resource/task, the PLCopen Coding Guidelines v1.0 and naming prefixes, and the PLCopen Motion and Safety FB patterns. Use whenever you write, read, explain, translate or check vendor-neutral PLC code, or when a question depends on what the standard allows or on which edition introduced a feature.

The file

We split this skill into the rules it gives an agent

2 rules. About 0 are common, 0 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Write standard ST unless the platform skill says otherwise.

    line 95
  2. Very specific:

    Run python3 ${CLAUDE_PLUGIN_ROOT}/scripts/plc_validate.py <file> on what you wrote.

    line 97

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

IEC 61131-3 and PLCopen

The standard is the common ground. Vendor dialects (Siemens SCL, CODESYS/TwinCAT, Schneider, Logix) add to it or deviate from it, so check this skill first and the platform skill second.

Facts you must get right

QuestionAnswer
Current editionEd.4, IEC 61131-3:2025, published 2025-05-22. Ed.3 (2013-02-20) was withdrawn on that date
IL statusDeprecated in Ed.3 and removed in Ed.4. Keep IL only for legacy maintenance. Never choose it for new code
Languages in Ed.4ST (textual), and LD and FBD (graphical). SFC is the structuring element on top of them
OOP (CLASS, METHOD, INTERFACE, EXTENDS, IMPLEMENTS, THIS/SUPER, access specifiers)Added in Ed.3
REF_TO / REF() / ^ / NULL, ARRAY[*], LTIME/LDATE/LTOD/LDT, CHAR/WCHAR, CONTINUE, NAMESPACE/USING, ?= assignment attemptAdded in Ed.3
USTRING/UCHAR (UTF-8), ASSERT, mutex/semaphore, PROPERTY_GET/PROPERTY_SETAdded in Ed.4
PROPERTY before Ed.4A CODESYS/TwinCAT extension, not in Ed.3
Octal literals 8#…, untyped TRUNC(x)Deprecated in Ed.3 and removed in Ed.4
BCD conversion functionsDeprecated in Ed.4
REAL→INT conversionRounds to nearest, ties to even: REAL_TO_INT(2.5) = 2. TRUNC truncates toward zero
String positions (MID, FIND, INSERT…)1-based
Short-circuit evaluation of AND/ORPermitted, not required. Never rely on it. CODESYS offers AND_THEN/OR_ELSE for the guaranteed form
Precedence of -/NOT vs **The standard ranks unary -/NOT above **, while CODESYS ranks ** above them. Parenthesise

State the edition whenever it matters, for example "USTRING needs an Ed.4 toolchain". Most shipping IDEs in 2026 implement Ed.3 plus vendor extensions.

Choosing a language

Part of the programBest fitWhy
Sequences with steps and waits (fill → heat → drain, homing, recipes)SFC, or an ST CASE state machineShows the state explicitly, and SFC step flags s.X and s.T come for free
Interlocks, permissives, simple discrete logic that maintenance must read onlineLDElectricians can follow power flow when monitoring online
Signal flow and continuous control (scaling, PID, filters)FBDMirrors a block diagram
Algorithms, maths, string/array handling, state machines, OOPSTCompact and diffable. It is also the only textual language left in Ed.4
Anything newNever ILIt is gone from Ed.4

POU rules (short form)

  • FUNCTION has no memory between calls and returns a value. It may not instantiate FBs that need state, and it must be deterministic.
  • FUNCTION_BLOCK is instantiated and keeps state in its instance. Call each instance exactly once per scan (PLCopen CP20), and gate its inputs instead of its call. See the TON trap in the debug skill.
  • PROGRAM is the top level and is associated with a TASK. PLCopen CP16 says tasks call only PROGRAMs.
  • VAR_IN_OUT is by reference. RETAIN/NON_RETAIN are not allowed on it.
  • VAR_INPUT must not be written inside the POU. VAR_TEMP is re-initialised on every call.
  • R_EDGE/F_EDGE on a BOOL VAR_INPUT creates the edge detector implicitly.
  • %I, %Q and %M addresses have the form % + I/Q/M + size (X or none, B, W, D, L)
    • dotted numbers, for example %IX0.0, %QW4, %MD48. %I* must be completed in VAR_CONFIG. PLCopen N1: declare a symbol instead of using addresses in code.

Reference files

Load only the file the task needs:

  • references/editions.md: edition history, what each edition added, removed or deprecated, and IEC TR 61131-8.
  • references/structured-text.md: ST syntax, precedence, statements, literals and idioms.
  • references/instruction-list.md: IL operators and modifiers, for reading and migrating legacy code.
  • references/ladder-and-fbd.md: LD contacts and coils, FBD rules, EN/ENO.
  • references/sfc.md: steps, transitions, divergence rules, action qualifiers (N R S L D P P0 P1 SD DS SL) and the final-scan rule.
  • references/pous-oop-config.md: POU types, OOP, namespaces, and CONFIGURATION/RESOURCE/TASK.
  • references/data-types-and-variables.md: elementary, generic and derived types, variable sections and qualifiers.
  • references/standard-library.md: conversion, numeric, bit, selection, comparison and string functions, and the standard FBs with their pins.
  • references/plcopen-guidelines.md: PLCopen Coding Guidelines v1.0 rules, naming prefixes, and the Motion (MC_) and Safety (SF_) patterns.

How to use this when writing code

  1. Name the target platform and edition first. If the user has not said, ask, because vendor dialects differ in ways that fail compilation.
  2. Write standard ST unless the platform skill says otherwise. Mark any vendor extension you use (PROPERTY, POINTER TO, {attribute}, AND_THEN).
  3. Run python3 ${CLAUDE_PLUGIN_ROOT}/scripts/plc_validate.py <file> on what you wrote. It catches structural errors, not type errors, so say that it is not a compile.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.