Explainer
Why move PC-based Python control to an IPC with a PLC runtime
Short answer
Move a machine from Python control to an IPC with a PLC runtime when it needs a guaranteed reaction faster than roughly 10 ms, synchronized motion, or a controls layer others can maintain: the runtime then owns outputs and axes, and Python stays as a client over ADS, OPC UA or shared memory. Count the field I/O, the runtime licence and the commissioning hours before committing.
On this page
- When does a Python loop stop being good enough for machine control?
- What reaction time do the REST and PLC-runtime designs actually give?
- What changes when the PLC runtime owns the outputs?
- Which interface should Python use: ADS, OPC UA or shared memory?
- Which industrial PC can host a PLC runtime?
- What does the switch add besides the IPC itself?
- Should you switch, stay, or move machine by machine?
- Questions asked
Yes — and the reason is timing, not fashion. A Python program steering I/O over REST delivers an average response time; a PLC runtime on an industrial PC delivers a worst case you can print in a machine specification. The move pays off when the machine needs that guarantee, coordinated motion, or a controls layer other engineers can maintain — and it does not retire your Python code, because the runtime takes the outputs while Python stays as a client over ADS, OPC UA or shared memory. Before committing, count everything that surrounds the IPC: field I/O, the runtime licence, drives and commissioning hours. Below is the boundary: when to switch, what the runtime owns, how Python talks to it, and what stays on the PC.
When does a Python loop stop being good enough for machine control? #
A Python loop stops being good enough when the machine needs a guaranteed reaction faster than roughly 10 ms, jitter of a millisecond or less, or more than one synchronized axis, because a general-purpose operating system delivers average timing, never a worst case you can put in a specification. Windows and standard Linux may delay any thread by milliseconds, and no API call lets you buy a worst case instead of an average. Garbage collection, page faults, driver interrupts and an antivirus scan all land on top of your loop, and the REST path stacks more on that: HTTP processing at both ends plus the device's own update period. None of this matters for a tank level or a conveyor start; all of it matters when a following error must be caught within a cycle or two.
Motion is the sharpest boundary. Trajectory planning and interpolated moves need a task that runs every cycle without fail and feedback clocks that agree with each other — EtherCAT's distributed clocks keep device clocks aligned to well under a microsecond, against the milliseconds of jitter a desktop OS hands out. That difference is architectural, not a matter of tighter Python. Note what does not fix it: moving the same Python loop onto industrial hardware changes the reliability of the box, not the determinism of the loop. The guarantee comes from the runtime, not the chassis.
What reaction time do the REST and PLC-runtime designs actually give? #
In the worked example below the REST design reacts in 130 ms and the PLC-runtime design in 2 ms, a ratio of sixty-five to one, and the gap is fixed by the transport hops and the task cycle rather than by how well either program is written. Take a hypothetical machine — the inputs are example assumptions, not measurements. Assume the Python control loop polls every 100 ms, one REST request-response between the PC and the I/O device takes 20 ms, and the device updates its outputs 10 ms after a valid request. A correction can then wait out a full loop period before it even starts:
Worst case = loop period + transport + device update = 100 ms + 20 ms + 10 ms = 130 ms
In the target design the same correction runs in the runtime's motion task, assumed at a 1 ms cycle, over a fieldbus with a 1 ms cycle:
Worst case = task cycle + bus cycle = 1 ms + 1 ms = 2 ms
The arithmetic is robust to the assumptions: halve the Python loop to 50 ms and the REST path still lands at 80 ms, forty times the runtime path, and the jitter comparison is worse still, because the REST path inherits the desktop OS's millisecond-scale scheduling jitter plus the network stack while the runtime path is clocked by the synchronized fieldbus. An engineer can defend either number in a design review — which is the difference between a specified architecture and a hopeful one.
What changes when the PLC runtime owns the outputs? #
The PLC runtime takes ownership of every output, axis and interlock, and your Python code becomes a client that requests moves and reads results, so no output on the machine ever has two programs able to drive it. Draw both architectures before touching code. Today: a Python application reaching the I/O device over REST, with separate C# wrappers reaching other hardware through their device APIs. Target: a Python or .NET client reaching runtime variables over ADS or OPC UA, with the runtime's cyclic task driving I/O and drives over the fieldbus. Windows-only device APIs — a camera SDK, a vendor DLL — stay on the PC side of that line; the runtime neither needs nor should host them.
The rule that keeps the drawing clean: every output and every axis has exactly one writer. If Python still switches an actuator over REST while the runtime commands the same motion, you have built a race, not an architecture. Assign each command and status value an owner, and resolve every unassigned interface before choosing protocols.
The boundary also runs the other way: the runtime can trigger Python for non-cyclic work such as image processing or a database write, the pattern covered in running Python scripts from a soft PLC runtime on Linux, while the outputs stay under runtime control. One thing never moves into either program: the emergency stop and the remaining safety functions stay in certified safety hardware that removes power independently of both the runtime and your Python code.
Which interface should Python use: ADS, OPC UA or shared memory? #
Use ADS when the runtime is TwinCAT, OPC UA when client and controller come from different vendors, and shared memory when both processes sit on the same IPC and you want the fastest same-box exchange. ADS is TwinCAT's native client interface: the vendor's .NET API implements the Automation Device Specification for .NET Framework languages, and pyads wraps the C API the vendor supplies, so Python gets the same reads, writes and change notifications without polling. An ADS client addresses its target by the runtime's NetId and port, and the same mechanism reaches a remote runtime, as shown when listing EtherCAT master NetIds on a remote runtime over ADS.
OPC UA is the cross-vendor answer: TwinCAT and CODESYS runtimes can both serve it, and any language with an OPC UA stack can subscribe to variable changes. Keep it for plant-level, historian and HMI traffic, where update rates far below any control cycle are acceptable, and off the cyclic control path. Settle early what the licence includes, because what a SCADA runtime licence covers beyond running the project is not always every server role.
Shared memory is the same-box route on a CODESYS controller: the vendor's product data sheet gives its purpose as exchanging data within a target system when no direct communication is possible, for example with an external process, and the vendor's example project shows a controller writing a structure that another process reads. Your Python side maps that block, and the handshake is yours to own — one writer per field, plus a sequence counter so a half-written structure is never consumed.
Which industrial PC can host a PLC runtime? #
Only industrial PCs on the runtime vendor's compatibility list qualify, because the list ties named processor generations, operating system builds and BIOS settings to the runtime version, and an unlisted box is a commissioning risk you discover on site. The installer enforces part of that list itself and refuses an operating system it was not built for, the failure mode covered in when a PLC runtime installer fails on the controller OS. The same validated-list principle explains why an S7-1500 Software Controller runs on some IPCs and not others: it is how every software controller is supported, not a quirk of one vendor.
Size the machine for two workloads. The real-time task wants cores of its own — a common setup reserves a core for the runtime and leaves the rest for Windows and your Python client — and the PC side wants the expansion its devices need, so check slots before settling on a fanless unit that has none. When the list check passes, specify the cabinet computer: an industrial mini PC when everything hangs off the fieldbus and USB, or a slotted industrial PC when a capture card is involved.
What does the switch add besides the IPC itself? #
Budget for four additions beyond the IPC itself: field I/O for every point you already count, the runtime licence where the hardware does not include it, drives and motion components, and the commissioning hours to write and validate the structured text. Count the I/O first. A hypothetical cell with 24 digital inputs, 16 digital outputs and 4 analog inputs needs, at an assumed 8 channels per slice, 3 + 2 + 1 = 6 slices, plus the bus coupler and end plate that make them a node. The REST device hid that count inside one box; the new design puts it on the drawing line by line, which is exactly why it gets counted, not estimated.
Add the runtime licence as its own line. On the vendor's own IPCs it is typically bundled with the hardware; on third-party hardware it is purchased separately — a difference big enough to steer the hardware choice on its own. Then the motion hardware: when an axis moves from an integrated smart servo with its own Ethernet API to a servo drive on the fieldbus, compare feedback, motion function blocks and cabling, because the drive now works inside the runtime's cycle discipline. Finally the hours: the structured text you move into the runtime has to be written, simulated and validated against the machine's own acceptance limits, and a first commissioning runs longer than the Python version would have. That learning curve is the largest item in the switch, and it is paid once.
Should you switch, stay, or move machine by machine? #
Switch when the machine needs a guaranteed reaction under 10 ms, two or more axes that must interpolate, or a controls team other than you to maintain it; stay with Python and REST when the slowest acceptable reaction is 100 ms or more. Beyond that first cut, switch when any one of these is true:
- Registration, reject gates or following-error response put the machine at that timing limit or tighter.
- Axes must interpolate or stay synchronized, which no desktop loop can clock.
- Controls engineers will maintain the machine, and structured text is the language they are paid to read.
- The customer's specification asks for PLC-standard behavior and documentation.
Stay when the machine lives at the slow end of that scale: one axis at human speeds, reactions where a tenth of a second is fine, and code only you will ever open. And take the middle path when neither is clear: keep shipping the REST design, put the engineering environment on a development PC, prove the client interface and one structured-text program against real hardware, and port the next machine rather than the current one.
Questions asked
Can I keep my REST I/O device after the switch?
Yes, as long as nothing fast depends on it. Leave slow signals such as tank levels and temperatures on the REST device with Python still serving them, and move everything in the control path to runtime-owned I/O. Then write the owner beside every point on the drawing, because a point with two writers is the one that fails during commissioning.
How do I try the architecture before buying hardware?
Put the engineering environment on your development PC and run the runtime there in its time-limited demo mode to prove the client interface and a first structured-text program against real I/O. A demo or a clean compile licenses nothing: before the machine ships, verify the active runtime licence on the deployed target itself, or continuous operation is not promised to anyone.
Can the IPC still run ordinary Windows software beside the runtime?
Yes, that is half the point. The visualization, your Python client, a camera SDK and office-style tools all run beside the runtime on the cores the real-time task does not own. What you give up is the freedom to let anything consume the machine: antivirus scans and uncontrolled updates are the classic source of runtime overruns, so freeze and test the exact PC workload you ship.
How hard is structured text for a Python programmer?
Easier than you fear and slower than you hope. Assignments, branches, loops and functions translate directly; the new habits are scan-cycle thinking, strictly typed variables and motion function blocks, and those only settle in on a real machine. Plan the first commissioning as a learning project with the vendor's example projects open beside your own.
Does EtherCAT mean replacing every device on the machine?
No. EtherCAT covers only the I/O and drives you buy into it. Existing serial, CANopen or Modbus devices keep working through their own paths, either an adapter on the PC side for slow data or a corresponding master added to the runtime. Replace a device only when its role in the control path demands the cycle, not because the protocol is older.