> Agent-readable docs index: /llms.txt. Download /docs.zip to grep all markdown files locally.

---
$schema: https://holocron.so/frontmatter.json
title: Native LD and FBD
description: Textual Ladder Diagram and Function Block Diagram syntax in the IEC 61131-3 compiler.
icon: lucide:layout-grid
---

RoboC++ accepts **native textual Ladder Diagram** and **Function Block Diagram** bodies in addition to [PLCopen](/plcopen) graphical exchange. Use **`.ld`** and **`.fbd`** files, or embed **`LADDER`** / **`FBD`** blocks inside a **`PROGRAM`** in any textual project.

## Ladder Diagram (`LADDER` / `RUNG`)

A program body can be written as labeled rungs with contacts and coils:

```text
PROGRAM NativeLadderDemo
VAR
    Start : BOOL := TRUE;
    Stop : BOOL := FALSE;
    Motor : BOOL := FALSE;
    Latched : BOOL := FALSE;
END_VAR

LADDER
RUNG MotorRun:
    CONTACT Start;
    CONTACT_NOT Stop;
    COIL Motor;
END_RUNG;

RUNG Latch:
    CONTACT Start;
    SET Latched;
END_RUNG;
END_LADDER
END_PROGRAM
```

Supported rung elements include **`CONTACT`**, **`CONTACT_NOT`**, **`COIL`**, **`SET`**, and **`RESET`**. Rungs use **`RUNG`** or **`NETWORK`** labels and close with **`END_RUNG`** or **`END_NETWORK`**.

```bash
cargo run -p rbcpp_cli -- check examples/native_ladder.ld
cargo run -p rbcpp_cli -- run examples/native_ladder.ld --cycles 2
```

Native textual LD lowers to normalized IR and runs through the same interpreter and generated-C paths as PLCopen LD lowering.

## Function Block Diagram (`FBD` / `NETWORK`)

FBD bodies use ordered **`OUT`** assignments with expression or call right-hand sides:

```text
PROGRAM NativeFbdDemo
VAR
    A : INT := 2;
    B : INT := 3;
    C : INT := 0;
    Ready : BOOL := FALSE;
END_VAR

FBD
NETWORK Sum:
    OUT C := ADD(A, B);
    OUT Ready := C >= 5;
END_NETWORK;
END_FBD
END_PROGRAM
```

Networks use **`NETWORK`** labels and close with **`END_NETWORK`**.

```bash
cargo run -p rbcpp_cli -- check examples/native_fbd.fbd
cargo run -p rbcpp_cli -- run examples/native_fbd.fbd --cycles 2
```

## SFC transition bodies

Textual SFC transitions can use native LD or FBD bodies instead of ST expressions or IL accumulators:

* **`LADDER` … `END_LADDER`** inside a transition
* **`FBD` … `END_FBD`** with **`OUT`** conditions

See [IL and SFC](/il-and-sfc) for ST and IL transition forms.

## PLCopen vs native

| Path                          | When to use                                        |
| ----------------------------- | -------------------------------------------------- |
| Native **`.ld`** / **`.fbd`** | Hand-written rungs and networks in text            |
| [PLCopen XML](/plcopen)       | Editor export, graphical topology, vendor metadata |

Both paths lower to the same IR and share interpreter/generated-C parity tests.

## Related

* [Examples](/examples): `native_ladder.ld`, `native_fbd.fbd`
* [Language support](/language-support): format overview
* [Compliance](/compliance): `language.ld.native_textual`, `language.fbd.native_textual`


---

*Powered by [holocron.so](https://holocron.so)*
