DEV Community

tia-forge
tia-forge

Posted on

Your agent generated ladder logic. TIA Portal rejected the XML. Here is why.

Ask a model to write ladder logic and it will happily produce something that reads correctly. Ask it to produce SimaticML — the XML TIA Portal actually imports — and the first import attempt usually fails with an error that names a UId you never wrote.

That's not a model problem. SimaticML isn't a document format with a bit of structure; it's a graph dressed as XML. Once you see it that way, generation, validation and rendering all fall into place.

Here's the shape of the problem, the four things that break first, and the pipeline that makes it verifiable without a TIA Portal licence.

The structure, in one block

A minimal LAD network, exported from TIA Portal, looks like this (abridged):

<Document>
  <SW.Blocks.FC ID="0">
    <AttributeList>
      <Name>FC_Motor</Name><Number>1</Number>
      <ProgrammingLanguage>LAD</ProgrammingLanguage>
    </AttributeList>
    <ObjectList>
      <SW.Blocks.CompileUnit ID="1" CompositionName="CompileUnits">
        <AttributeList>
          <NetworkSource>
            <FlgNet>
              <Parts>
                <Access Scope="GlobalVariable">
                  <Symbol><Component Name="Start"/></Symbol>
                </Access>
                <Part Name="Contact" UId="21"/>
                <Part Name="Coil"    UId="22"/>
              </Parts>
              <Wires>
                <Wire UId="31"><Powerrail/><NameCon UId="21" Name="in"/></Wire>
                <Wire UId="32"><NameCon UId="21" Name="out"/><NameCon UId="22" Name="in"/></Wire>
                <Wire UId="33"><NameCon UId="22" Name="out"/><Powerrail/></Wire>
              </Wires>
            </FlgNet>
          </NetworkSource>
        </AttributeList>
      </SW.Blocks.CompileUnit>
    </ObjectList>
  </SW.Blocks.FC>
</Document>
Enter fullscreen mode Exit fullscreen mode

Three levels matter: block (FC/FB/OB + attributes), CompileUnit (one per network), and FlgNet (the graph: Parts are boxes, Wires are edges between pins, not between boxes).

The four things that break first

1. UId is identity, and it must be consistent everywhere. Every Part gets a UId; every wire endpoint references NameCon UId="…" Name="pin". A generator that renumbers parts between passes produces XML that parses fine and imports as garbage — or gets rejected with Part with UId 21 not found. Generate UIds deterministically (walk the IR in a fixed order) and the diffs stay readable too.

2. Wires are pin-to-pin, and the power rail is a node. <Powerrail/> appears as an endpoint exactly like a pin. So a rung is not a list of elements left-to-right; it's a path from the rail through contacts into coils, back to the rail. Any branch is a second path, and the ordering of <Wire> elements matters — depth-first, matching the branch nesting, or you get layout errors that don't point at the actual cause.

3. Branches are OpenCon / CloseCon pairs. Parallel paths are expressed by opening a branch marker before the first wire of the branch and closing it after the last. Unbalanced or nested-out-of-order markers are the most common reason a block renders as spaghetti, or refuses to import at all.

4. A block can mix languages per network. ProgrammingLanguage exists both on the block and inside each CompileUnit. Real projects have blocks where network 1 is LAD and network 7 is SCL. Code that assumes one language per block works on your test file and fails in the wild.

And one that isn't a graph problem: not everything can be ladder. Global DBs, instance DBs and UDTs have no ladder diagram to draw, and FBD / GRAPH / STL are different representations entirely. Tools should reject these explicitly (UNSUPPORTED_DOCUMENT, UNSUPPORTED_LANGUAGE) rather than emit an empty image and let you guess.

The pipeline that actually holds together

LadDoc IR ──validate──► SimaticML ──render──► PNG ──import──► TIA Portal ──simulate──► PASS/FAIL
   (text)                (XML)      (eyeball)                 (project)            (behaviour)
Enter fullscreen mode Exit fullscreen mode

Each arrow is a gate, and each gate catches a different class of mistake:

  • IR → validate. A ladder description in text (series/parallel, contacts, coils, timers) is what a model writes well. Validate it as a document — unknown symbol, duplicate tag, a coil with no driver — before any XML exists. Validation is binary: one issue, no output. You never hand TIA Portal something that can't import.
  • IR → SimaticML must be deterministic. Same input, byte-identical XML. That's what makes review possible: the diff of two generated blocks shows the logic change, not UId churn.
  • XML → PNG before import. Rendering the block server-side — no TIA installed — turns "trust the model" into "look at the picture". You catch the inverted contact, the coil on the wrong side of the rail, the branch that merged into the wrong pin. This is the cheapest review step in the whole chain and almost nobody does it, because they assume rendering needs the engineering tool.
  • Import → simulate. "Compiles" and "works" are different claims. Running the block against a scenario (start pressed, no fault, 3 s later the motor output is on) and getting PASS/FAIL back is the only signal an agent can act on by itself.

Practical limits worth designing around

From the hosted renderer we run, the numbers that shape the design: 4 MiB of XML per request, image side capped at 20,000 px, and 120 requests/minute. A 300-network block will exceed the image limit long before it exceeds anything else — so the API takes a network parameter and renders one network at a time, with scale for legibility. If your tool renders whole blocks only, the big ones will fail on the largest projects, which is exactly where you wanted the help.

The other limit is human: 300 networks of generated ladder is not reviewable. Render one network, show it next to the diff, and let the engineer approve a screen at a time.

Why this is worth doing

The reason to go through SimaticML instead of writing SCL is that ladder is what technicians read at 3 a.m.. SCL is fine for the engineer who wrote it; the person maintaining the machine reads rungs. An AI that can only emit SCL has produced code the plant can't service — and an AI that can produce importable LAD, with the layout rendered for review and the behaviour simulated before download, fits into the workflow that already exists.

That's the whole trick: not a better model, but gates on either side of it.


Disclosure: I work on the tooling below. The design notes are ours; Openness and SimaticML are Siemens'.

LadDoc Cloud — ladder IR → validated, deterministic SimaticML (V19), over MCP. LAD Render Cloud — SimaticML → PNG ladder diagram, no TIA Portal needed. PLC Cloud Sim — run LAD/SCL against a scenario, get PASS/FAIL. 100 free calls each. For the on-premises half — reading and writing real projects through Siemens Openness, with the guard set — TiaLink (commercial).

Top comments (0)