This commit is contained in:
@@ -85,6 +85,8 @@ namespace MembranePoreTester.ViewModels
|
||||
public ICommand CalculateCommand { get; }
|
||||
public ICommand GenerateReportCommand { get; }
|
||||
|
||||
public ICommand OpenPressureCalibCommand { get; }
|
||||
|
||||
public BubblePointViewModel()
|
||||
{
|
||||
|
||||
@@ -96,6 +98,7 @@ namespace MembranePoreTester.ViewModels
|
||||
ReadPlcCommand = new RelayCommand(async () => await ReadPlcAsync());
|
||||
SaveCommand = new RelayCommand(SaveToDatabase);
|
||||
ExportCommand = new RelayCommand(ExportToExcel);
|
||||
OpenPressureCalibCommand = new RelayCommand(OpenPressureCalibration);
|
||||
}
|
||||
|
||||
|
||||
@@ -194,7 +197,21 @@ namespace MembranePoreTester.ViewModels
|
||||
|
||||
public ICommand ExportCommand { get; }
|
||||
|
||||
|
||||
private void OpenPressureCalibration()
|
||||
{
|
||||
// 使用简单的输入框获取新零点系数和量程系数
|
||||
string zeroStr = Microsoft.VisualBasic.Interaction.InputBox("请输入压力零点系数", "压力校准", "0");
|
||||
string spanStr = Microsoft.VisualBasic.Interaction.InputBox("请输入压力量程系数", "压力校准", "1");
|
||||
if (float.TryParse(zeroStr, out float zero) && float.TryParse(spanStr, out float span))
|
||||
{
|
||||
Task.Run(async () =>
|
||||
{
|
||||
await WriteFloatAsync(_plcConfig.PressureCalibZero, zero);
|
||||
await WriteFloatAsync(_plcConfig.PressureCalibSpan, span);
|
||||
MessageBox.Show("压力校准系数已写入", "完成");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void ExportToExcel()
|
||||
{
|
||||
|
||||
@@ -127,8 +127,21 @@ namespace MembranePoreTester.ViewModels
|
||||
MessageBox.Show($"写压力模式失败: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public MainViewModel()
|
||||
{
|
||||
for (int i = 1; i <= 3; i++)
|
||||
|
||||
@@ -9,6 +9,7 @@ using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
|
||||
|
||||
namespace MembranePoreTester.ViewModels
|
||||
{
|
||||
public class PoreDistributionViewModel : ViewModelBase, IStationViewModel
|
||||
@@ -122,6 +123,10 @@ namespace MembranePoreTester.ViewModels
|
||||
ReadPlcCommand = new RelayCommand(async () => await ReadPlcAsync());
|
||||
SaveCommand = new RelayCommand(SaveToDatabase);
|
||||
ExportCommand = new RelayCommand(ExportToExcel);
|
||||
OpenFlowCalibCommand = new RelayCommand(OpenFlowCalibration);
|
||||
|
||||
|
||||
Record.DataPoints.CollectionChanged += (s, e) => UpdatePlot();
|
||||
}
|
||||
|
||||
|
||||
@@ -220,8 +225,20 @@ namespace MembranePoreTester.ViewModels
|
||||
ReportGenerator.GeneratePoreDistributionReport(Record);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void OpenFlowCalibration()
|
||||
{
|
||||
string zeroStr = Microsoft.VisualBasic.Interaction.InputBox("请输入流量零点系数", "流量校准", "0");
|
||||
string spanStr = Microsoft.VisualBasic.Interaction.InputBox("请输入流量量程系数", "流量校准", "1");
|
||||
if (float.TryParse(zeroStr, out float zero) && float.TryParse(spanStr, out float span))
|
||||
{
|
||||
Task.Run(async () =>
|
||||
{
|
||||
await WriteFloatAsync(_plcConfig.FlowCalibZero, zero);
|
||||
await WriteFloatAsync(_plcConfig.FlowCalibSpan, span);
|
||||
MessageBox.Show("流量校准系数已写入", "完成");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private int _stationId;
|
||||
public int StationId
|
||||
@@ -301,7 +318,7 @@ namespace MembranePoreTester.ViewModels
|
||||
public ICommand SaveCommand { get; }
|
||||
|
||||
|
||||
|
||||
public ICommand OpenFlowCalibCommand { get; }
|
||||
public ICommand ExportCommand { get; }
|
||||
|
||||
|
||||
@@ -330,6 +347,63 @@ namespace MembranePoreTester.ViewModels
|
||||
set => SetProperty(ref _testMode, value);
|
||||
}
|
||||
|
||||
private int _selectedFlowModeIndex; // 0=大流量,1=小流量
|
||||
public int SelectedFlowModeIndex
|
||||
{
|
||||
get => _selectedFlowModeIndex;
|
||||
set
|
||||
{
|
||||
if (SetProperty(ref _selectedFlowModeIndex, value))
|
||||
{
|
||||
ushort reg = StationId switch
|
||||
{
|
||||
1 => _plcConfig.FlowModeRegister1,
|
||||
2 => _plcConfig.FlowModeRegister2,
|
||||
3 => _plcConfig.FlowModeRegister3,
|
||||
_ => 0
|
||||
};
|
||||
Task.Run(async () => await _plcService.WriteSingleRegisterAsync(reg, (ushort)value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private OxyPlot.PlotModel _plotModel;
|
||||
public OxyPlot.PlotModel PlotModel
|
||||
{
|
||||
get => _plotModel;
|
||||
set => SetProperty(ref _plotModel, value);
|
||||
}
|
||||
|
||||
|
||||
private void UpdatePlot()
|
||||
{
|
||||
var sorted = Record.DataPoints.OrderBy(p => p.Pressure).ToList();
|
||||
if (sorted.Count == 0)
|
||||
{
|
||||
PlotModel = null;
|
||||
return;
|
||||
}
|
||||
|
||||
var model = new OxyPlot.PlotModel { Title = "流量-压力曲线" };
|
||||
model.Axes.Add(new OxyPlot.Axes.LinearAxis { Position = OxyPlot.Axes.AxisPosition.Bottom, Title = "压力" });
|
||||
model.Axes.Add(new OxyPlot.Axes.LinearAxis { Position = OxyPlot.Axes.AxisPosition.Left, Title = "流量 (L/min)" });
|
||||
|
||||
var wetSeries = new OxyPlot.Series.LineSeries { Title = "湿膜流量", Color = OxyPlot.OxyColors.Blue, MarkerType = OxyPlot.MarkerType.Circle };
|
||||
var drySeries = new OxyPlot.Series.LineSeries { Title = "干膜流量", Color = OxyPlot.OxyColors.Red, MarkerType = OxyPlot.MarkerType.Circle };
|
||||
|
||||
foreach (var dp in sorted)
|
||||
{
|
||||
wetSeries.Points.Add(new OxyPlot.DataPoint(dp.Pressure, dp.WetFlow));
|
||||
drySeries.Points.Add(new OxyPlot.DataPoint(dp.Pressure, dp.DryFlow));
|
||||
}
|
||||
|
||||
model.Series.Add(wetSeries);
|
||||
model.Series.Add(drySeries);
|
||||
|
||||
PlotModel = model;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.ComponentModel;
|
||||
using MembranePoreTester.Communication;
|
||||
using System.ComponentModel;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace MembranePoreTester.ViewModels
|
||||
@@ -19,5 +20,15 @@ namespace MembranePoreTester.ViewModels
|
||||
OnPropertyChanged(propertyName);
|
||||
return true;
|
||||
}
|
||||
|
||||
protected async Task WriteFloatAsync(ushort address, float value)
|
||||
{
|
||||
byte[] bytes = BitConverter.GetBytes(value);
|
||||
if (BitConverter.IsLittleEndian) Array.Reverse(bytes);
|
||||
ushort high = (ushort)((bytes[0] << 8) | bytes[1]);
|
||||
ushort low = (ushort)((bytes[2] << 8) | bytes[3]);
|
||||
await App.PlcService.WriteSingleRegisterAsync(address, high);
|
||||
await App.PlcService.WriteSingleRegisterAsync((ushort)(address + 1), low);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user