> For the complete documentation index, see [llms.txt](https://docs.enlyze.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.enlyze.com/en/connect/ot-connectivity/supported-industrial-protocols/modbus-tcp.md).

# Modbus TCP

Set up the Modbus TCP protocol for ENLYZE.

This guide walks you through connecting data sources that communicate via Modbus TCP. Modbus is an open, vendor-neutral protocol supported by many devices on the machine network, such as energy meters, temperature controllers, frequency inverters, sensors, and PLCs. ENLYZE connects these devices over Ethernet via Modbus TCP (default port `502`). In the ENLYZE Platform, the connector is called **Modbus TCP**.

{% hint style="info" %}
**Add variables manually instead of Variable Discovery**

Modbus addresses data through numbered registers rather than symbolic tags, so [Variable Discovery](https://docs.enlyze.com/en/connect/ot-connectivity.md#variable-discovery) is not possible. Instead, you add the variables directly in the ENLYZE Platform, either manually or with the help of an AI assistant via the [ENLYZE MCP](https://docs.enlyze.com/en/integrations/mcp.md). Both ways start from the device's register map (Modbus mapping). See [Add variables](#add-variables) for details.
{% endhint %}

## Supported devices

You can connect any device that works as a Modbus TCP server (slave), including:

* energy meters and power analyzers, e.g. from Janitza
* temperature controllers, frequency inverters, and sensors with an Ethernet interface
* PLCs with a Modbus TCP server function, e.g. [Siemens](https://docs.enlyze.com/en/connect/ot-connectivity/supported-controller-brands/siemens.md) LOGO! 8

You connect devices that only speak Modbus RTU (serial, RS-485) through a Modbus gateway (TCP to RTU). In the ENLYZE Platform, you then create the gateway as a Modbus TCP data source and address the individual devices through their [unit ID](#unit-id). If you want to connect an RTU device directly to the serial interface of the Edge Device, contact us at <support@enlyze.com>.

## Before you start

Have the following ready:

* the IP address of the device or of the Modbus gateway
* the device's register map, usually found in the manual or provided by the machine builder. For each value it lists the register type, the address, the data type and, for values spanning several registers, the word order (see [Addresses and data types](#addresses-and-data-types))
* the device's unit ID, if the register map does not state it

{% stepper %}
{% step %}

#### Connect the data source to the network

If not done yet, first establish a network connection between the data source and the respective Edge Device. You can find the possible networking scenarios [here](https://docs.enlyze.com/en/connect/integration-scenarios.md). The connector opens a TCP connection to the device on port `502`. If there is a firewall, make sure this port is open between the Edge Device and the device.

Use the [network tools](https://docs.enlyze.com/en/connect/edge-device/enlyze-edge/network-tools.md) to ping the device and check that it is reachable from the Edge Device.
{% endstep %}

{% step %}

#### Create the data source

Open the [ENLYZE Manufacturing Data Platform](https://app.enlyze.com/platform), select the machine you want to add this data source to, and click **+ Data source**.

Enter a descriptive name and add the manufacturer and model of the device under **Device details**, e.g. **Janitza** and `UMG 604`.
{% endstep %}

{% step %}

#### Add connection details

Under **Connection details**, select the **Edge device**. You can find its name on the sticker on the device (format `adjective-scientist`). Select **Modbus TCP** as the **Connector** and fill in the connector details:

* **IP address**: the IPv4 address of the device or of the Modbus gateway
* **Port**: the default is `502`. Only change it if the device answers on a different port.
* **Ephemeral connections**: when enabled (the default), the Edge Device opens a new connection to the device for every readout. When disabled, it keeps one connection open permanently. Keep the default unless we recommend otherwise.

You don't enter the unit ID here. You set it for each variable instead.

Click **Save** and confirm with **Save and try to connect**. The Edge Device connects to the device.

{% hint style="info" %}
If you are still missing some details, you can **save the data source as a draft** first. You add the connection details later via **Add connection details** on the data source page.
{% endhint %}
{% endstep %}

{% step %}

#### Add variables

Open the **Variables** tab on the data source page. As long as the data source has no variables, it offers two ways: **Add manually** and **Add via MCP Server**.

{% tabs %}
{% tab title="A: Manually" %}
**You need** the device's register map.

1. Click **Add manually**. The **Add variables** dialog opens.
2. Fill in one row per variable. [Addresses and data types](#addresses-and-data-types) explains what goes into each column:
   * **Register type**: **Coil**, **Discrete input**, **Input register**, or **Holding register**
   * **Slave ID**: the device's unit ID (`0` to `255`)
   * **Address**: the register address, counted from `0` (`0` to `65535`)
   * **Data type**: e.g. `UINT16` or `FLOAT32BE`. For `STRING[n]`, also enter the **String length** in bytes.
   * **Display name**, **Unit**, and **Scaling factor**: how the value is shown in the ENLYZE Platform. Unit and scaling factor are only available for numeric values.
   * **State**: **Evaluating** (recommended) records the variable in the Exploration state, so you can check the values before you activate it. **Active** records it right away and makes it available to all services. An active variable requires a display name.
3. Use **Add row** to add more variables. You can add up to 100 rows at a time.
4. Click **Add variables**.

If a variable already exists, it is not created twice. The dialog tells you in the affected row.
{% endtab %}

{% tab title="B: ENLYZE MCP" %}
**You need** an AI assistant connected to the ENLYZE MCP (see [Set up ENLYZE MCP](https://docs.enlyze.com/en/integrations/mcp/set-up-mcp-server.md)) and information about the device: the data sheet or register map as a PDF, CSV, or link, or alternatively a photo of the type plate.

1. Click **Add via MCP Server**.
2. Click **Copy prompt**. The prompt already contains the site, machine, and data source.
3. Paste the prompt into your AI assistant and share the device information.
4. The assistant reads the register map, converts the addresses, and asks you whenever something is not clearly documented, such as word order, scaling, or unit ID.
5. Review the proposed variable table and approve it. Only then does the assistant create the variables in the ENLYZE Platform.
   {% endtab %}
   {% endtabs %}
   {% endstep %}

{% step %}

#### Check the values and activate the variables

Variables in the **Evaluating** state are already recorded but not yet available to all services. Compare the first values with a known value, such as the reading on the device display. If they are clearly off, see [Check the values](#check-the-values). Once the values are right, [contextualize and activate](https://docs.enlyze.com/en/variable-mapping/contextualisation.md) the variables. **See all available variables** in the **Variables** tab takes you straight there.

{% hint style="warning" %}
The number of variables that can be recorded per data source is limited. If you see the message **Variable limit reached**, contact us at <support@enlyze.com>.
{% endhint %}
{% endstep %}
{% endstepper %}

## Addresses and data types

Register maps are structured differently from one manufacturer to the next. The following sections show how to transfer the details from the manual into the fields of the ENLYZE Platform.

### Register types

| Register type in the ENLYZE Platform | Classic notation | Content                                | Data types        |
| ------------------------------------ | ---------------- | -------------------------------------- | ----------------- |
| **Coil**                             | `0xxxx`          | single bit, readable and writable      | `BOOL`            |
| **Discrete input**                   | `1xxxx`          | single bit, read-only                  | `BOOL`            |
| **Input register**                   | `3xxxx`          | 16-bit register, read-only             | all except `BOOL` |
| **Holding register**                 | `4xxxx`          | 16-bit register, readable and writable | all except `BOOL` |

You can't read a single bit inside an input or holding register directly as `BOOL`. In that case, add the register as `UINT16` and contact us if you want to evaluate the bit separately.

### Address

The ENLYZE Platform expects the address that is actually sent over the network. It is counted from `0` and contains no digit for the register type. Many manuals use the classic notation instead, which is counted from `1` and where the first digit indicates the register type. This is how you convert it:

| Value in the manual | Register type    | Address |
| ------------------- | ---------------- | ------- |
| `40001`             | Holding register | `0`     |
| `40101`             | Holding register | `100`   |
| `30001`             | Input register   | `0`     |
| `10005`             | Discrete input   | `4`     |
| `00010`             | Coil             | `9`     |

If the manual already gives the address without a type digit (e.g. "register 100" or `0x0064`), it is usually counted from `0` already and you can use it as is. Convert hexadecimal values to decimal: `0x0064` is `100`.

### Data types

A Modbus register holds 16 bits. Larger values occupy several consecutive registers. The address is always that of the first register.

| Data type                                    | Registers                            | Data type in the ENLYZE Platform |
| -------------------------------------------- | ------------------------------------ | -------------------------------- |
| `BOOL`                                       | 1 bit (coil and discrete input only) | Boolean                          |
| `INT16`, `UINT16`                            | 1                                    | Integer                          |
| `INT32BE`, `INT32LE`, `UINT32BE`, `UINT32LE` | 2                                    | Integer                          |
| `INT64BE`, `INT64LE`, `UINT64BE`, `UINT64LE` | 4                                    | Integer                          |
| `FLOAT32BE`, `FLOAT32LE`                     | 2                                    | Float                            |
| `FLOAT64BE`, `FLOAT64LE`                     | 4                                    | Float                            |
| `STRING[n]`                                  | n/2                                  | String                           |

`INT` stands for signed integers, `UINT` for unsigned ones. For `STRING[n]`, `n` is the length in bytes and must be an even number.

### Word order

For values spanning several registers, the suffix `BE` or `LE` defines the order in which the registers are combined:

* **`BE`**: the first register holds the most significant part of the value. Manuals call this "big endian", "high word first", or `ABCD`. This is the most common order.
* **`LE`**: the first register holds the least significant part of the value. Manuals call this "word swap", "low word first", or `CDAB`.

The bytes within a register are always read in the Modbus standard order. Devices with swapped bytes (`BADC`, `DCBA`) are not supported.

### Unit ID

The unit ID (**Slave ID** in the ENLYZE Platform) defines which device behind an IP address is addressed.

* **Device directly on the network**: many devices ignore the unit ID or expect a fixed value, usually `1` or `255`. The manual tells you the right value.
* **Device behind a Modbus gateway**: the unit ID is the bus address set on the RTU device. This lets you connect several devices through one gateway and one data source.

### Scaling factor

Many devices transmit measured values as integers with a fixed factor, e.g. `2305` for 230.5 V. You find the factor in the register map. Enter it as the **Scaling factor**, `0.1` in this example. The scaling factor must not be `0`.

### Check the values

After adding the variables, check the first values against a known value. Typical deviations and their causes:

* **Implausibly large or tiny values** (e.g. `1.2E-38` instead of `230.5`): the word order is wrong. Switch between `BE` and `LE`.
* **Values belong to a neighboring measurement**: the address is off by one. Check the conversion from the classic notation.
* **Values off by a factor of 10, 100, or 1000**: the scaling factor is missing or wrong.
* **No values**: register type, address, or unit ID don't match the device. Only add addresses the device actually provides. Each variable is read with its own request, and registers that can't be read slow down the readout of the remaining variables.

If you have any questions, feel free to contact us at <support@enlyze.com>.
