Skip to main content

Ladder logic is great to read on a screen and painful to work with anywhere else. The moment you want to diff it in Git, review it in a pull request, or hand it to an AI assistant, you hit a wall: Siemens TIA Portal will not export a ladder block to text. This workshop shows how to convert ladder logic to SCL reliably, using SimaticML XML as a bridge and Claude as the translator. We take a real function block written in Ladder Diagram (LAD), convert it to Structured Control Language (SCL), and re-import the result back into TIA Portal as a compiled block.

Workshop title slide on how to convert ladder logic to SCL and ST with Claude and TIA Openness
Workshop title slide on how to convert ladder logic to SCL and ST with Claude and TIA Openness

The problem: ladder does not export to SCL

TIA Openness, the automation API for TIA Portal, has a built-in source generator. GenerateSource() will happily write a clean .scl file from a block, let you edit it, and re-import it. The catch is that it only accepts text-based blocks. Ask it for source from an SCL or STL block and it works. Point it at a LAD or FBD block and it refuses, because there is no built-in graph-to-text translator inside Openness.

The problem slide showing TIA Openness exports SCL and STL blocks but blocks LAD to SCL export
The problem slide showing TIA Openness exports SCL and STL blocks but blocks LAD to SCL export

The reason is structural. Ladder is a graph of contacts, coils and wires, not a sequence of statements. There is no one obvious way to flatten that graph into text, so Siemens simply does not do it for you. If you have read our guide on the TIA Portal MCP server, this is the same wall from a different angle: the graphical languages stay locked unless you bridge them to text first.

The bridge: SimaticML XML

There is one format that every block can export to, regardless of language: SimaticML XML. A LAD block, an FBD block, an SCL block, an STL block, all of them serialize to SimaticML. For ladder, that export is a complete graph of the rung: every Part (each contact, coil, edge detector, MOVE, comparator and function-block call), every Wire (how the parts connect, source pin to target pins), and every Access (the symbols, locals, globals and literals, fully qualified).

The SimaticML XML bridge slide used to convert ladder logic to SCL, listing Parts, Wires and Access
The SimaticML XML bridge slide used to convert ladder logic to SCL, listing Parts, Wires and Access

It is verbose but lossless. A human cannot easily read it, but that does not matter, because the whole point is to hand it to an AI that can.

How to convert ladder logic to SCL: the four-step workflow

The end-to-end process is four steps, and a round trip takes about a minute.

The four-step workflow slide for ladder to SCL conversion: export SimaticML, Claude reads it, Claude writes SCL, re-import
The four-step workflow slide for ladder to SCL conversion: export SimaticML, Claude reads it, Claude writes SCL, re-import
  1. Export the LAD block as SimaticML, using TIA Openness.
  2. Claude reads the XML, walking the Parts and Wires network by network, and reconstructs the Boolean logic, edge detectors, timer and counter calls, and function-block invocations.
  3. Claude writes the equivalent SCL, using IF and CASE, typed assignments and the same instance calls. The interface, the static variables and the original network titles are preserved as comments.
  4. Re-import the SCL into TIA Portal, where it compiles as a normal block.

Because each step is scripted through TIA Openness, you can convert ladder logic to SCL in about a minute once the pipeline is set up.

A real example: FB_Robot

To make it concrete, the demo uses FB_Robot, a pneumatic-cell controller originally written in ladder. Exported from TIA Portal, the block becomes more than 1,754 lines of SimaticML spread across ten LAD networks. No PLC programmer wants to read that by hand.

The FB_Robot example slide: a ladder block exported as 1,754 lines of SimaticML for the LAD to SCL conversion
The FB_Robot example slide: a ladder block exported as 1,754 lines of SimaticML for the LAD to SCL conversion

Claude, on the other hand, reads it with ease. In the demo it identifies the four inputs, two outputs and seven statics, the timer and counter instances, and the original network titles, then writes matching SCL.

Walking through the demo

Here is the source block open in TIA Portal version 20: FB1, the FB_Robot function block, with its logic laid out in ladder networks before we convert ladder logic to SCL.

FB_Robot ladder logic open in TIA Portal before the SCL conversion
FB_Robot ladder logic open in TIA Portal before the SCL conversion

To get the XML out, the workshop uses an export and import add-in for TIA Portal. With it, any block can be written out as a SimaticML text file.

The TIA Portal export add-in producing a SimaticML file from the ladder block for SCL conversion
The TIA Portal export add-in producing a SimaticML file from the ladder block for SCL conversion

The result is the SimaticML file itself: an XML structure holding every ladder element we saw in the project. Hard for us to decode, easy for Claude.

The exported SimaticML XML, the bridge format for the ladder to SCL conversion, open in an editor
The exported SimaticML XML, the bridge format for the ladder to SCL conversion, open in an editor

Letting Claude handle the LAD to SCL conversion

With Claude Code running alongside TIA Portal, the first instruction is simply to export the FB_Robot block to XML. Claude runs the export and drops the SimaticML file into the right folder.

Claude Code exporting the FB_Robot block to SimaticML XML to start the ladder to SCL conversion
Claude Code exporting the FB_Robot block to SimaticML XML to start the ladder to SCL conversion

The next instruction is the conversion itself: turn the ladder logic into SCL. Here you can give Claude a free hand or specify a style, naming choices and comments. In the workshop the commands are given one at a time, but the same steps can be wrapped into a pipeline so you only point at the ladder block and Claude exports, converts and re-imports automatically. This is the same idea explored in our TIA Portal and Claude Code step-by-step guide.

Claude Code prompted to convert ladder logic to SCL from the SimaticML XML
Claude Code prompted to convert ladder logic to SCL from the SimaticML XML

Claude translates the XML and saves the result as FB_Robot.scl in the project folder.

Claude saving the converted FB_Robot.scl file after the ladder to SCL conversion
Claude saving the converted FB_Robot.scl file after the ladder to SCL conversion

The converted code is clean SCL, structured as networks. Each original ladder network shows up as a commented section, so you can trace every block of SCL back to the rung it came from.

The converted SCL code with each ladder network preserved as a comment
The converted SCL code with each ladder network preserved as a comment

Re-import, rename and compile

The last step closes the loop. Claude imports the SCL back into the open TIA Portal project. Because the original block still exists, we ask it to rename the function block so the two do not clash. Renaming means changing both the file name and the block name inside the code, and Claude handles both, importing it as FB_Robot_SCL.

The re-imported FB_Robot_SCL block with its variable list and SCL editor in TIA Portal
The re-imported FB_Robot_SCL block with its variable list and SCL editor in TIA Portal

Then the real test: hit Compile. The converted block builds with zero errors.

TIA Portal compiling the SCL block produced by the ladder to SCL conversion with no errors
TIA Portal compiling the SCL block produced by the ladder to SCL conversion with no errors

Why ladder-to-SCL conversion matters

Once your logic lives as SCL text instead of a ladder graph, everything downstream gets easier. You can version it in Git and see real diffs. You can review it in a pull request. And you can hand it to any AI chat agent for refactoring, documentation or extension, because text-based code is what these tools are best at. Working directly with ladder is awkward precisely because of the XML structure underneath it, but once you are in SCL, the friction disappears.

The conversion is not a black box either. Because Claude preserves the interface, the statics and the network titles as comments, the SCL stays readable and reviewable. The goal is to convert ladder logic to SCL without losing the semantics, so you can confirm every decision before it goes anywhere near a live controller, and the compiler is the final check.

Conclusion

Converting Siemens ladder logic to SCL used to be a manual rewrite. With SimaticML as the bridge and Claude as the translator, you can convert ladder logic to SCL in a one-minute round trip that ends in a compiled block. Export the LAD as XML, let the AI reconstruct the logic as SCL, re-import, and compile. From a graphical block to maintainable text, without losing the semantics.

Want more hands-on AI and PLC programming workshops? Subscribe to the ControlByte channel, and check out our courses on PLC programming, Python for automation engineers, and more at controlbyte.tech.

Author

Jacob Biedulski, MSc

Author Jacob Biedulski, MSc

Automation Engineer and PLC Specialist CTO & Co-Founder at ControlByte I help students and professionals master PLC programming and IIoT technologies.

More posts by Jacob Biedulski, MSc