新增模拟硬件测试功能
This commit is contained in:
+26
-5
@@ -137,14 +137,35 @@ def measure_volume(conn_mgr,
|
||||
return result
|
||||
|
||||
|
||||
def main():
|
||||
"""独立运行入口:自建连接、跑测试、画图验证。"""
|
||||
import matplotlib.pyplot as plt
|
||||
from PcControl import Easy521ModbusClient, MotorModbusRTUClient
|
||||
def main():
|
||||
"""独立运行入口:自建连接、跑测试、画图验证。"""
|
||||
import matplotlib.pyplot as plt
|
||||
from PcControl import Easy521ModbusClient, MotorModbusRTUClient
|
||||
import os
|
||||
from core.simulated_device import SimulatedDevice
|
||||
|
||||
q_in_slm = 50.0
|
||||
|
||||
modbus_client = Easy521ModbusClient()
|
||||
if os.environ.get("REINLOOP_SIMULATION", "").strip().lower() in {
|
||||
"1", "true", "yes", "on"}:
|
||||
device = SimulatedDevice()
|
||||
device.connect()
|
||||
result = measure_volume(device, q_in_slm=q_in_slm)
|
||||
device.disconnect()
|
||||
record_time = result['record_time']
|
||||
p_actual = result['p_actual']
|
||||
plt.figure(figsize=(10, 6))
|
||||
plt.plot(record_time, p_actual, 'b.-', label='Simulated P (kPa)')
|
||||
plt.title('Simulated Pressure Rise Test')
|
||||
plt.xlabel('Time (s)')
|
||||
plt.ylabel('Pressure (kPa)')
|
||||
plt.grid(True)
|
||||
plt.legend()
|
||||
plt.tight_layout()
|
||||
plt.show()
|
||||
return
|
||||
|
||||
modbus_client = Easy521ModbusClient()
|
||||
if modbus_client.connect():
|
||||
print("成功连接到PLC")
|
||||
modbus_client.start_control()
|
||||
|
||||
Reference in New Issue
Block a user