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

---
$schema: https://holocron.so/frontmatter.json
title: Standard Library
description: Built-in IEC 61131-3 functions, timers, counters, and communication function blocks.
icon: lucide:library
---

The **`iec_stdlib`** crate catalogs IEC 61131-3 standard symbols for the tracked **`2003-strict`** profile. Runtime and C lowering implement the cataloged functions and function blocks; communication blocks are recognized but not fully simulated without target hooks.

## Standard function blocks

These FBs have interpreter and C support for common call patterns:

| FB                   | Role             |
| -------------------- | ---------------- |
| `SR`, `RS`           | Bistable latches |
| `R_TRIG`, `F_TRIG`   | Edge detection   |
| `CTU`, `CTD`, `CTUD` | Counters         |
| `TON`, `TOF`, `TP`   | Timers           |

Try `examples/function_blocks.st`, `timers.st`, and related files.

## Communication blocks (target hooks required)

`USEND`, `URCV`, `BSEND`, `BRCV`, `SEND`, and `RCV` are cataloged. Semantic checking emits a warning that each **communication function block requires a target runtime hook**. The CLI **`run`** command does not install hooks; generated C exposes **`_set_comm_hook`** so targets can bridge IEC comm calls to real transports. The runtime also exposes **`run_*_with_communication_hooks`** for library callers.

<Aside>
  <Tip>
    Install a comm hook in generated C to connect standard communication FBs to Modbus, EtherCAT, ROS 2, or GPIO without editing scan code.
  </Tip>
</Aside>

## Standard functions

The catalog registers standard names with IEC clause references. The table below groups families with active evaluator and C backend support. For the full list, inspect **`standard_symbols()`** in `iec_stdlib` or run **`rbcpp compliance`** and read **`pou.functions`** rows.

| Family          | Examples                                                                                                                                                                                        |
| --------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Arithmetic      | `ADD`, `SUB`, `MUL`, `DIV`, `MOD`, `EXPT`, `MOVE`                                                                                                                                               |
| Selection       | `MIN`, `MAX`, `LIMIT`, `SEL`, `MUX`                                                                                                                                                             |
| Comparison      | `GT`, `GE`, `EQ`, `NE`, `LE`, `LT`                                                                                                                                                              |
| Bit / shift     | `SHL`, `SHR`, `ROL`, `ROR`, `AND`, `OR`, `XOR`, `NOT`                                                                                                                                           |
| Math            | `ABS`, `SQRT`, `SIN`, `COS`, `TAN`, `LN`, `LOG`, `EXP`                                                                                                                                          |
| Strings         | `LEN`, `LEFT`, `RIGHT`, `MID`, `CONCAT`, `INSERT`, `DELETE`, `REPLACE`, `FIND`                                                                                                                  |
| Time / date     | `ADD_TIME`, `SUB_TIME`, `MUL_TIME`, `DIV_TIME`, `ADD_TOD_TIME`, `SUB_DT_DT`, `SPLIT_DATE`, `SPLIT_TOD`, `SPLIT_DT`, construction and extraction helpers (IEC Table 30)                          |
| Enumerated data | `SEL`, `MUX`, `EQ`, `NE` with enum-aware checks (IEC Table 31)                                                                                                                                  |
| Conversions     | Dynamic **`SOURCE_TO_TARGET`** pairs for elementary types, plus BCD helpers (`WORD_BCD_TO_UINT`, `UINT_TO_BCD_WORD`, and generic `*_BCD_TO_*` / `*_TO_BCD_*` patterns), `TRUNC`, string parsers |

See `examples/conversions.st` and `examples/strings_dates.st` for conversion and string calls that run today.

<Info>
  For the authoritative list of implemented standard symbols, use **`rbcpp compliance`** and read rows such as `pou.functions` and `pou.function_blocks`.
</Info>

## Related

* [Structured Text](/structured-text): calling conventions and EN/ENO
* [Examples](/examples): runnable `.st` files


---

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