# Connect to a Modbus server

> Connect to a Modbus TCP server using Synnax.

The Synnax Driver connects to [Modbus TCP/IP](https://modbus.org/) servers such as PLCs, variable-frequency drives, power meters, and industrial I/O modules.

> Modbus RTU and Modbus ASCII (serial) are not supported.

## Prerequisites

Before you can connect to a Modbus TCP server, you will need to ensure that you have the following:

1. A [Synnax Core](https://docs.synnaxlabs.com/reference/core/quick-start) running on your network.
2. A [Synnax Driver](https://docs.synnaxlabs.com/reference/driver/get-started) running on your network. This Driver must be connected to the Core and running on the same machine or network as your Modbus server.
3. The [Synnax Console](https://docs.synnaxlabs.com/reference/console/get-started) installed on your local machine.
4. A Modbus TCP server running on your network. This server must be reachable by the Driver.

## Supported operating systems

| Platform           | Status          |
| ------------------ | --------------- |
| Windows            | ✓ Supported     |
| Linux              | ✓ Supported     |
| NI Linux Real-Time | ✗ Not Supported |
| macOS              | ✓ Supported     |
| Docker             | ✓ Supported     |

> When running in a Docker container, ensure [the container has network access](https://docs.docker.com/get-started/docker-concepts/running-containers/publishing-ports/) to the Modbus server.

## Configuration parameters reference

| Parameter    | Type    | Required | Default | Description                                                                                  |
| ------------ | ------- | -------- | ------- | -------------------------------------------------------------------------------------------- |
| `name`       | string  | Yes      | -       | Human-readable server name for identification in Console                                     |
| `rack`       | integer | No       | -       | Synnax Driver (rack) key that will connect to the Modbus server                              |
| `host`       | string  | Yes      | -       | IP address or hostname of the Modbus server (e.g., `192.168.1.100` or `localhost`)           |
| `port`       | integer | Yes      | -       | TCP port number for the Modbus server (standard Modbus port is 502)                          |
| `swap_bytes` | boolean | No       | `false` | Swap byte order within 16-bit words for endianness handling (applies to register types only) |
| `swap_words` | boolean | No       | `false` | Swap word order for 32-bit and 64-bit values (applies to multi-register data types only)     |

## How-to

**Console**

[](https://synnax.nyc3.cdn.digitaloceanspaces.com/docs/device-drivers/modbus/connect-server/modbus-connect-dark.mp4#t=0.001)

**Python**

Connect to Modbus server

```python
import synnax as sy
from synnax import modbus

# Initialize Synnax client
client = sy.Synnax()

# Retrieve the embedded rack
rack = client.racks.retrieve_embedded_rack()

# Create the Modbus device
device = modbus.Device(
    host="192.168.1.100",
    port=502,
    name="My Modbus Server",
    location="192.168.1.100:502",
    rack=rack.key,
    swap_bytes=False,
    swap_words=False,
)

# Create the device in Synnax
device = client.devices.create(device)

# Or retrieve by location
device = client.devices.retrieve(location="192.168.1.100:502")

# Or retrieve by name
device = client.devices.retrieve(name="My Modbus Server")

print(f"Connected to Modbus server: {device.name}")
```

Disconnect server

```python
import synnax as sy

# Initialize Synnax client
client = sy.Synnax()

# Retrieve the device by name
device = client.devices.retrieve(
    name="My Modbus Server",
    ignore_not_found=True
)

if device is not None:
    # Delete the server
    client.devices.delete([device.key])
    print(f"Disconnected Modbus server: {device.name}")
else:
    print("Server not found")
```
