添加项目文件。
This commit is contained in:
101
Models/PlcConfiguration.cs
Normal file
101
Models/PlcConfiguration.cs
Normal file
@@ -0,0 +1,101 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AciTester.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// PLC 配置类,用于存储从 appsettings.json 读取的 Modbus 参数和寄存器地址。
|
||||
/// </summary>
|
||||
public class PlcConfiguration
|
||||
{
|
||||
// ========== 网络连接参数 ==========
|
||||
public string IpAddress { get; set; } // PLC IP 地址
|
||||
public int Port { get; set; } // 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 PumpCoil { get; set; } // 高压超限 M180
|
||||
|
||||
|
||||
public ushort FlowRegister { get; set; } // 高压超限 M180
|
||||
|
||||
|
||||
|
||||
|
||||
// 新增地址
|
||||
public ushort FlowCalibrationReg { get; set; } = 1328;
|
||||
public ushort FlowProtectReg { get; set; } = 1332;
|
||||
public ushort TemperatureReg { get; set; } = 1380;
|
||||
public ushort TempCalibrationReg { get; set; } = 1378;
|
||||
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
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// PLC 服务接口,定义与 Modbus 设备通信的方法。
|
||||
/// </summary>
|
||||
public interface IPlcService
|
||||
{
|
||||
/// <summary> 读取指定工位的压力(浮点数) </summary>
|
||||
/// <param name="stationId">工位号 1~3</param>
|
||||
Task<float> ReadPressureAsync(int stationId);
|
||||
|
||||
/// <summary> 读取湿膜流量(浮点数) </summary>
|
||||
Task<float> ReadWetFlowAsync(int stationId);
|
||||
|
||||
|
||||
/// <summary> 写入线圈(如 M 元件) </summary>
|
||||
Task WriteCoilAsync(ushort coilAddress, bool value);
|
||||
|
||||
/// <summary> 写入单个寄存器(16位) </summary>
|
||||
Task WriteRegisterAsync(ushort registerAddress, ushort value);
|
||||
|
||||
/// <summary> 读取线圈状态(如 M 元件的 ON/OFF) </summary>
|
||||
Task<bool> ReadCoilAsync(ushort coilAddress);
|
||||
|
||||
/// <summary> 读取连续多个保持寄存器(16位) </summary>
|
||||
Task<ushort[]> ReadHoldingRegistersAsync(ushort startAddress, ushort count);
|
||||
|
||||
/// <summary> 写入单个保持寄存器(16位) </summary>
|
||||
Task WriteSingleRegisterAsync(ushort registerAddress, ushort value);
|
||||
|
||||
|
||||
Task WriteMultipleRegistersAsync(ushort registerAddress, float value);
|
||||
|
||||
float UshortToFloat(ushort P1, ushort P2);
|
||||
|
||||
Task<float> ReadFloatAsync(ushort startAddress);
|
||||
|
||||
Task EnsureConnectedAsync(int retryCount = 3);
|
||||
|
||||
void Dispose();
|
||||
|
||||
bool IsConnected { get; } // 新增
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user