Introduction
In industrial automation, CAN bus (Controller Area Network) remains the backbone for real-time communication between sensors, actuators, and controllers. From automotive ECUs to factory floor motor drives, CAN bus delivers deterministic messaging at speeds up to 1 Mbps. Yet, integrating CAN bus with an AI agent has traditionally required custom middleware, protocol parsers, and manual scripting. ASI Biont changes this: you describe your CAN bus setup in a chat conversation, and the AI generates the integration code on the fly. No dashboards, no drag-and-drop — just natural language. This article walks through a step-by-step guide: connecting CAN bus hardware, writing Python scripts, and controlling motors, climate systems, and monitoring via chat.
Why CAN Bus + AI?
CAN bus is everywhere: vehicles, factory lines, building management, agricultural machinery. However, extracting data or sending commands often requires a dedicated HMI or PLC programming. With ASI Biont, you gain:
- Dynamic logic: AI can analyze CAN frames in real time and adjust setpoints based on trends.
- Remote access: control CAN nodes from anywhere via chat.
- Zero coding overhead: you don't write the integration from scratch — AI writes it for you.
Connection Methods Supported by ASI Biont
ASI Biont connects to CAN bus through two primary paths, depending on your hardware:
| Method | Hardware Needed | ASI Biont Tool | Use Case |
|---|---|---|---|
| COM port (RS-232/RS-485) | CAN-to-serial converter (e.g., USBtin, CANtact) + bridge.py on PC | industrial_command with protocol serial:// |
Direct CAN frame read/write via serial bridge |
| SSH | Single-board computer (Raspberry Pi, BeagleBone) with CAN hat, running socketcan | execute_python with paramiko |
Remote CAN bus control over SSH |
| MQTT | ESP32 with CAN shield + MQTT broker | execute_python with paho-mqtt |
Cloud-connected CAN nodes |
| execute_python (universal) | Any device reachable via network | AI writes Python script using python-can library |
Full flexibility: parse frames, log, trigger actions |
Important: ASI Biont does not have a built-in CAN driver. Instead, it leverages execute_python — the AI writes a Python script that runs in a cloud sandbox and uses the python-can library to interface with CAN hardware via the chosen transport (serial, socketcan, MQTT bridge).
Concrete Use Case: Motor Control with CAN Bus
Scenario
You have a CANopen-compatible motor drive (e.g., Copley, Maxon) connected via a USBtin CAN-to-serial adapter. You want to:
- Read motor speed (RPM) from CAN ID 0x201.
- Send a start command (0x00) to control word at ID 0x202.
- Log data to a CSV file on your PC.
- Get a Telegram alert if speed exceeds 3000 RPM.
Step-by-Step Implementation
1. Hardware Setup
- Connect USBtin to PC (COM3, 115200 baud).
- Connect USBtin CAN bus to motor drive (CAN H, CAN L).
- Run bridge.py on your PC:
bridge.py --token=YOUR_TOKEN --ports=COM3 --default-baud=115200 - The bridge connects to ASI Biont cloud via HTTP long polling, exposing COM3 to the AI.
2. Describe in Chat
User:
"Connect to CAN bus on COM3 at 115200 baud. Use python-can library. Read motor speed from CAN ID 0x201 every 2 seconds. If speed > 3000 RPM, send a Telegram message to my chat. Also log all readings to a CSV file."
3. AI Generates and Executes Code
import asyncio
import can
import csv
import time
from datetime import datetime
async def main():
# Configure CAN interface via serial bridge
bus = can.interface.Bus(bustype='serial', channel='COM3', bitrate=115200)
# Prepare CSV logger
with open('motor_log.csv', 'a', newline='') as f:
writer = csv.writer(f)
for _ in range(30): # run for 60 seconds
# Request speed from motor (SDO read)
msg = can.Message(arbitration_id=0x201, data=[0x40, 0x6C, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00], is_extended_id=False)
bus.send(msg)
# Wait for response
response = bus.recv(timeout=1.0)
if response and response.arbitration_id == 0x581:
# Extract speed (bytes 4-7, little-endian)
speed = int.from_bytes(response.data[4:8], byteorder='little', signed=True)
timestamp = datetime.now().isoformat()
writer.writerow([timestamp, speed])
print(f"{timestamp} Speed: {speed} RPM")
# Alert if over threshold
if speed > 3000:
# Send Telegram via ASI Biont (simplified)
await send_telegram_alert(f"Motor speed critical: {speed} RPM")
await asyncio.sleep(2)
bus.shutdown()
asyncio.run(main())
Note: The send_telegram_alert function is a placeholder — in practice, the AI would use the slack_sdk or twilio library available in the sandbox, or instruct the user to set up a webhook.
4. AI Executes and Monitors
- The script runs for 60 seconds (sandbox timeout is 30 seconds, but AI can split into multiple runs).
- CSV file is saved locally via the bridge's file access.
- If speed exceeds 3000 RPM, AI sends a message to the user's chat.
Alternative: MQTT-based CAN Bridge
If you have an ESP32 with CAN shield and MQTT:
import paho.mqtt.client as mqtt
import json
def on_message(client, userdata, msg):
payload = json.loads(msg.payload)
speed = payload.get('rpm', 0)
print(f"CAN frame: {msg.topic} -> {speed} RPM")
if speed > 3000:
# AI can send alert via chat
print("ALERT: Over speed!")
client = mqtt.Client()
client.on_message = on_message
client.connect("test.mosquitto.org", 1883, 60)
client.subscribe("can/motor/speed")
client.loop_start()
This script runs in execute_python, subscribes to can/motor/speed, and prints alerts. The AI can extend it to log to a database or trigger a command.
Climate Control via CAN Bus
Scenario
You have a building HVAC system with CANopen nodes (temperature sensors, fan speed controllers). You want to:
- Read temperature from sensor ID 0x101.
- Set fan speed (0-100%) by writing to ID 0x102.
- Automate: if temperature > 25°C, increase fan to 80%.
Chat Command
User:
"Monitor CAN bus temperature from ID 0x101. If temp > 25°C, write 80 to fan speed at ID 0x102. Log all changes."
AI generates:
import can
import time
bus = can.interface.Bus(bustype='serial', channel='COM3', bitrate=125000)
while True:
# Read temperature
msg = can.Message(arbitration_id=0x101, data=[0x40, 0x65, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00])
bus.send(msg)
resp = bus.recv(timeout=0.5)
if resp:
temp = int.from_bytes(resp.data[4:8], 'little') / 10.0 # assume scaling
print(f"Temp: {temp}°C")
if temp > 25.0:
# Write fan speed
cmd = can.Message(arbitration_id=0x102, data=[0x23, 0x66, 0x20, 0x00, 80, 0x00, 0x00, 0x00])
bus.send(cmd)
print("Fan set to 80%")
time.sleep(5)
Again, while True is problematic for sandbox; the AI would use a loop with timeout or run periodic execute_python calls.
Why This Matters: AI Does the Heavy Lifting
Traditional integration requires:
- Reading CAN bus specification
- Writing a custom Python script with pyserial or socketcan
- Debugging frame parsing
- Deploying and monitoring
With ASI Biont, you simply describe the task. The AI:
- Chooses the correct library (python-can, pyserial, paho-mqtt)
- Constructs CAN frames with proper SDO protocol
- Handles error checking and timeouts
- Integrates with external services (Telegram, Slack, database)
No waiting for vendor SDKs. No manual wiring of logic. The AI adapts to any CAN bus device — motor drives, sensors, PLCs, HVAC controllers.
Conclusion
CAN bus integration with ASI Biont turns a chat conversation into a powerful industrial automation tool. Whether you're controlling a motor, monitoring a factory line, or managing building climate, the AI writes the code, connects to the hardware, and executes your logic. Stop writing boilerplate — start describing.
Try it now: Go to asibiont.com, describe your CAN bus device in the chat, and watch the AI connect and control it in seconds.
Comments