---
title: "Modbus Server"
description: "Run a Modbus client and a Modbus server in the same process over the RAW_ADU backend — the register model, with no UART, RS-485, or TCP wiring."
source: https://docs.alplab.ai/sdk/examples/modbus-server
---

# `modbus-server`

Run a Modbus client and a Modbus server in the same process over the RAW_ADU backend — the register model, with no UART, RS-485, or TCP wiring.

Source: [`examples/connectivity/modbus-server/`](https://github.com/alplabai/alp-sdk/tree/main/examples/connectivity/modbus-server).

## What it does

Brings up one Zephyr Modbus client and one Zephyr Modbus server in a single process and exercises the register model — holding registers and coils — end to end. Because both ends are in-process over RAW_ADU, `native_sim` can build and run it without any physical bus.

:::note[In-tree, not a third-party pin]
Modbus is the in-tree Zephyr subsystem. `libraries: [modbus]` is the ADR 0018 top-level form: the generator reads `metadata/libraries/modbus.yaml` and emits `CONFIG_MODBUS=y`. `prj.conf` keeps only the app-specific backend choice (RAW_ADU).
:::

## Moving to serial

For RTU or ASCII on real hardware, keep the server callbacks in `src/main.c` and replace the RAW_ADU setup with a UART-backed Modbus interface. The board devicetree must provide an enabled node with compatible `zephyr,modbus-serial` — Zephyr's `CONFIG_MODBUS_SERIAL` depends on that node plus a UART driver.

## `board.yaml`

This is the odd one out of the library examples: it targets V2N on the E1M-X EVK, and its core is `m33_sm` rather than `m55_hp`.

```yaml
libraries:
  - name: modbus

som:
  sku: E1M-V2N101

preset: e1m-x-evk

cores:
  m33_sm:
    os: zephyr
    app: ./src
    peripherals: []

diagnostics:
  log_level: info
```

## Expected output

```text
[modbus] RAW_ADU server example starting
[modbus] holding[0]=0x4d42
[modbus] coils[0..7]=0x01
[modbus] done
```

## See also

- [`coap-client-get`](https://docs.alplab.ai/sdk/examples/coap-client-get) — the other in-tree-subsystem library example
- [Examples overview](https://docs.alplab.ai/sdk/examples/overview)
