using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AciTester.Models { /// /// PLC 配置类,用于存储从 appsettings.json 读取的 Modbus 参数和寄存器地址。 /// public class PlcConfiguration { // ========== 网络连接参数 ========== public string IpAddress { get; set; } = "192.168.1.10"; // PLC IP 地址 public int Port { get; set; } = 502; // Modbus TCP 端口 public byte SlaveId { get; set; } = 1; // 从站地址(默认1) // 以下属性用于与上位机交互(但实际按工位读取,此处保留兼容) public ushort PressureRegister { get; set; } // 不再使用,保留兼容 public ushort WetFlowRegister { get; set; } // 湿膜流量寄存器起始地址 public ushort WetFlowRegister2 { get; set; } // 湿膜流量寄存器起始地址 public ushort WetFlowRegister3 { get; set; } // 湿膜流量寄存器起始地址 // ========== 工位专用寄存器 ========== public ushort PressureRegisterStation1 { get; set; } // 工位1 压力寄存器起始地址 public ushort PressureRegisterStation2 { get; set; } // 工位2 public ushort PressureRegisterStation3 { get; set; } // 工位3 public ushort ValveCoil { get; set; } = 5; // 假设 M5 对应线圈地址 5 public ushort PumpCoil { get; set; } = 6; // 高压超限 M180 public ushort FlowRegister { get; set; } = 1330; // 高压超限 M180 // 新增地址 public ushort FlowCalibrationReg { get; set; } = 1328; public ushort FlowProtectReg { get; set; } = 1332; public ushort TemperatureReg { get; set; } = 1082;// public ushort TempCalibrationReg { get; set; } = 1080; public ushort PumpPressureReg { get; set; } = 1430; public ushort PumpPressureCalibReg { get; set; } = 1428; public ushort ImpactorPressureReg { get; set; } = 1480; public ushort ImpactorPressureCalibReg { get; set; } = 1478; public ushort ImpactorPressureCalibCoil { get; set; } = 1303; // M1303 public ushort AcLowPressureAlarmCoil { get; set; } = 1001; // M1001 public ushort AcHighPressureAlarmCoil { get; set; } = 1002; // M1002 public ushort AcStartupCountdownReg { get; set; } = 50; // D50 (双整数) public ushort DefrostTempSetReg { get; set; } = 302; // D302 (浮点) public ushort DefrostTimeSetReg { get; set; } = 310; // D310 (双整数) public ushort DefrostMinuteReg { get; set; } = 42; // D42 (双整数) public ushort DefrostSecondReg { get; set; } = 40; // D40 (双整数) public ushort TempProtectReg { get; set; } = 1084; // D1084 (浮点) public ushort ConstantTempStartCoil { get; set; } = 4; // M4 public ushort DefrostStartCoil { get; set; } = 19; // M19 } /// /// PLC 服务接口,定义与 Modbus 设备通信的方法。 /// public interface IPlcService { /// 读取指定工位的压力(浮点数) /// 工位号 1~3 Task ReadPressureAsync(int stationId); /// 读取湿膜流量(浮点数) Task ReadWetFlowAsync(int stationId); /// 写入线圈(如 M 元件) Task WriteCoilAsync(ushort coilAddress, bool value); /// 写入单个寄存器(16位) Task WriteRegisterAsync(ushort registerAddress, ushort value); /// 读取线圈状态(如 M 元件的 ON/OFF) Task ReadCoilAsync(ushort coilAddress); /// 读取连续多个保持寄存器(16位) Task ReadHoldingRegistersAsync(ushort startAddress, ushort count); /// 写入单个保持寄存器(16位) Task WriteSingleRegisterAsync(ushort registerAddress, ushort value); Task WriteMultipleRegistersAsync(ushort registerAddress, float value); float UshortToFloat(ushort P1, ushort P2); Task ReadFloatAsync(ushort startAddress); Task EnsureConnectedAsync(int retryCount = 3); void Dispose(); bool IsConnected { get; } // 新增 Task ReadInt32Async(ushort startAddress); Task WriteInt32Async(ushort startAddress, int value); } }