You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

多RS485通信系统首次开机机器人异常问题技术问询

首次启动RS485控制系统异常,重启后恢复的问题排查

我正在开发一套控制系统,通过单台PC的4个USB端口连接12台RS485设备,用于控制电机及其他组件。RS485连接配置如下:

#RS485 Lines 
self.line1 = ModbusConnection(port='/dev/ttyAMA2') # Robot 1 
self.line2 = ModbusConnection(port='/dev/ttyAMA4') # Robot 2 
self.line3 = ModbusConnection(port='/dev/ttyACM3') # Encoder/Relay 
self.line4 = ModbusConnection(port='/dev/ttyACM2') # Shaking system (Station 8/10) 
# Drivers and Robots 
self.robot1 = RobotDriver(self.line1, motor_x_id=1, motor_z_id=2, encoder_id=3) 
self.robot2 = RobotDriver(self.line2, motor_x_id=1, motor_z_id=2, encoder_id=3) 
self.io_driver = IODriver(self.line3, device_id=1)
self.relay = RelayDriver(self.line3, device_id=2)
self.station_motor_8 = StationMotorDriver(self.line4, motor_id=1, encoder_id=2, station_no=8)
self.station_motor_10 = StationMotorDriver(self.line4, motor_id=4, encoder_id=3, station_no=10)

首次按下电源按钮启动系统硬件并运行软件时,robot1或robot2会在运行一段时间后完全静止不动。但关闭并重启整个系统后,系统运行正常,机器人可顺利执行所有指令。目前在软硬件层面均未找到异常原因,想请教是否有人遇到过此类问题?

我的ModbusConnection类代码如下:

import threading

import logging
from pymodbus.client import ModbusSerialClient

class ModbusConnection:
    def __init__(self, port: str, baudrate: int = 19200):
        self._lock = threading.Lock()
        self.client = ModbusSerialClient(
            port=port,
            baudrate=baudrate,
            bytesize=8,
            parity='N',
            stopbits=1,
            timeout=0.2
        )
        self._connected = self.client.connect()
        if not self._connected:
            logging.error(f"RS485 connection error: {port}")

    def read_registers(self, slave_id: int, address: int, count: int):
        with self._lock:
            return self.client.read_holding_registers(
                address=address,
                count=count,
                slave=slave_id
            )

    def write_register(self, slave_id: int, address: int, value: int):
        with self._lock:
            return self.client.write_register(
                address=address,
                value=value,
                slave=slave_id
            )

    def write_registers(self, slave_id: int, address: int, values: list):
        with self._lock:
            return self.client.write_registers(
                address=address,
                values=values,
                slave=slave_id
            )

    def read_discrete_inputs(self, slave_id: int, address: int, count: int):
        with self._lock:
            return self.client.read_discrete_inputs(
                address=address,
                count=count,
                slave=slave_id
            )

    def read_coils(self, slave_id: int, address: int, count: int):
        with self._lock:
            return self.client.read_coils(
                address=address,
                count=count,
                slave=slave_id
            )

    def write_coil(self, slave_id: int, address: int, value: bool):
        with self._lock:
            return self.client.write_coil(
                address=address,
                value=value,
                slave=slave_id
            )

    def read_input_registers(self, slave_id: int, address: int, count: int):
        with self._lock:
            return self.client.read_input_registers(
                address=address,
                count=count,
                slave=slave_id
            )

    def close(self):
        self.client.close()

内容的提问来源于stack exchange,提问作者furkan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.02 11:34:54