Files
HeadgearViewingRange3M/Helpers/PlcConfiguration.cs
2026-03-24 21:05:32 +08:00

80 lines
2.9 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
namespace MembranePoreTester.Communication
{
public class PlcConfiguration
{
public string IpAddress { get; set; }
public int Port { get; set; }
public byte SlaveId { get; set; } = 1; // 从站地址默认1
public ushort PressureRegister { get; set; }
public ushort WetFlowRegister { get; set; }
public ushort DryFlowRegister { get; set; }
public double PressureFactor { get; set; } = 1.0;
public double WetFlowFactor { get; set; } = 1.0;
public double DryFlowFactor { get; set; } = 1.0;
public ushort PressureRegisterStation1 { get; set; }
public ushort PressureRegisterStation2 { get; set; }
public ushort PressureRegisterStation3 { get; set; }
public ushort PressureModeRegister { get; set; }
public ushort PressCoil { get; set; }
public ushort StartCoil { get; set; }
public ushort EnableCoil { get; set; }
public ushort StopCoil { get; set; }
public ushort PressureUpperLimit { get; set; } = 300;
public ushort PressureRate { get; set; } = 280;
public ushort PressureCoeff { get; set; } = 282;
public ushort HPCoeff1 { get; set; } = 3120;
public ushort LPCoeff1 { get; set; } = 3122;
public ushort HPCoeff2 { get; set; } = 3124;
public ushort LPCoeff2 { get; set; } = 3126;
public ushort HPCoeff3 { get; set; } = 3128;
public ushort LPCoeff3 { get; set; } = 3130;
public ushort LargeFlowCoeff1 { get; set; } = 3048;
public ushort SmallFlowCoeff1 { get; set; } = 380;
public ushort LargeFlowCoeff2 { get; set; } = 1218;
public ushort SmallFlowCoeff2 { get; set; } = 1318;
public ushort LargeFlowCoeff3 { get; set; } = 1418;
public ushort SmallFlowCoeff3 { get; set; } = 1468;
public ushort FlowModeRegister1 { get; set; } = 5; // 工位1流量模式 (0=大,1=小)
public ushort FlowModeRegister2 { get; set; } = 6;
public ushort FlowModeRegister3 { get; set; } = 7;
// 校准系数地址需与PLC约定
public ushort PressureCalibZero { get; set; } = 3200;
public ushort PressureCalibSpan { get; set; } = 3202;
public ushort FlowCalibZero { get; set; } = 3204;
public ushort FlowCalibSpan { get; set; } = 3206;
}
public interface IPlcService
{
Task<float> ReadPressureAsync(int stationId); // 按工位读取压力
Task<float> ReadWetFlowAsync();
Task<float> ReadDryFlowAsync();
Task WriteCoilAsync(ushort coilAddress, bool value); // 写线圈
Task WriteRegisterAsync(ushort registerAddress, ushort value); // 写寄存器
Task<bool> ReadCoilAsync(ushort coilAddress); // 新增:读取线圈状态
Task<ushort[]> ReadHoldingRegistersAsync(ushort startAddress, ushort count);
Task WriteSingleRegisterAsync(ushort registerAddress, ushort value);
}
}