Introduction
Industrial automation is built on protocols like Modbus/TCP, connecting PLCs, RTUs, and sensors across factories and utilities. But managing these systems manually — writing ladder logic, scripting Python for data collection, configuring alarms — is time-consuming and error-prone. Enter ASI Biont, an AI agent that can interface directly with Modbus/TCP devices through natural language commands. No more digging through manuals or writing custom code for every controller. In this guide, I'll show you exactly how to connect a Modbus/TCP PLC or RTU to ASI Biont, with real code examples, wiring considerations, and practical automation scenarios. Whether you're monitoring a water treatment plant's pressure readings or controlling conveyor belts in a warehouse, this integration lets you treat your industrial equipment like a conversational partner.
Why Connect a Modbus/TCP Device to an AI Agent?
Modbus/TCP is ubiquitous in industrial control systems — it's supported by over 90% of PLCs and RTUs from manufacturers like Siemens, Allen-Bradley, Schneider Electric, and WAGO. Traditional integration requires a dedicated SCADA system or custom Python scripts that poll registers and handle exceptions manually. With ASI Biont, you simply tell the AI what you need: "Read holding register 40001 every 10 seconds and alert me if it exceeds 100°C." The AI writes the code, establishes the connection, and executes the monitoring loop — all within seconds. This reduces setup time from hours to minutes and makes industrial data accessible to operators without deep programming expertise.
Connection Method: Modbus/TCP via pymodbus
ASI Biont supports Modbus/TCP through two mechanisms:
- industrial_command tool — For direct, stateless operations like reading registers or writing coils. You issue a command in the chat, and ASI Biont translates it into a pymodbus request.
- execute_python — For complex, stateful automations (e.g., logging data to a database, conditional logic, or multi-step workflows). The AI writes a Python script using the
pymodbuslibrary and runs it in a sandbox environment.
Both methods connect to your PLC or RTU via its IP address and standard Modbus TCP port (usually 502). No additional hardware bridges are required — just network connectivity between your ASI Biont instance (running on Railway) and the device.
Real-World Use Case: Monitoring and Controlling a Water Pump Station
Let's walk through a concrete scenario: You have a Schneider Electric M221 PLC connected to a water pump station. The PLC exposes:
| Register Type | Address | Description |
|---|---|---|
| Holding Register | 40001 | Pump pressure (PSI) |
| Holding Register | 40002 | Flow rate (L/min) |
| Coil | 00001 | Pump on/off control |
| Coil | 00002 | Alarm reset |
Goal: Monitor pressure every 5 seconds, log to a CSV, automatically turn off the pump if pressure exceeds 80 PSI, and send a Telegram alert.
Step 1: Test Basic Connectivity via Chat
First, verify that ASI Biont can reach your PLC. In the chat, type:
"Connect to Modbus/TCP device at 192.168.1.100:502. Read holding register 40001 and coil 00001."
ASI Biont responds with:
Using industrial_command:
- Read holding register 40001: result = 45.2 PSI
- Read coil 00001: result = True (pump is ON)
This confirms the PLC is reachable and responding correctly.
Step 2: Set Up Continuous Monitoring with Alerts
Now, describe the full automation:
"Write a Python script that connects to the Modbus/TCP device at 192.168.1.100:502. Every 5 seconds, read holding register 40001 (pressure). If pressure > 80 PSI, write coil 00001 to False to turn off the pump, write coil 00002 to True to reset alarm, and send a Telegram message to chat ID @mychannel: 'Pump shutdown due to overpressure: {value} PSI'. Log all readings to a CSV file named pump_log.csv. Run continuously for 1 hour."
ASI Biont generates the following script and executes it:
import asyncio
from pymodbus.client import AsyncModbusTcpClient
import csv
from datetime import datetime
import os
TELEGRAM_BOT_TOKEN = os.environ.get('TELEGRAM_BOT_TOKEN')
TELEGRAM_CHAT_ID = '@mychannel'
PLC_IP = '192.168.1.100'
PLC_PORT = 502
PRESSURE_REGISTER = 40001
PUMP_COIL = 1 # coil 00001
ALARM_RESET_COIL = 2 # coil 00002
PRESSURE_THRESHOLD = 80.0
CSV_FILE = 'pump_log.csv'
async def send_telegram(message: str):
import aiohttp
url = f'https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/sendMessage'
async with aiohttp.ClientSession() as session:
await session.post(url, json={'chat_id': TELEGRAM_CHAT_ID, 'text': message})
async def main():
client = AsyncModbusTcpClient(PLC_IP, port=PLC_PORT)
await client.connect()
with open(CSV_FILE, 'a', newline='') as f:
writer = csv.writer(f)
if f.tell() == 0:
writer.writerow(['timestamp', 'pressure_psi', 'pump_state', 'action'])
start_time = datetime.now()
end_time = start_time.replace(hour=start_time.hour + 1)
while datetime.now() < end_time:
# Read pressure
result = await client.read_holding_registers(PRESSURE_REGISTER - 40001, count=1, slave=1)
pressure = result.registers[0] / 10.0 # assuming 1 decimal place
# Read pump state
coil_result = await client.read_coils(PUMP_COIL - 1, count=1, slave=1)
pump_on = coil_result.bits[0]
action = ''
if pressure > PRESSURE_THRESHOLD and pump_on:
# Turn off pump
await client.write_coil(PUMP_COIL - 1, False, slave=1)
await client.write_coil(ALARM_RESET_COIL - 1, True, slave=1)
action = 'Pump turned OFF, alarm reset'
await send_telegram(f'Pump shutdown due to overpressure: {pressure} PSI')
# Log to CSV
with open(CSV_FILE, 'a', newline='') as f:
writer = csv.writer(f)
writer.writerow([datetime.now().isoformat(), pressure, pump_on, action])
await asyncio.sleep(5)
await client.close()
asyncio.run(main())
This script runs in the ASI Biont sandbox for the specified duration, handling all communication, logic, and alerting automatically.
Step 3: Manual Override via Chat
While the script runs, you can still intervene. Type:
"Write coil 00001 to True to restart the pump."
ASI Biont uses industrial_command to immediately write the coil, overriding the automation if needed.
Advanced Scenario: Multi-Register Data Logging with Trend Analysis
For a more complex setup, say you have an RTU monitoring three temperature zones (registers 40010, 40011, 40012) and want daily summary reports:
"Read registers 40010, 40011, 40012 every minute. Calculate hourly average for each. If any hourly average exceeds 75°C, generate a PDF report and email it to ops@factory.com. Store all data in a PostgreSQL database."
ASI Biont writes a script using pymodbus, psycopg2, matplotlib (for charts), and fpdf2 (for PDF generation) — all available in the sandbox environment. The entire integration is described in the chat, no manual coding required.
Wiring and Network Considerations
While Modbus/TCP runs over standard Ethernet, keep these practical points in mind:
- IP Configuration: Ensure your PLC/RTU has a static IP. Use a dedicated VLAN for industrial traffic to avoid collisions.
- Firewall Rules: Allow TCP port 502 from the ASI Biont server IP (Railway's egress IP range) to your device.
- Slave IDs: Most Modbus/TCP devices default to slave ID 1. Verify in your PLC configuration.
- Register Addressing: ASI Biont uses 1-based addressing (e.g., 40001 = first holding register). The underlying pymodbus library uses 0-based offsets, but the AI abstracts this automatically.
- Timeout Handling: The sandbox has a 30-second execution timeout per script. For long-running automation, ASI Biont handles re-scheduling internally.
Why This Beats Traditional Approaches
| Aspect | Traditional Method | ASI Biont Integration |
|---|---|---|
| Setup Time | 2-4 hours (write Python, test, deploy) | 2 minutes (describe in chat) |
| Error Handling | Manual exception catching | AI adds retry logic automatically |
| Changes | Edit code, redeploy | Just tell the AI to modify |
| Data Visualization | Separate dashboard tool | Chat-based summaries, no extra software |
| Multi-Device | Each device needs separate script | AI handles multiple devices in one conversation |
Conclusion
Connecting a Modbus/TCP PLC or RTU to ASI Biont transforms your industrial equipment from a black box into a conversational partner. You can monitor, control, log, and automate without writing a single line of ladder logic or Python — just describe what you need in natural language. The AI handles the pymodbus communication, error handling, data persistence, and alerting, all within seconds.
Ready to give your PLC a voice? Head over to asibiont.com and start your first chat-based integration. No installation, no configuration — just connect, describe, and automate.
For the official pymodbus documentation, see pymodbus.readthedocs.io. For Modbus protocol specifics, refer to the Modbus Organization's specification at modbus.org.
Comments