Why a Logic Editor Inside a Simulation Tool?
Anyone who works with material flow simulation knows the problem: the simulation shows that a bottleneck occurs — but not why the PLC program at a particular station is dragging down the cycle. Between the abstract simulation model and the real PLC program, there's a gap that in practice leads to weeks of commissioning delays.
With Phase 9 of FactoryLine Pro, we close that gap. The new Component Logic Editor lets you define complete control logic for every station in your factory — directly inside the simulation environment, without opening TIA Portal. The logic is modeled according to IEC 61131-3, can be exported as SCL, and can be traced step by step in the integrated debugger.
Two Views, One Model
One of the first design decisions was fundamental: do we support FBD (Function Block Diagram), Ladder Diagram, or both? The answer became clear quickly. In the DACH manufacturing industry, some commissioning engineers prefer FBD while others swear by Ladder. Supporting both views simultaneously wasn't a nice-to-have — it was a hard requirement.
The solution: a single data model in the backend that serves both views. Each network consists of elements (contacts, coils, function blocks) and connections between them. The FBD view renders these as a React Flow canvas with freely positionable blocks. The Ladder view translates the same model into classic rungs with power rails, series contacts, and parallel branches.
Switching between FBD and Ladder happens with a single click — no data loss, no recalculation. Whatever you change in FBD is instantly visible in Ladder and vice versa.
27 Standard Function Blocks per IEC 61131-3
The editor ships with a complete library of IEC-compliant function blocks, organized into logical categories:
That alone would be sufficient for a generic PLC development environment. But FactoryLine Pro isn't a generic tool — it's simulation software for production lines. That's why we developed five custom function blocks that reduce typical machine control patterns to a single block.
| Category | Blocks | Application |
|---|---|---|
| Logic | AND, OR, NOT, XOR | Basic combinational logic |
| Bistable | SR, RS | Latching elements |
| Edge | R_TRIG, F_TRIG | Edge detection |
| Timer | TON, TOF, TP | Time-based control |
| Counter | CTU, CTD, CTUD | Part counting, batch control |
| Compare | CMP_GT, CMP_LT, CMP_EQ, CMP_GE, CMP_LE | Threshold monitoring |
| Arithmetic | ADD, SUB, MUL, DIV | Calculations |
| Data | MOVE, SEL, MUX | Value transfer, selection |
Five Custom Blocks for Manufacturing
Anyone who has ever programmed a pneumatic cylinder controller in FBD knows: a clean implementation with end-position detection, timeout monitoring, and error handling quickly requires 15–20 blocks and half a dozen networks. Our CYLINDER_CTRL block encapsulates all of this logic in a single element with six clearly defined states: Idle, Extending, Extended, Retracting, Retracted, and Error.
Each of these blocks is directly connected to FactoryLine Pro's physics engine. A CYLINDER_CTRL block doesn't just drive virtual signals — it actually moves the simulated cylinder with realistic travel times.
- SEQUENCE manages step sequences with N steps and configurable timeout per step — the most common use case in station control
- CYLINDER_CTRL models pneumatic cylinders as a state machine with end-position sensors, timeout, and error handling
- HANDSHAKE implements the classic station-to-station part transfer protocol with Request/Acknowledge/Complete
- MOTOR_CTRL controls motors with ramp-up, speed monitoring, and fault handling
- SENSOR_DEBOUNCE debounces sensor signals with configurable debounce time — essential for light barriers in high-vibration environments
The Compiler: From Networks to Executable Logic
A visual editor is only half the battle. The real challenge was the LogicCompiler — the module that translates the visual representation into an executable sequence.
The core problem: in an FBD network, blocks can be connected in arbitrary ways, including circular dependencies. To ensure the evaluation order is deterministic and correct, we use Kahn's algorithm for topological sorting. The compiler traverses the connection graph, detects cycles (and reports them as errors), and produces a flat, ordered list of evaluation steps.
The result: `LogicRuntime.execute_cycle(dt_ms)` evaluates all networks for a component on every simulation tick — read inputs, evaluate contacts and function blocks, write coils. Optionally, the runtime synchronizes with the SimPy simulation via the SignalTable, so that logic outputs directly drive physical actuators.
SCL Export: Straight Into TIA Portal
One of the most frequently requested features in our beta feedback was: "Can I transfer the logic into my TIA Portal?" The answer is now yes.
The SCL generator produces fully compilable Structured Control Language code from the visual model, compatible with TIA Portal V17. Each network is translated into its own REGION block. Contacts become IF/AND/OR expressions, SEQUENCE blocks become CASE statements, function blocks become instance calls with parameter assignment.
The result isn't prototype code that needs manual rework — it's production-ready SCL code with correct VAR_INPUT/VAR_OUTPUT/VAR declarations that you can paste directly into a TIA function block.
Step Debugger: Trace Logic, Find Bugs
The integrated step debugger was the feature that was the most fun to develop — and caused the most headaches. The requirement sounds simple: set breakpoints on individual elements, step through the logic one evaluation at a time, observe signal values live.
The implementation was anything but trivial. The debugger had to be integrated into the SimPy time loop without blocking the simulation tick. The solution: a dedicated debug mode in which the runtime pauses after each evaluation step and sends the current state to the React UI via WebSocket. The UI then shows a visual overlay: active elements glow green, inactive ones are grayed out, and each block displays the current values of its inputs and outputs.
On top of that, there's a watch list for any signals and variables, plus a cycle counter that tracks how many PLC cycles have elapsed since the start. Combined with the existing signal trace (the oscilloscope-style signal recorder from Phase 4), the result is a debugging experience that comes remarkably close to TIA Portal's diagnostic tools.
Templates: Don't Start From Scratch
Six included logic templates cover the most common machine types:
Each template is a complete, runnable logic model that can be simulated immediately. You select the template when creating new machine logic and adapt it to your requirements. This reduces the time from blank canvas to running station program from hours to minutes.
- CNC_BASIC — Clamp, process, release: the three-step cycle for CNC machines
- PRESS_BASIC — Clamping cycle plus press stroke with safety interlock
- ASSEMBLY_STATION — Multi-step assembly sequence with part handover
- CONVEYOR_CONTROL — Motor control with sensor logic for conveyors
- ROBOT_CELL — Pick-and-place sequence with gripper and position control
- EMPTY — Blank template as a starting point for custom logic
The Architecture Behind It
Technically, the Logic Editor is built on a clean separation of concerns:
The entire module is backed by over 200 tests — from individual function blocks through compiler logic to API integration. Backward compatibility is non-negotiable: every extension must leave existing configurations unchanged.
- Python backend (`logic/model.py`) defines the Pydantic data model: networks, elements, connections, variables
- Function blocks (`logic/function_blocks.py`, `logic/custom_blocks.py`) implement the IEC blocks with `evaluate()` methods
- Runtime (`logic/runtime.py`) executes the compiled logic and binds to the SignalTable
- SCL export (`logic/scl_export.py`) generates TIA-compatible code
- React frontend renders FBD as a React Flow canvas and Ladder as a structured rung diagram
- WebSocket API (`api/logic_api.py`) connects frontend and backend for saving, loading, compiling, and debugging
What This Means for Virtual Commissioning
With the Logic Editor, the circle closes in FactoryLine Pro. You can now model a complete production line from planning through simulation to PLC logic in a single tool:
This closed loop doesn't just save time during commissioning — it transforms the entire development process. Control logic is no longer written only once the machine is standing on the shop floor, but in parallel with mechanical engineering, validated through simulation.
- Create the layout in the 2D editor and visualize it in 3D
- Simulate material flow and identify bottlenecks (Mode A)
- Define control logic per station in the Logic Editor
- Export SCL code and import it into TIA Portal
- Bring the PLC program back into the simulation via PLCSIM Advanced (Mode B/C)
- Analyze timing deviations between the physics model and the PLC program in the debugger
Outlook
The Logic Editor has been available since Phase 9 and is actively being developed further. On the roadmap are direct TIA Openness integration for bidirectional code exchange, extended validation rules for safety-relevant logic, and AI-assisted logic generation that automatically derives control optimization suggestions from simulation analysis.
The Logic Editor is accessible via F7 — just select a machine in the layout and get started.