Consystence
Request a demo
Back to blog
Updated 29 October 2026

Generated, not written: deterministic PLC code from the device model

How deterministic code generation connects equipment definitions to controller programs, screens and history, without replacing the behaviour checks each controller target still needs. Includes dated implementation updates.

Garry Thomas
ArchitectureAutomationEngineering

Update — 29 October 2026. We have corrected the “So where is the AI?” paragraph below in place. It described an AI step, under a name we no longer use, that chose which device types to generate and how many. That is no longer how it works: since 6 October 2026, on request, IO, the Consystence advisory assistant, can queue a code-generation preview of the site model for an engineer to review. The code comes from the deterministic generator, not a language model, and IO never sees or deploys it.

Update — 21 October 2026. We have corrected this post in place. Our 20 July note said the dam-pump-station program on our workshop’s virtual PLCnext had become a generated one; it was still the hand-written program, and we have corrected that note. A generated eCLR C# program first ran there in September 2026, for our coal-preparation demonstration. A later generated build was loaded there on 18 October 2026 and verified running, including after a restart; as loaded, it used one hand-written sequence helper. No generated program has run on PLCnext hardware yet. Lines below also overstated how the targets are held together. No test suite holds the C# blocks to the hand-authored Structured Text they were first ported from: some of their tests trace scenarios from it, but none runs it. And test vectors from the C# blocks have been replayed on a controller for ControlLogix only; per-block replay on PLCnext is planned. The Structured Text library in the 15 July note is no longer frozen: in October some fixes made in the C# blocks were ported to it by hand.

Update — 20 July 2026. The caveat at the end of this post stands: the dam-pump-station program running the virtual PLCnext on our workshop rig is still the hand-written one. Structured Text has also returned to the pipeline’s output as a delivery format — the generated program emitted as IEC 61131-3 ST in PLCopen XML for controllers programmed through the vendor’s engineering tool — alongside the eCLR C# runtime target described below. The generator’s mapping has also grown since publication: eight catalogue types now resolve to six function-block types. The full story is in C#, not Structured Text.

Update — 15 July 2026. The generator no longer targets Structured Text on PLCnext: it now emits the controller program as eCLR C# directly — the same class of artifact our dam-pump-station proving run executed — and the hand-authored CSY_* ST library is frozen as the reference implementation. The determinism below is unchanged: same input, same code, every time. The reasoning is in C#, not Structured Text.

Original engineering account

The implementation and status descriptions below record the work at publication. For current controller support, demonstration scope and beta availability, see the Platform page.

A pump on a dam station gets described more times than anyone admits. Once in the PLC program the integrator typed. Again in the HMI’s tag database. A third time in the alarm list, a fourth in the commissioning spreadsheet, a fifth in the O&M manual nobody opens. Every copy starts identical and every copy drifts — a tag renamed here, a fault code in the controller that never reached the screen. Then a new site is built, and someone re-types all five from scratch.

So we keep one, not five. A device type is defined once, and the platform generates the PLC code from that one model — the same model that renders its faceplate and feeds its historian. Controller code is generated from the model, and each controller target still needs its own behaviour checks. Same input, same code, every time.

One model, one source of truth

Defining a pump as a device type drives everything downstream. A mapping file is the contract: it ties each device type to a function block plus its wiring metadata — hardware I/O, call parameters, and the GDS port declarations the HMI and historian read. Seven of the catalogue’s device types resolve to five function-block types in the generator today: pumps, motorised valves, VFD motors, flow/pressure/level sensors, and PID loops. Generate a site and the platform emits a PLCnext PROGRAM: each device’s function block declared, called in the scan with its I/O wired, outputs mapped back to hardware — plus the GDS port list, so the faceplate and historian bind to the exact tags it exposes. Variable names come from the operator-readable asset number (PP-01 becomes Pp_01), not a synthetic ID, so the generated code reads the way the plant is labelled.

Generated, not guessed

This is the line we will not blur — the same one as advisory by design, where AI explains but never commands. The generation is deterministic template expansion: Scriban filling in .st.sbn templates, not a language model. The output is a pure function of the request, the type mapping and the templates; between two runs of identical input, only a timestamp in a comment header changes. That matters because PLC code has to be reviewable and reproducible, not probabilistic — you can diff it, sign it off, and get the same bytes next time.

So where is the AI? When we wrote this, an AI step assembled the request — it chose which device types, and how many — then called the deterministic generator: it picked the blocks, it did not write them (see the 29 October note for how this works now). The function blocks themselves are hand-authored and human-reviewed in IEC 61131-3: a library of CSY_* blocks, of which CSY_Pump alone is a 323-line state machine with speed ramping, interlocks, condition-monitoring alarms and run-hour tracking. The generator instantiates and wires those blocks, exactly the way an engineer instantiates a Rockwell AOI. The creativity lives in the reviewed library and the device model; the generator is mechanical glue. A static check then runs over the output — resource limits (a program tops out near a thousand GDS variables), naming, tag completeness, leftover placeholders — a structural review, not a compile.

One source, two runtimes

Here is the property the determinism buys. The same request and the same type mapping that produce the PLCnext Structured Text also drive a software simulation of the plant. No ST is parsed; both are generated from the same model and wire the same device blocks — one as Structured Text for the controller, one as the C# the simulator runs natively. The C# blocks are translated from the hand-authored ST and covered by their own test suite, some of it traced from the ST’s scenarios, plus a full dam-pump-station scenario. So the sim is the same model, wired the same way, though it runs the C# blocks rather than the controller’s own code.

What ships, and what is next

To be precise about the line:

  • Shipped: the deterministic generator (Scriban → IEC 61131-3 Structured Text plus GDS port declarations); the hand-authored, reviewed CSY_* function-block library it instantiates; and a C# simulation of those blocks, driven from the same device model.
  • Roadmap: field-hardware sign-off, and the throughput and scale targets only a real controller can settle.

A caveat we owe you. The simulation runs the C# translation of the function blocks — covered by those tests, some traced from the hand-authored Structured Text — not the generated ST program itself, which has not yet run on a virtual or physical PLC. Our headline dam-pump-station proving run, against a virtual PLCnext, executed a separate hand-authored, pure-managed C# program on the controller’s eCLR runtime, not the generated ST. The pipeline is deterministic and shipped; the hardware run is still ahead of us.

Generating from one model reduces manual duplication. Target conformance and deployment checks are still needed to keep the running system aligned.