This commit is contained in:
@@ -16,6 +16,14 @@ namespace MembranePoreTester.Communication
|
|||||||
public ushort PressureRegister { get; set; } // 不再使用,保留兼容
|
public ushort PressureRegister { get; set; } // 不再使用,保留兼容
|
||||||
public ushort WetFlowRegister { get; set; } // 湿膜流量寄存器起始地址
|
public ushort WetFlowRegister { get; set; } // 湿膜流量寄存器起始地址
|
||||||
public ushort DryFlowRegister { get; set; } // 干膜流量寄存器起始地址
|
public ushort DryFlowRegister { get; set; } // 干膜流量寄存器起始地址
|
||||||
|
|
||||||
|
|
||||||
|
public ushort WetFlowRegister2 { get; set; } // 湿膜流量寄存器起始地址
|
||||||
|
public ushort DryFlowRegister2 { get; set; } // 干膜流量寄存器起始地址
|
||||||
|
|
||||||
|
|
||||||
|
public ushort WetFlowRegister3 { get; set; } // 湿膜流量寄存器起始地址
|
||||||
|
public ushort DryFlowRegister3 { get; set; } // 干膜流量寄存器起始地址
|
||||||
public double PressureFactor { get; set; } = 1.0; // 压力系数(单位换算)
|
public double PressureFactor { get; set; } = 1.0; // 压力系数(单位换算)
|
||||||
|
|
||||||
|
|
||||||
@@ -152,10 +160,10 @@ namespace MembranePoreTester.Communication
|
|||||||
Task<float> ReadPressureAsync(int stationId);
|
Task<float> ReadPressureAsync(int stationId);
|
||||||
|
|
||||||
/// <summary> 读取湿膜流量(浮点数) </summary>
|
/// <summary> 读取湿膜流量(浮点数) </summary>
|
||||||
Task<float> ReadWetFlowAsync();
|
Task<float> ReadWetFlowAsync(int stationId);
|
||||||
|
|
||||||
/// <summary> 读取干膜流量(浮点数) </summary>
|
/// <summary> 读取干膜流量(浮点数) </summary>
|
||||||
Task<float> ReadDryFlowAsync();
|
Task<float> ReadDryFlowAsync(int stationId);
|
||||||
|
|
||||||
/// <summary> 写入线圈(如 M 元件) </summary>
|
/// <summary> 写入线圈(如 M 元件) </summary>
|
||||||
Task WriteCoilAsync(ushort coilAddress, bool value);
|
Task WriteCoilAsync(ushort coilAddress, bool value);
|
||||||
|
|||||||
@@ -39,11 +39,28 @@ namespace MembranePoreTester.Communication
|
|||||||
public async Task<float> ReadPressureAsync() =>
|
public async Task<float> ReadPressureAsync() =>
|
||||||
await ReadFloatAsync(_config.PressureRegister);
|
await ReadFloatAsync(_config.PressureRegister);
|
||||||
|
|
||||||
public async Task<float> ReadWetFlowAsync() =>
|
public async Task<float> ReadWetFlowAsync(int stationId)
|
||||||
await ReadFloatAsync(_config.WetFlowRegister);
|
{
|
||||||
|
ushort startAddress = stationId switch
|
||||||
|
{
|
||||||
|
1 => _config.WetFlowRegister,
|
||||||
|
2 => _config.WetFlowRegister2,
|
||||||
|
3 => _config.WetFlowRegister3,
|
||||||
|
};
|
||||||
|
return await ReadFloatAsync(startAddress);
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<float> ReadDryFlowAsync() =>
|
public async Task<float> ReadDryFlowAsync(int stationId)
|
||||||
await ReadFloatAsync(_config.DryFlowRegister);
|
{
|
||||||
|
ushort startAddress = stationId switch
|
||||||
|
{
|
||||||
|
1 => _config.DryFlowRegister,
|
||||||
|
2 => _config.DryFlowRegister2,
|
||||||
|
3 => _config.DryFlowRegister3,
|
||||||
|
_ => throw new ArgumentException("Invalid station")
|
||||||
|
};
|
||||||
|
return await ReadFloatAsync(startAddress);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public async Task WriteCoilAsync(ushort coilAddress, bool value)
|
public async Task WriteCoilAsync(ushort coilAddress, bool value)
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ using System.Collections.ObjectModel;
|
|||||||
using System.Collections.Specialized;
|
using System.Collections.Specialized;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Net;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
|
|
||||||
@@ -105,12 +106,12 @@ namespace MembranePoreTester.ViewModels
|
|||||||
double flow = 0;
|
double flow = 0;
|
||||||
if (TestMode.Contains("湿膜"))
|
if (TestMode.Contains("湿膜"))
|
||||||
{
|
{
|
||||||
float rawFlow = await _plcService.ReadWetFlowAsync();
|
float rawFlow = await _plcService.ReadWetFlowAsync(StationId);
|
||||||
flow = Math.Round(ConvertFlowByMode(rawFlow), 3);
|
flow = Math.Round(ConvertFlowByMode(rawFlow), 3);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
float rawFlow = await _plcService.ReadDryFlowAsync();
|
float rawFlow = await _plcService.ReadDryFlowAsync(StationId);
|
||||||
flow = Math.Round(ConvertFlowByMode(rawFlow), 3);
|
flow = Math.Round(ConvertFlowByMode(rawFlow), 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -340,13 +341,24 @@ namespace MembranePoreTester.ViewModels
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
float speedRate = 0;
|
float speedRate = 0;
|
||||||
|
ushort address = 0;
|
||||||
switch (StationId)
|
switch (StationId)
|
||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
speedRate = await _plcService.ReadFloatAsync(_plcConfig.HPCoeff11); // 使用正确的地址
|
address = _plcConfig.HPCoeff11;
|
||||||
|
speedRate = await _plcService.ReadFloatAsync(address);
|
||||||
|
SpeedRate1 = speedRate.ToString("F3");
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
address = _plcConfig.HPCoeff12;
|
||||||
|
speedRate = await _plcService.ReadFloatAsync(address);
|
||||||
|
SpeedRate1 = speedRate.ToString("F3");
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
address = _plcConfig.HPCoeff13;
|
||||||
|
speedRate = await _plcService.ReadFloatAsync(address);
|
||||||
SpeedRate1 = speedRate.ToString("F3");
|
SpeedRate1 = speedRate.ToString("F3");
|
||||||
break;
|
break;
|
||||||
// case 2,3 可类似添加
|
|
||||||
}
|
}
|
||||||
// 如果需要刷新 Record 中的绑定(可选)
|
// 如果需要刷新 Record 中的绑定(可选)
|
||||||
OnPropertyChanged(nameof(SpeedRate1));
|
OnPropertyChanged(nameof(SpeedRate1));
|
||||||
@@ -408,12 +420,12 @@ namespace MembranePoreTester.ViewModels
|
|||||||
SelectedDataPoint.Pressure = pressure;
|
SelectedDataPoint.Pressure = pressure;
|
||||||
if (TestMode == "湿膜")
|
if (TestMode == "湿膜")
|
||||||
{
|
{
|
||||||
float rawWet = await _plcService.ReadWetFlowAsync();
|
float rawWet = await _plcService.ReadWetFlowAsync(StationId);
|
||||||
SelectedDataPoint.WetFlow = ConvertFlowByMode(rawWet);
|
SelectedDataPoint.WetFlow = ConvertFlowByMode(rawWet);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
float rawDry = await _plcService.ReadDryFlowAsync();
|
float rawDry = await _plcService.ReadDryFlowAsync(StationId);
|
||||||
SelectedDataPoint.DryFlow = ConvertFlowByMode(rawDry);
|
SelectedDataPoint.DryFlow = ConvertFlowByMode(rawDry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -423,12 +435,12 @@ namespace MembranePoreTester.ViewModels
|
|||||||
var newPoint = new Models.DataPoint { Pressure = pressure };
|
var newPoint = new Models.DataPoint { Pressure = pressure };
|
||||||
if (TestMode == "湿膜")
|
if (TestMode == "湿膜")
|
||||||
{
|
{
|
||||||
float rawWet = await _plcService.ReadWetFlowAsync();
|
float rawWet = await _plcService.ReadWetFlowAsync(StationId);
|
||||||
newPoint.WetFlow = ConvertFlowByMode(rawWet);
|
newPoint.WetFlow = ConvertFlowByMode(rawWet);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
float rawDry = await _plcService.ReadDryFlowAsync();
|
float rawDry = await _plcService.ReadDryFlowAsync(StationId);
|
||||||
newPoint.DryFlow = ConvertFlowByMode(rawDry);
|
newPoint.DryFlow = ConvertFlowByMode(rawDry);
|
||||||
}
|
}
|
||||||
Record.DataPoints.Add(newPoint);
|
Record.DataPoints.Add(newPoint);
|
||||||
|
|||||||
@@ -42,6 +42,15 @@
|
|||||||
// 流量寄存器地址(每个工位共用,但需配合流量模式切换)
|
// 流量寄存器地址(每个工位共用,但需配合流量模式切换)
|
||||||
"WetFlowRegister": 12, // 湿膜流量寄存器起始地址(D2~D3)
|
"WetFlowRegister": 12, // 湿膜流量寄存器起始地址(D2~D3)
|
||||||
"DryFlowRegister": 12, // 干膜流量寄存器起始地址(D4~D5)
|
"DryFlowRegister": 12, // 干膜流量寄存器起始地址(D4~D5)
|
||||||
|
|
||||||
|
"WetFlowRegister2": 14, // 湿膜流量寄存器起始地址(D2~D3)
|
||||||
|
"DryFlowRegister2": 14, // 干膜流量寄存器起始地址(D4~D5)
|
||||||
|
|
||||||
|
"WetFlowRegister3": 16, // 湿膜流量寄存器起始地址(D2~D3)
|
||||||
|
"DryFlowRegister3": 16, // 干膜流量寄存器起始地址(D4~D5)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
"WetFlowFactor": 1.0, // 湿膜流量系数
|
"WetFlowFactor": 1.0, // 湿膜流量系数
|
||||||
"DryFlowFactor": 1.0, // 干膜流量系数
|
"DryFlowFactor": 1.0, // 干膜流量系数
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user