更新
This commit is contained in:
@@ -43,8 +43,10 @@
|
|||||||
public ushort DissolutionStartCoil { get; set; }
|
public ushort DissolutionStartCoil { get; set; }
|
||||||
public ushort Dissolution1StartCoil { get; set; }
|
public ushort Dissolution1StartCoil { get; set; }
|
||||||
public ushort Dissolution1StopCoil { get; set; }
|
public ushort Dissolution1StopCoil { get; set; }
|
||||||
|
public ushort Dissolution1SampleAckCoil { get; set; }
|
||||||
public ushort Dissolution2StartCoil { get; set; }
|
public ushort Dissolution2StartCoil { get; set; }
|
||||||
public ushort Dissolution2StopCoil { get; set; }
|
public ushort Dissolution2StopCoil { get; set; }
|
||||||
|
public ushort Dissolution2SampleAckCoil { get; set; }
|
||||||
public ushort Dissolution1Time { get; set; }
|
public ushort Dissolution1Time { get; set; }
|
||||||
public ushort Dissolution2Time { get; set; }
|
public ushort Dissolution2Time { get; set; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
|
using System.Windows.Controls;
|
||||||
|
using System.Windows.Media;
|
||||||
using System.Windows.Threading;
|
using System.Windows.Threading;
|
||||||
using TabletTester2025.Models;
|
using TabletTester2025.Models;
|
||||||
using TabletTester2025.Services;
|
using TabletTester2025.Services;
|
||||||
@@ -35,6 +37,10 @@ namespace TabletTester2025.ViewModels
|
|||||||
private DateTime _dissolution2StartTime = DateTime.MinValue;
|
private DateTime _dissolution2StartTime = DateTime.MinValue;
|
||||||
private bool _isDissolution1Running;
|
private bool _isDissolution1Running;
|
||||||
private bool _isDissolution2Running;
|
private bool _isDissolution2Running;
|
||||||
|
private bool _dissolution1SampleRequestActive;
|
||||||
|
private bool _dissolution2SampleRequestActive;
|
||||||
|
private bool _isDissolution1SamplePromptOpen;
|
||||||
|
private bool _isDissolution2SamplePromptOpen;
|
||||||
private string _dissolutionResultChannel = "";
|
private string _dissolutionResultChannel = "";
|
||||||
private double _dissolutionResultRate30Min;
|
private double _dissolutionResultRate30Min;
|
||||||
private double _dissolutionResultRSquared;
|
private double _dissolutionResultRSquared;
|
||||||
@@ -309,10 +315,16 @@ namespace TabletTester2025.ViewModels
|
|||||||
DisintegrationTemp = await _plc.ReadFloatAsync(_plcConfig.DisintegrationTemp);
|
DisintegrationTemp = await _plc.ReadFloatAsync(_plcConfig.DisintegrationTemp);
|
||||||
|
|
||||||
if (_isDissolution1Running)
|
if (_isDissolution1Running)
|
||||||
|
{
|
||||||
|
await CheckDissolutionSampleAsync(1);
|
||||||
updated |= await ReadDissolutionChannelAsync(1);
|
updated |= await ReadDissolutionChannelAsync(1);
|
||||||
|
}
|
||||||
|
|
||||||
if (_isDissolution2Running)
|
if (_isDissolution2Running)
|
||||||
|
{
|
||||||
|
await CheckDissolutionSampleAsync(2);
|
||||||
updated |= await ReadDissolutionChannelAsync(2);
|
updated |= await ReadDissolutionChannelAsync(2);
|
||||||
|
}
|
||||||
|
|
||||||
UpdateDissolutionClock();
|
UpdateDissolutionClock();
|
||||||
|
|
||||||
@@ -320,6 +332,129 @@ namespace TabletTester2025.ViewModels
|
|||||||
DissolutionPlotModel.InvalidatePlot(true);
|
DissolutionPlotModel.InvalidatePlot(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task CheckDissolutionSampleAsync(int channel)
|
||||||
|
{
|
||||||
|
ushort coilAddress = channel == 1
|
||||||
|
? _plcConfig.Dissolution1SampleAckCoil
|
||||||
|
: _plcConfig.Dissolution2SampleAckCoil;
|
||||||
|
|
||||||
|
if (coilAddress == 0)
|
||||||
|
{
|
||||||
|
DissolutionCurveStatus = $"溶出{channel}取样确认线圈未配置";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool sampleConfirmed = await _plc.ReadCoilAsync(coilAddress);
|
||||||
|
if (sampleConfirmed)
|
||||||
|
{
|
||||||
|
SetDissolutionSampleRequestActive(channel, false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IsDissolutionSampleRequestActive(channel) || IsDissolutionSamplePromptOpen(channel))
|
||||||
|
return;
|
||||||
|
|
||||||
|
SetDissolutionSampleRequestActive(channel, true);
|
||||||
|
SetDissolutionSamplePromptOpen(channel, true);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await ShowDissolutionSampleDialogAsync(channel);
|
||||||
|
await _plc.WriteCoilAsync(coilAddress, true);
|
||||||
|
LocalAlarm = $"溶出{channel}已确认取样";
|
||||||
|
DissolutionCurveStatus = "";
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
SetDissolutionSampleRequestActive(channel, false);
|
||||||
|
await App.Current.Dispatcher.InvokeAsync(() =>
|
||||||
|
MessageBox.Show($"溶出{channel}取样确认失败:{ex.Message}", "取样确认失败", MessageBoxButton.OK, MessageBoxImage.Error));
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
SetDissolutionSamplePromptOpen(channel, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool IsDissolutionSampleRequestActive(int channel)
|
||||||
|
{
|
||||||
|
return channel == 1 ? _dissolution1SampleRequestActive : _dissolution2SampleRequestActive;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetDissolutionSampleRequestActive(int channel, bool value)
|
||||||
|
{
|
||||||
|
if (channel == 1)
|
||||||
|
_dissolution1SampleRequestActive = value;
|
||||||
|
else
|
||||||
|
_dissolution2SampleRequestActive = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool IsDissolutionSamplePromptOpen(int channel)
|
||||||
|
{
|
||||||
|
return channel == 1 ? _isDissolution1SamplePromptOpen : _isDissolution2SamplePromptOpen;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetDissolutionSamplePromptOpen(int channel, bool value)
|
||||||
|
{
|
||||||
|
if (channel == 1)
|
||||||
|
_isDissolution1SamplePromptOpen = value;
|
||||||
|
else
|
||||||
|
_isDissolution2SamplePromptOpen = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task ShowDissolutionSampleDialogAsync(int channel)
|
||||||
|
{
|
||||||
|
bool confirmed = await App.Current.Dispatcher.InvokeAsync(() =>
|
||||||
|
{
|
||||||
|
var dialog = new Window
|
||||||
|
{
|
||||||
|
Title = $"溶出{channel}取样",
|
||||||
|
Width = 420,
|
||||||
|
SizeToContent = SizeToContent.Height,
|
||||||
|
WindowStartupLocation = WindowStartupLocation.CenterOwner,
|
||||||
|
ResizeMode = ResizeMode.NoResize,
|
||||||
|
Background = Brushes.White,
|
||||||
|
Owner = Application.Current.MainWindow
|
||||||
|
};
|
||||||
|
|
||||||
|
var panel = new StackPanel { Margin = new Thickness(24) };
|
||||||
|
panel.Children.Add(new TextBlock
|
||||||
|
{
|
||||||
|
Text = "请取样分析后,取样结束后点击“确定已取样”继续运行。",
|
||||||
|
FontSize = 16,
|
||||||
|
Foreground = new SolidColorBrush(Color.FromRgb(16, 42, 67)),
|
||||||
|
TextWrapping = TextWrapping.Wrap,
|
||||||
|
Margin = new Thickness(0, 0, 0, 18)
|
||||||
|
});
|
||||||
|
|
||||||
|
var button = new Button
|
||||||
|
{
|
||||||
|
Content = "确定已取样",
|
||||||
|
Width = 128,
|
||||||
|
Height = 38,
|
||||||
|
HorizontalAlignment = System.Windows.HorizontalAlignment.Right,
|
||||||
|
Background = new SolidColorBrush(Color.FromRgb(21, 101, 169)),
|
||||||
|
Foreground = Brushes.White,
|
||||||
|
BorderThickness = new Thickness(0),
|
||||||
|
FontSize = 15,
|
||||||
|
FontWeight = System.Windows.FontWeights.SemiBold,
|
||||||
|
Cursor = System.Windows.Input.Cursors.Hand
|
||||||
|
};
|
||||||
|
button.Click += (_, _) =>
|
||||||
|
{
|
||||||
|
dialog.DialogResult = true;
|
||||||
|
dialog.Close();
|
||||||
|
};
|
||||||
|
|
||||||
|
panel.Children.Add(button);
|
||||||
|
dialog.Content = panel;
|
||||||
|
return dialog.ShowDialog() == true;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!confirmed)
|
||||||
|
throw new InvalidOperationException("取样确认窗口已关闭,未写入确认线圈");
|
||||||
|
}
|
||||||
|
|
||||||
private async Task<bool> ReadDissolutionChannelAsync(int channel)
|
private async Task<bool> ReadDissolutionChannelAsync(int channel)
|
||||||
{
|
{
|
||||||
ushort registerAddress = channel == 1
|
ushort registerAddress = channel == 1
|
||||||
@@ -775,6 +910,7 @@ namespace TabletTester2025.ViewModels
|
|||||||
Phase = TestPhase.Running;
|
Phase = TestPhase.Running;
|
||||||
DissolutionPass = false;
|
DissolutionPass = false;
|
||||||
ResetDissolutionChannel(1);
|
ResetDissolutionChannel(1);
|
||||||
|
ResetDissolutionSampleState(1);
|
||||||
_dissolution1StartTime = DateTime.Now;
|
_dissolution1StartTime = DateTime.Now;
|
||||||
_isDissolution1Running = true;
|
_isDissolution1Running = true;
|
||||||
DissolutionPlotModel.Title = "溶出曲线";
|
DissolutionPlotModel.Title = "溶出曲线";
|
||||||
@@ -792,6 +928,7 @@ namespace TabletTester2025.ViewModels
|
|||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
_isDissolution1Running = false;
|
_isDissolution1Running = false;
|
||||||
|
ResetDissolutionSampleState(1);
|
||||||
Phase = _isDissolution2Running ? TestPhase.Running : TestPhase.Idle;
|
Phase = _isDissolution2Running ? TestPhase.Running : TestPhase.Idle;
|
||||||
UpdateDissolutionClock();
|
UpdateDissolutionClock();
|
||||||
}
|
}
|
||||||
@@ -810,6 +947,7 @@ namespace TabletTester2025.ViewModels
|
|||||||
Phase = TestPhase.Running;
|
Phase = TestPhase.Running;
|
||||||
DissolutionPass = false;
|
DissolutionPass = false;
|
||||||
ResetDissolutionChannel(2);
|
ResetDissolutionChannel(2);
|
||||||
|
ResetDissolutionSampleState(2);
|
||||||
_dissolution2StartTime = DateTime.Now;
|
_dissolution2StartTime = DateTime.Now;
|
||||||
_isDissolution2Running = true;
|
_isDissolution2Running = true;
|
||||||
DissolutionPlotModel.Title = "溶出曲线";
|
DissolutionPlotModel.Title = "溶出曲线";
|
||||||
@@ -827,6 +965,7 @@ namespace TabletTester2025.ViewModels
|
|||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
_isDissolution2Running = false;
|
_isDissolution2Running = false;
|
||||||
|
ResetDissolutionSampleState(2);
|
||||||
Phase = _isDissolution1Running ? TestPhase.Running : TestPhase.Idle;
|
Phase = _isDissolution1Running ? TestPhase.Running : TestPhase.Idle;
|
||||||
UpdateDissolutionClock();
|
UpdateDissolutionClock();
|
||||||
}
|
}
|
||||||
@@ -857,6 +996,12 @@ namespace TabletTester2025.ViewModels
|
|||||||
DissolutionPlotModel.InvalidatePlot(true);
|
DissolutionPlotModel.InvalidatePlot(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ResetDissolutionSampleState(int channel)
|
||||||
|
{
|
||||||
|
SetDissolutionSampleRequestActive(channel, false);
|
||||||
|
SetDissolutionSamplePromptOpen(channel, false);
|
||||||
|
}
|
||||||
|
|
||||||
private async Task FinalizeDissolutionChannelAsync(int channel)
|
private async Task FinalizeDissolutionChannelAsync(int channel)
|
||||||
{
|
{
|
||||||
var times = channel == 1 ? _dissolution1Times : _dissolution2Times;
|
var times = channel == 1 ? _dissolution1Times : _dissolution2Times;
|
||||||
|
|||||||
@@ -37,8 +37,10 @@
|
|||||||
"DissolutionStartCoil": 40,
|
"DissolutionStartCoil": 40,
|
||||||
"Dissolution1StartCoil": 40,
|
"Dissolution1StartCoil": 40,
|
||||||
"Dissolution1StopCoil": 43,
|
"Dissolution1StopCoil": 43,
|
||||||
|
"Dissolution1SampleAckCoil": 44,
|
||||||
"Dissolution2StartCoil": 30,
|
"Dissolution2StartCoil": 30,
|
||||||
"Dissolution2StopCoil": 33,
|
"Dissolution2StopCoil": 33,
|
||||||
|
"Dissolution2SampleAckCoil": 34,
|
||||||
"Dissolution1Time": 430,
|
"Dissolution1Time": 430,
|
||||||
"Dissolution2Time": 440
|
"Dissolution2Time": 440
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user