新增模拟硬件测试功能

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
+21 -5
View File
@@ -204,17 +204,33 @@ def collect_data_with_prbs(conn_mgr,
}
# ==================== 6. 主程序 ====================
def main():
"""独立运行入口:自建连接、采集、存盘。"""
from PcControl import Easy521ModbusClient, MotorModbusRTUClient
def main():
"""独立运行入口:自建连接、采集、存盘。"""
from PcControl import Easy521ModbusClient, MotorModbusRTUClient
import os
from core.simulated_device import SimulatedDevice
dt = 0.1
n_order = 7 # 码元数 127
t_c = 5 # 码元周期 5 秒
levels = [10, 20, 30, 40, 50, 60, 70, 80] # 8 个电平,对应 group_bits=3
# 连接 PLC
modbus_client = Easy521ModbusClient()
if os.environ.get("REINLOOP_SIMULATION", "").strip().lower() in {
"1", "true", "yes", "on"}:
device = SimulatedDevice()
device.connect()
q_in_val = float(input("请输入实验时的流量 (SLM): "))
try:
collect_data_with_prbs(device,
q_in_val=q_in_val, dt=dt, n_order=n_order,
t_c=t_c, levels=levels, save_dir="test_data",
repeat=2)
finally:
device.disconnect()
return
# 真实硬件路径:保留原有 PLC/电机 Modbus TCP/RTU 连接代码。
modbus_client = Easy521ModbusClient()
if not modbus_client.connect():
print("无法连接 PLC,退出")
return