PLCSim — Simulator
Documentation Course Terms of Use
| |

PLCSim

Simulate PLC programs in Structured Text (IEC 61131-3) directly in VS Code — no hardware needed.

Write and run complete Structured Text programs directly in VS Code. No hardware, no compilation, no deployment. Free forever for learning and prototyping; Pro unlocks the tools you need for serious work.


Get started

VS Code 1.90 or later. No additional software required for Free features. MQTT broker required for MQTT connectivity (Pro).

Install PLCSim Search "PLCSim" in the VS Code Extensions panel and click Install.
Open the PLCSim panel Click the PLCSim icon in the Activity Bar. Load one of the built-in examples or open your own .st file.
Run the simulator Interact in real time — toggle inputs, change values and watch outputs react. No compilation, no deployment.

Full IEC 61131-3 Syntax & Simulator FREE

Language

Scalar types BOOL · SINT INT DINT LINT · USINT UINT UDINT ULINT · REAL LREAL · TIME DATE TIME_OF_DAY DATE_AND_TIME · STRING WSTRING · BYTE WORD DWORD LWORD
User-defined types STRUCT, ENUM (with optional default member), ARRAY (1D and 2D, including arrays of function block instances), typed literals (WORD#16#FF, DINT#-100)
References REFERENCE TO / REF_TO (IEC 61131-3 Edition 3) — REF(), dereference ^, NULL, with clear runtime errors on NULL access
Variables & scope VAR, VAR_INPUT, VAR_OUTPUT, VAR_IN_OUT, VAR_TEMP, VAR_GLOBAL, PERSISTENT, RETAIN
Control flow IF / ELSIF / ELSE, FOR, WHILE, REPEAT, CASE, RETURN, EXIT, CONTINUE
Logic & arithmetic AND, OR, NOT, XOR, comparators, + * / MOD **
Bitwise operators AND, OR, XOR, NOT (on WORD/INT)
Shift & rotate SHL, SHR, ROL, ROR
Timers TON, TOF, TP, TONR
Counters CTU, CTD, CTUD
Bistables & edges RS, SR, R_TRIG, F_TRIG
Standard functions 30+ functions: String (LEN, CONCAT, REPLACE, LEFT, RIGHT, MID), Math (ABS, SQRT, SIN, COS, ROUND, FLOOR, CEIL, TRUNC), Type conversions, Time/Date, Array bounds
Comments Block (* ... *), line // ..., doc comments (** ... *) for auto-generated documentation
Syntax highlighting Full .st language support
Examples 20 ready-to-run programs included

Simulator

Interactive panel Toggle BOOL inputs, set INT/REAL values and watch outputs update instantly.
Scan cycle control Configurable from 10 ms to 5000 ms with drift compensation
Trend charts Oscilloscope view for every variable — 30 s of history, auto-scrolling
Cold / Warm restart Explicit restart buttons in the Simulator panel — Cold clears RETAIN state, Warm preserves it, matching real PLC restart semantics
PLCSim — Simulator RUNNING (SCAN: 142)
NAME TYPE VALUE DIR
bsensorentry BOOL IN
bsensorexit BOOL IN
itarget INT 100+ IN
bmotor BOOL TRUE OUT
icounter INT 47 OUT
blotdone BOOL FALSE OUT
Trends — ILEN Logic Over Time

Unit Testing Framework PRO

Write YAML test plans and run them from the VS Code Testing tab.

# .plcsim.yaml test plan file
name: String Support Verification
steps:
  - set: sordercode
    value: "ORD-ABC-042"
  - wait: 100
  - assert: ilen
    expected: 11
  - assert: bready
    expected: true

Pro — Debugging & Test PRO

Native Debugger (DAP) Set breakpoints in .st files, step over (F10), step into function blocks (F11), inspect variables in the Variables panel and on hover
Watch Window Live variable list with filter, sort, pinned variables and change history
Single Scan / Step Pause the simulator and execute one scan cycle at a time
Snapshots Capture and restore simulator state — ideal for reproducing bugs
Unit Testing Write YAML test plans and run them from the VS Code Testing tab.

AI Assistant (@plcsim) FREE

A chat participant that writes IEC 61131-3 Structured Text code from a plain-language description — and never shows you code it hasn't verified against PLCSim's own compiler.

@plcsim chat participant Describe the logic you need in VS Code's Chat panel; get back a validated ST code block with a transparency footer ("validated on first try" / "after N retries")
Built-in safety rules Fail-safe (NC) inputs, explicit IEC 60204-1 stop categories, bounded/deterministic loops, safe arithmetic — real industrial conventions, not generic coding advice
Validation loop Every response is checked with the same LSP engine that powers editor diagnostics before you see it, with up to 3 automatic retries on error
Bring Your Own Key (BYOK) Works with GitHub Copilot Chat by default, or connect your own Anthropic (pay-per-token) or Google Gemini (free tier available) API key via PLCSim: Configure AI Provider — keys are stored in the OS keychain, never on disk

Editor Intelligence (LSP) FREE

Real-time diagnostics Syntax and type errors underlined as you type — no need to run the simulator
Code completion IntelliSense for variables, function blocks, standard functions and keywords
Hover documentation Type information and signatures on hover
Go to Definition F12 to jump to any variable or function block declaration
Find All References See every usage of a symbol across your project
Rename Symbol F2 to safely rename a symbol and all its references in one step
Cross-file support All LSP features work across multiple .st files in the same workspace

Pro — Project Structure PRO

Custom Function Blocks FUNCTION_BLOCK definitions, nested instances
Multi-File Projects Multi-file projects (types/, globals/, blocks/)
# PLCSim: New Project ← generates this layout
workspace/
├── types/   ← TYPE … END_TYPE (structs, enums)
├── globals/ ← VAR_GLOBAL blocks
├── blocks/  ← FUNCTION_BLOCK definitions
└── Main.st  ← main program logic

FB Instances PRO

fbstation : station
bstart [input] false
ballrunning [output] true
banyfault [output] false
fbmotor1 : motor
bstart [input] true
brunning [output] true
iruncount [output] 0

PLCSim — WATCH PANEL PRO RUNNING (SCAN: 0)
NAME TYPE VALUE DIR
sprefix STRING "ORD" OUT
sproduct STRING "ABC" OUT
sstatus STRING "Order: ORD-ABC-042" OUT
sordercode STRING "ORD-ABC-042" IN
smachinestate STRING "RUNNING" IN
ilen INT 11 OUT
idashpos INT 4 OUT
bready BOOL TRUE OUT

Ladder Diagram Editor PRO

A visual editor for Ladder Diagram (LD) that compiles directly to the same Structured Text engine as the rest of PLCSim.

Visual canvas Draw contacts, coils and parallel groups on an SVG canvas — undo/redo, live structural validation and auto-generated variable declarations
Unified tool + form pattern One toolbar per element family (Contact / Coil / Group / Block): click a tool, click a placement point, fill in a small inline form
Timer & counter blocks TON, TOF, CTU, CTD and CTUD as first-class Ladder elements — placed and wired from the canvas, with automatic multi-instance aggregation
Coil fork Multiple coils per branch, each driven by the accumulated logic since the start of the branch — the same pattern used in TIA Portal, Studio 5000 and CODESYS
Documentation generator Turn a Ladder Diagram into readable Markdown documentation, same tooling as the ST doc generator

Pro — Export & Dialects PRO

TIA Portal export Export programs as .scl files ready to import in Siemens TIA Portal
TwinCAT export (beta) Export programs as native TwinCAT files (.TcPOU/.TcDUT/.TcGVL) — import in TwinCAT XAE with Add > Existing Item
Siemens SCL dialect Native SCL syntax support
Beckhoff TwinCAT TwinCAT ST syntax support
Schneider Unity Unity Pro ST syntax support

Pro — Industrial Communications PRO

OPC-UA server Exposes all variables as OPC-UA nodes — connect any SCADA or HMI
Modbus TCP server Map variables to coils, discrete inputs, holding and input registers — and verify the mapping from a .plcsim.yaml test plan (assert_modbus), no external client needed
EtherNet/IP server Map variables to CIP tags
MQTT connector Publish variables to Node-RED, Home Assistant or MQTT brokers
// protocols.config.json
{
  "protocols": [
    { "modbusTCP":  { "enabled": true, "port": 5020 } },
    { "ethernetIP": { "enabled": true, "port": 44818 } },
    { "opcua":     { "enabled": true, "port": 4840,
                   "nodeIdFormat": "generic" } },
    { "mqtt":      { "enabled": true,
                   "brokerUrl": "mqtt://localhost:1883" } }
  ]
}

Pro — Object-Oriented Programming PRO

Modern IEC 61131-3 Edition 3 with classes, inheritance, interfaces and polymorphic dispatch.

Classes CLASS blocks with methods, properties, and internal state
Inheritance EXTENDS for single-parent inheritance; SUPER to call parent methods
Interfaces & polymorphism INTERFACE contracts with IMPLEMENTS; use an interface name as the type of a variable, parameter or array element — calls dispatch to the actual type of the assigned instance
Properties Computed attributes with GET and SET accessors
Methods Callable procedures with parameters and return values
THIS Reference to current instance inside methods and properties
Instance collections ARRAY[..] OF <FB> and nested sub-instances (outer.inner.Method()) for the "N identical devices in a loop" pattern

Pro — Documentation PRO

ST Documentation Generator Generate Markdown documentation from (** ... *) doc comments — @description, @param, @returns, @author and @version tags for FUNCTION_BLOCK, FUNCTION and PROGRAM

AI Agents (MCP Server) FREE PRO

Connect Claude Code, Claude Desktop or any MCP client directly to the PLCSim simulation engine, without VS Code open.

Free tools plcsim_validate, plcsim_hover, plcsim_definition, plcsim_references, plcsim_rename, plcsim_simulate, plcsim_validate_ladder, plcsim_compile_ladder, plcsim_simulate_ladder — same diagnostics, LSP, simulator and Ladder engine as the editor
Pro tools plcsim_debug_run, plcsim_run_tests, plcsim_export, plcsim_generate_docs, plcsim_generate_ladder_docs — debugging, tests, export and documentation (ST and Ladder)

Server at ~/.plcsim/mcp-server/index.mjs — created automatically, stable across updates.