Connect to a Modbus Server
Connect to a Modbus TCP server using Synnax.
Prerequisites
Before you can connect to a Modbus TCP server, you will need to ensure that you have the following:
- A Synnax Core running on your network.
- A Synnax Driver running on your network. This Driver must be connected to the Core and running on the same machine or network as your Modbus server.
- The Synnax Console installed on your local machine.
- A Modbus TCP server running on your network. This server must be reachable by the Driver.
Configuration Parameters Reference
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
name | string | Yes | - | Human-readable server name for identification in Console |
rack | string | Yes | - | 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 | 502 | 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
Connect to Modbus Server
import synnax as sy
from synnax.hardware import modbus
# Initialize Synnax client
client = sy.Synnax()
# Retrieve the embedded rack
rack = client.hardware.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.hardware.devices.create(device)
# Or retrieve by location
device = client.hardware.devices.retrieve(location="192.168.1.100:502")
# Or retrieve by name
device = client.hardware.devices.retrieve(name="My Modbus Server")
print(f"Connected to Modbus server: {device.name}") Disconnect server
import synnax as sy
# Initialize Synnax client
client = sy.Synnax()
# Retrieve the device by name
device = client.hardware.devices.retrieve(
name="My Modbus Server",
ignore_not_found=True
)
if device is not None:
# Delete the server
client.hardware.devices.delete([device.key])
print(f"Disconnected Modbus server: {device.name}")
else:
print("Server not found")