|
| 1 | +# Why pyrung? A look at what else is out there |
| 2 | + |
| 3 | +## The big vendors have simulators. Click doesn't. |
| 4 | + |
| 5 | +Siemens has S7-PLCSIM. Allen-Bradley has the RSLogix Emulator. Beckhoff has TwinCAT's simulation manager. CODESYS has a built-in simulation mode and a paid Test Manager add-on. Even within AutomationDirect's own lineup, the Do-more and Productivity PLCs have software simulators built into their free programming tools. |
| 6 | + |
| 7 | +The Click PLC has none. AutomationDirect sells physical input simulator modules, toggle switches and potentiometer boards, but no software simulation. You write ladder in Click Programming Software, download to hardware, and test it there. If you don't have the hardware, you wait. |
| 8 | + |
| 9 | +## An emerging trend: people want more than GUI-only PLC programming |
| 10 | + |
| 11 | +For decades, PLC programming has meant vendor-specific graphical IDEs. You draw ladder in the vendor's editor, download to hardware, and hope. That's starting to change. |
| 12 | + |
| 13 | +For Structured Text, the vendor story is already meaningful. CODESYS has simulation, a Test Manager, Python scripting, and a unit testing framework (CoUnit). Beckhoff TwinCAT gives ST developers full Visual Studio integration with unit testing via TcUnit. Running a CODESYS soft PLC and driving tests from pytest over OPC-UA is an emerging pattern, though it amounts to integration testing against a running process rather than deterministic simulation of the logic itself. If your world is ST on those platforms, you're reasonably well served. |
| 14 | + |
| 15 | +Beyond the vendor ecosystems, independent projects are pushing further. [rungs.dev](https://rungs.dev/) is a browser-based ladder logic and ST editor with real-time simulation and an integrated test runner with deterministic, isolated scan cycles. It targets Allen-Bradley style (XIC/XIO/OTE, Add-On Instructions) and is the closest thing in spirit to pyrung's test-first philosophy, arriving from a completely different direction. |
| 16 | + |
| 17 | +Open-source PLC platforms like **OpenPLC** and **Beremiz** are full IEC 61131-3 environments with graphical editors, simulation modes, and multiple target hardware platforms. They're serious engineering, but they're PLC *replacements*, not test-first development tools for an existing vendor's hardware. |
| 18 | + |
| 19 | +## The ladder-as-text problem |
| 20 | + |
| 21 | +The pattern across all of this is clear: **people who want text go to Structured Text, and people who want ladder stay graphical.** The IEC standard positions ST as the text-based option. The CODESYS/Beckhoff ecosystem is investing heavily in that direction. |
| 22 | + |
| 23 | +But ladder remains the dominant language in North American discrete manufacturing, especially on platforms like Click, Do-more, and Allen-Bradley. Those users are stuck in proprietary graphical editors with no version control, no automated testing, and often no simulation. The ST crowd has options. The ladder crowd doesn't. |
| 24 | + |
| 25 | +The few Python projects that have tried to represent ladder, [pyladdersim](https://github.com/akshatnerella/pyladdersim) being the most visible, model rungs as flat lists of component objects: |
| 26 | + |
| 27 | +```python |
| 28 | +rung = Rung([Contact("Start"), InvertedContact("Stop"), Output("Lamp")]) |
| 29 | +``` |
| 30 | + |
| 31 | +The structure that makes ladder readable is lost. The idea of a proper text-based ladder with testability has been [floating around since at least 2000](https://mail.python.org/pipermail/python-list/2000-March/049350.html), but nobody shipped it. A CODESYS Forge user [asked for ladder scripting in Python in 2017](https://forge.codesys.com/forge/talk/Engineering/thread/fdc3d03c95/); the answer was "You can't do Ladder with Scripting." |
| 32 | + |
| 33 | +## What pyrung does differently |
| 34 | + |
| 35 | +```python |
| 36 | +with Program() as logic: |
| 37 | + with Rung(Start, ~Stop): |
| 38 | + out(Motor) |
| 39 | + with Rung(Fault): |
| 40 | + reset(Motor) |
| 41 | +``` |
| 42 | + |
| 43 | +Condition on the rail, instruction in the body. The `with` block naturally separates "when this is true" from "do this," which is exactly what a ladder rung does. It reads like the diagram, runs as a deterministic scan cycle, and targets real Click PLC behavior faithfully. |
| 44 | + |
| 45 | +**The code looks like ladder.** Not Structured Text. Not flat lists. Not ASCII art. The DSL preserves the condition/instruction structure that makes ladder readable, in code a controls engineer can map to the diagram they already know. |
| 46 | + |
| 47 | +**You can watch it evaluate.** A full DAP-protocol VS Code debugger steps through scans rung by rung. Breakpoints on rungs, inline tag updates, force values, diff between scans, time-travel through history. |
| 48 | + |
| 49 | +**It targets real hardware faithfully.** Nearly the complete Click instruction set, memory banks, numeric quirks, scan-cycle semantics. If your program behaves differently in pyrung than on a Click PLC, that's a bug. |
| 50 | + |
| 51 | +**It deploys without transposing.** pyrung compiles to two backends from the same tested source. For Click, [laddercodec](https://github.com/ssweber/laddercodec) encodes your rungs into the bytes the CLICK editor expects on paste. For the ProductivityOpen P1AM-200, pyrung generates a self-contained CircuitPython scan loop that runs directly on the hardware with the same Modbus TCP interface as a Click. Write once, test once, deploy to either. |
| 52 | + |
| 53 | +## Where pyrung fits |
| 54 | + |
| 55 | +The emerging tools above are vendor-agnostic by design. rungs.dev runs in a browser. OpenPLC replaces the vendor stack entirely. |
| 56 | + |
| 57 | +pyrung chose fidelity over generality, because the whole point is to test before you deploy to a specific PLC. But fidelity to Click behavior doesn't mean fidelity to Click hardware alone. The same logic that simulates faithfully against Click's instruction set can also compile to CircuitPython and run on open hardware with no proprietary toolchain in the path. That combination, faithful simulation of a real vendor's behavior plus deployment to hardware the vendor doesn't control, is something none of the tools above attempt. |
| 58 | + |
| 59 | +The ladder-as-text problem has been open for 25 years. pyrung is a serious attempt at closing it. |
0 commit comments