2026-03-24 20:40:26 +08:00
|
|
|
|
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; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2026-04-01 20:29:45 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 设备参数地址(示例,请根据实际PLC地址修改)
|
|
|
|
|
|
public ushort UpperLampData1 { get; set; } = 350;
|
|
|
|
|
|
public ushort UpperLampData2 { get; set; } = 351;
|
|
|
|
|
|
public ushort UpperLampData3 { get; set; } = 352;
|
|
|
|
|
|
public ushort UpperLampData4 { get; set; } = 353;
|
|
|
|
|
|
public ushort UpperLampData5 { get; set; } = 354;
|
|
|
|
|
|
public ushort UpperLampData6 { get; set; } = 355;
|
|
|
|
|
|
|
|
|
|
|
|
public ushort LowerLampData1 { get; set; } = 356;
|
|
|
|
|
|
public ushort LowerLampData2 { get; set; } = 357;
|
|
|
|
|
|
public ushort LowerLampData3 { get; set; } = 358;
|
|
|
|
|
|
public ushort LowerLampData4 { get; set; } = 359;
|
|
|
|
|
|
public ushort LowerLampData5 { get; set; } = 360;
|
|
|
|
|
|
public ushort LowerLampData6 { get; set; } = 361;
|
|
|
|
|
|
|
|
|
|
|
|
public ushort LeftEyeAreaCoeff { get; set; } = 212;
|
|
|
|
|
|
public ushort RightEyeAreaCoeff { get; set; } = 214;
|
|
|
|
|
|
public ushort SaveRateCorrectionCoeff { get; set; } = 428;
|
|
|
|
|
|
|
|
|
|
|
|
public ushort MiddleLamp1 { get; set; } = 362;
|
|
|
|
|
|
public ushort MiddleLamp2 { get; set; } = 363;
|
|
|
|
|
|
public ushort MiddleLamp3 { get; set; } = 364;
|
|
|
|
|
|
public ushort MiddleLamp4 { get; set; } = 365;
|
|
|
|
|
|
public ushort MiddleLamp5 { get; set; } = 366;
|
|
|
|
|
|
public ushort MiddleLamp6 { get; set; } = 367;
|
|
|
|
|
|
public ushort MiddleLamp7 { get; set; } = 368;
|
|
|
|
|
|
|
|
|
|
|
|
public ushort MotorLimit { get; set; } = 330;
|
|
|
|
|
|
public ushort ResetCompensation { get; set; } = 340; // 新增复位补偿
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2026-03-24 20:40:26 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2026-04-01 20:29:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public enum ParameterDataType
|
|
|
|
|
|
{
|
|
|
|
|
|
Int16, // 16位整数
|
|
|
|
|
|
Float32 // 32位浮点数
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2026-03-24 20:40:26 +08:00
|
|
|
|
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);
|
2026-03-24 21:05:32 +08:00
|
|
|
|
|
2026-03-24 20:40:26 +08:00
|
|
|
|
Task WriteSingleRegisterAsync(ushort registerAddress, ushort value);
|
2026-04-01 20:29:45 +08:00
|
|
|
|
|
|
|
|
|
|
float UshortToFloat(ushort P1, ushort P2);
|
|
|
|
|
|
|
|
|
|
|
|
Task WriteMultipleRegistersAsync(ushort registerAddress, float value);
|
2026-03-24 20:40:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|