新增模拟硬件测试功能

This commit is contained in:
2026-07-31 11:29:10 +08:00
parent 692d8dd18a
commit 14291ee984
7 changed files with 242 additions and 34 deletions
+19 -6
View File
@@ -26,7 +26,7 @@ import serial.tools.list_ports
from stable_baselines3 import SAC
import torch
# from PressureEnv import CustomPressureEnv
from PcControl import Easy521ModbusClient, MotorModbusRTUClient
from PcControl import Easy521ModbusClient, MotorModbusRTUClient
# from zzp import SECRET_KEY
# from PcControl import PressureModbusRTUClient, MotorModbusRTUClient
from controllers import IncrementalPID
@@ -35,8 +35,9 @@ from get_V import measure_volume
from ind_collector import collect_data_with_prbs
import logging
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from api import base_url, data_record_url, the_folder
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from core.simulated_device import SimulatedDevice
from api import base_url, data_record_url, the_folder
warnings.filterwarnings('ignore')
logging.getLogger("pymodbus").setLevel(logging.ERROR)
@@ -1127,9 +1128,21 @@ class ControlGUI:
else:
self.connect_plc()
def connect_plc(self):
"""连接到PLC及电机"""
# ---------------- 读取 Modbus TCP 参数 ----------------
def connect_plc(self):
"""连接到PLC及电机"""
if os.environ.get("REINLOOP_SIMULATION", "").strip().lower() in {
"1", "true", "yes", "on"}:
# 模拟路径:不创建真实 TCP/RTU 客户端。
self.simulation_mode = True
self.modbus_client = SimulatedDevice()
self.motor = self.modbus_client
self.modbus_client.connect()
self.connection_status_var.set("模拟已连接")
self.connect_btn.config(text="断开连接")
self.log_message("模拟设备已连接(未访问真实 TCP/串口硬件)")
return
# ---------------- 读取 Modbus TCP 参数 ----------------
ip_address = self.tcp_ip_entry.get().strip()
try:
tcp_port = int(self.tcp_port_entry.get())