Introduction
USB-to-Serial adapters based on FTDI, CH340, and CP2102 chips are the unsung heroes of embedded systems. They bridge the gap between modern computers (which lack native COM ports) and legacy industrial equipment, microcontrollers, and sensors. Whether you're programming an Arduino Uno, reading data from a Modbus RTU temperature controller, or controlling a relay board via serial commands, a USB-to-Serial adapter is your gateway. But what if you could connect that adapter to an AI agent that writes its own integration code on the fly? With ASI Biont, you can. Instead of manually writing Python scripts with pyserial, you simply describe your device in a chat, and the AI agent handles the connection, data parsing, and automation. This article explains how to integrate USB-to-Serial adapters with ASI Biont, with real code examples and practical scenarios.
How ASI Biont Connects to USB-to-Serial Adapters
ASI Biont does not run on your local machine—it operates in the cloud. To access a physical COM port on your PC, you use the Hardware Bridge (bridge.py). This small Python application connects to ASI Biont via WebSocket and acts as a proxy. You download bridge.py from the ASI Biont dashboard (Devices → Create API Key → Download bridge), install dependencies (pip install pyserial requests websockets), and run it with your API token: python bridge.py --token=YOUR_TOKEN --ports=COM3 --baud 115200. Once running, the AI agent can send commands to your COM port using the industrial_command tool with the serial:// protocol. The bridge performs an atomic write+read operation: it sends data (as a hex string or escape sequence) and immediately reads the response. For example, to send HELP and get a response, the AI uses serial_write_and_read(data="48454c500a") (hex for HELP\n).
Practical Example: Controlling a Relay Board via FTDI Adapter
Consider a common scenario: you have an 8-channel relay board controlled by serial commands (e.g., RELAY_ON 1\r\n turns on relay 1). The board is connected to a USB-to-Serial adapter (FTDI) on COM3 at 9600 baud. You want the AI agent to turn relays on/off based on a schedule or external conditions. Here's how you set it up:
- Connect the hardware: Wire the FTDI adapter to the relay board (TX→RX, RX→TX, GND→GND, VCC→5V).
- Run bridge.py:
python bridge.py --token=abc123 --ports=COM3 --baud 9600 - Chat with ASI Biont: You type: "Connect to COM3 at 9600 baud. The relay board accepts commands like 'RELAY_ON 1\r\n' to turn on relay 1. Turn on relay 1 and relay 3, then read the status."
The AI agent responds by executing industrial_command(protocol='serial://COM3', command='serial_write_and_read', data='52454c41595f4f4e20310d0a') (hex for RELAY_ON 1\r\n), then 52454c41595f4f4e20330d0a for relay 3. It then sends a status request command and parses the response. All without you writing a single line of code.
Automation Scenarios
| Scenario | Device | Connection | AI Task |
|---|---|---|---|
| Temperature monitoring | Arduino + DHT22 | COM port via bridge | Read temperature every 10 minutes, log to a Google Sheet, send alert if >30°C |
| Industrial PLC control | Siemens S7-1200 | Modbus RTU via USB-to-RS485 | Read holding registers for tank level, write setpoint when level <20% |
| GPS tracker | NEO-6M GPS module | COM port via bridge | Parse NMEA sentences, plot coordinates on a map, calculate speed |
| Smart home relay | 4-channel relay board | COM port via bridge | Turn on lights at sunset, turn off at 11 PM, log energy usage |
| Motor controller | DM542 stepper driver | COM port via bridge | Send acceleration profile, monitor position, stop on limit switch |
How the AI Agent Handles Data Parsing
One of the most powerful features is the AI's ability to parse arbitrary serial data. For example, if your device outputs a CSV line like T:25.3,H:60.1 every second, you simply tell the AI: "The device sends temperature and humidity in format T:xx.x,H:xx.x every second. Extract the values and alert if temperature exceeds 30°C." The AI writes a Python script (using execute_python) that runs in the cloud sandbox with pyserial? No—wait. Actually, execute_python cannot access your COM port directly. However, the AI can use the bridge to read a chunk of data, then parse it locally in the cloud. The AI might instruct the bridge to read 100 bytes via serial_write_and_read(data="") (empty write just reads), then parse the response. This is a two-step process: bridge reads raw bytes, sends them to the cloud, AI parses and acts.
Why This Matters for Embedded Engineers
Traditionally, integrating a USB-to-Serial device with an AI agent requires:
- Writing a Python script with pyserial, threading, and error handling
- Setting up a REST API or MQTT broker to communicate with the AI
- Debugging serial port conflicts on Windows (e.g., PermissionError: Access is denied)
With ASI Biont, you bypass all of that. The Hardware Bridge handles low-level COM port access (including Windows-specific fixes like CancelIoEx and PurgeComm for reliable writes). The AI agent handles all parsing logic, scheduling, and external integrations (Telegram, email, databases). You just plug in the adapter and describe what you want. For instance, a common issue on Windows is that pyserial writes may fail with "written: 0" due to overlapped I/O. The bridge automatically detects this, cancels pending operations, purges buffers, and retries with synchronous WriteFile—so you don't have to write that boilerplate.
Real-World Case: Factory Temperature Monitoring
A manufacturing company needed to monitor temperature in 10 ovens using PT100 sensors connected to a Modbus RTU controller (RS-485). They used a USB-to-RS485 adapter (based on CP2102) to connect to a laptop running bridge.py. The AI agent was configured to:
- Every 5 minutes, read holding register 0 (temperature) from each oven via Modbus RTU commands sent over serial
- Log the data to a PostgreSQL database (using psycopg2 in execute_python)
- If any oven exceeded 250°C, send an SMS alert via Twilio
- Generate a daily report in Excel (using openpyxl)
The entire integration took 15 minutes of chat conversation. No manual coding of Modbus functions, no database setup—the AI wrote and executed the Python scripts on the fly.
Code Example: AI-Generated Python for Serial Data Logging
Here is an example of a Python script that ASI Biont might generate and execute in its sandbox (using execute_python) to handle data from a serial device via the bridge. Note that this script does NOT access the COM port directly—it receives data via the bridge's WebSocket response.
import json
import requests
# This script would be triggered by the AI after reading data from the bridge
# The AI sends a command to bridge, gets raw hex response, then parses it here
raw_hex = "543a32352e332c483a36302e310a" # example: "T:25.3,H:60.1\n"
bytes_data = bytes.fromhex(raw_hex)
decoded = bytes_data.decode('ascii').strip()
parts = decoded.split(',')
temp = float(parts[0].split(':')[1])
hum = float(parts[1].split(':')[1])
print(f"Temperature: {temp}°C, Humidity: {hum}%")
if temp > 30:
# Send alert via Telegram (using requests)
requests.post("https://api.telegram.org/botTOKEN/sendMessage", json={"chat_id": "123", "text": "High temperature!"})
This script runs in the sandbox, which has requests available. The AI writes it, executes it, and the result is shown in the chat. You don't need to copy-paste anything.
Conclusion
USB-to-Serial adapters are the most cost-effective way to connect legacy and modern devices to a computer. With ASI Biont, you can transform that simple COM port into an AI-controlled automation hub. The Hardware Bridge handles the low-level connection, while the AI agent writes all the parsing, decision-making, and integration code. Whether you're a hobbyist controlling relays or an engineer monitoring industrial PLCs, you can start in minutes: download bridge.py from the ASI Biont dashboard, plug in your adapter, and describe your task in the chat. No coding, no waiting for SDKs—just pure AI-driven integration. Try it now at asibiont.com and see how fast you can connect your USB-to-Serial device to the future.
Comments