From 263fffbcf5478018912cf0afac4050113ce5e7c4 Mon Sep 17 00:00:00 2001 From: "GukSang.Jin" Date: Wed, 20 May 2026 14:37:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Services/PlcSimulator.cs | 2 ++ ViewModels/StationViewModel.cs | 16 ++++++++++++++- Views/SettingsWindow.xaml | 10 ++++++++++ Views/SettingsWindow.xaml.cs | 36 ++++++++++++++++++++++++++++++++++ 4 files changed, 63 insertions(+), 1 deletion(-) diff --git a/Services/PlcSimulator.cs b/Services/PlcSimulator.cs index a2ec195..87e6380 100644 --- a/Services/PlcSimulator.cs +++ b/Services/PlcSimulator.cs @@ -41,6 +41,8 @@ namespace TabletTester2025.Services int value = startAddress switch { 410 => 100, // 脆碎圈数 + 430 => 30, // 溶出1时间(min) + 440 => 30, // 溶出2时间(min) _ => _rand.Next(0, 1000) }; return Task.FromResult(value); diff --git a/ViewModels/StationViewModel.cs b/ViewModels/StationViewModel.cs index a1e921d..6c3f655 100644 --- a/ViewModels/StationViewModel.cs +++ b/ViewModels/StationViewModel.cs @@ -1624,7 +1624,7 @@ namespace TabletTester2025.ViewModels AddHardnessSample(value); await ReadHardnessMaxCaptureAsync(); ApplyHardnessStatistics(count); - await WaitForCoilStateAsync(completeCoil, false, TimeSpan.FromSeconds(10), "硬度完成信号未回落"); + await TryWaitForCoilStateAsync(completeCoil, false, TimeSpan.FromSeconds(2)); } if (_hardnessResults.Count < count) @@ -1786,6 +1786,20 @@ namespace TabletTester2025.ViewModels throw new TimeoutException(timeoutMessage); } + private async Task TryWaitForCoilStateAsync(ushort coilAddress, bool expectedState, TimeSpan timeout) + { + DateTime deadline = DateTime.Now.Add(timeout); + while (_isHardnessRunning && DateTime.Now <= deadline) + { + if (await _plc.ReadCoilAsync(coilAddress) == expectedState) + return true; + + await Task.Delay(100); + } + + return false; + } + private void ApplyHardnessStatistics(int requiredCount) { var stats = TestCalculationService.CalculateHardness( diff --git a/Views/SettingsWindow.xaml b/Views/SettingsWindow.xaml index e6e53d6..83b7c2f 100644 --- a/Views/SettingsWindow.xaml +++ b/Views/SettingsWindow.xaml @@ -151,6 +151,16 @@ + + + + + + + + diff --git a/Views/SettingsWindow.xaml.cs b/Views/SettingsWindow.xaml.cs index 3610f58..d41ea57 100644 --- a/Views/SettingsWindow.xaml.cs +++ b/Views/SettingsWindow.xaml.cs @@ -29,6 +29,8 @@ namespace TabletTester2025 // 溶出度 await LoadPlcFloatToTextBoxAsync(ResolveDissolution1SpeedRegister(), Dissolution1SpeedBox); await LoadPlcFloatToTextBoxAsync(ResolveDissolution2SpeedRegister(), Dissolution2SpeedBox); + await LoadPlcIntToTextBoxAsync(ResolveDissolution1TimeRegister(), Dissolution1TimeBox); + await LoadPlcIntToTextBoxAsync(ResolveDissolution2TimeRegister(), Dissolution2TimeBox); await LoadPlcFloatToTextBoxAsync(ResolveDissolution1IntervalRegister(), Dissolution1IntervalBox); await LoadPlcFloatToTextBoxAsync(ResolveDissolution2IntervalRegister(), Dissolution2IntervalBox); } @@ -44,6 +46,8 @@ namespace TabletTester2025 DisintegrationTimeMinBox.Text = ResolveDisintegrationTimeMin(p).ToString("0.###"); //DisintegrationTempBox.Text = p.DisintegrationTemperatureC.ToString(); //DissolutionTempBox.Text = p.DissolutionTemperatureC.ToString(); + Dissolution1TimeBox.Text = p.Dissolution1TimeMin.ToString(); + Dissolution2TimeBox.Text = p.Dissolution2TimeMin.ToString(); Dissolution1IntervalBox.Text = p.Dissolution1SampleIntervalMin.ToString(); Dissolution2IntervalBox.Text = p.Dissolution2SampleIntervalMin.ToString(); } @@ -83,6 +87,8 @@ namespace TabletTester2025 //p.DissolutionTemperatureC = ParseFiniteDouble(DissolutionTempBox.Text, "溶出介质温度"); double dissolution1Speed = ParsePositiveDouble(Dissolution1SpeedBox.Text, "溶出速度1"); double dissolution2Speed = ParsePositiveDouble(Dissolution2SpeedBox.Text, "溶出速度2"); + p.Dissolution1TimeMin = ParsePositiveInt(Dissolution1TimeBox.Text, "溶出1时间"); + p.Dissolution2TimeMin = ParsePositiveInt(Dissolution2TimeBox.Text, "溶出2时间"); p.Dissolution1SampleIntervalMin = ParsePositiveDouble(Dissolution1IntervalBox.Text, "溶出1取样间隔"); p.Dissolution2SampleIntervalMin = ParsePositiveDouble(Dissolution2IntervalBox.Text, "溶出2取样间隔"); @@ -94,6 +100,8 @@ namespace TabletTester2025 await WriteDisintegrationTimeAsync(disintegrationTimeMin); await WriteDissolution1SpeedAsync(dissolution1Speed); await WriteDissolution2SpeedAsync(dissolution2Speed); + await WriteDissolution1TimeAsync(p.Dissolution1TimeMin); + await WriteDissolution2TimeAsync(p.Dissolution2TimeMin); await WriteDissolution1IntervalAsync(p.Dissolution1SampleIntervalMin); await WriteDissolution2IntervalAsync(p.Dissolution2SampleIntervalMin); App.CurrentPharmaParams = p; @@ -351,6 +359,24 @@ namespace TabletTester2025 await App.PlcService.WriteFloatAsync(registerAddress, (float)value); } + private static async Task WriteDissolution1TimeAsync(int value) + { + ushort registerAddress = ResolveDissolution1TimeRegister(); + if (registerAddress == 0) + throw new InvalidOperationException("溶出1时间PLC寄存器地址未配置。"); + + await App.PlcService.WriteRegisterAsync(registerAddress, (ushort)Math.Clamp(value, 1, ushort.MaxValue)); + } + + private static async Task WriteDissolution2TimeAsync(int value) + { + ushort registerAddress = ResolveDissolution2TimeRegister(); + if (registerAddress == 0) + throw new InvalidOperationException("溶出2时间PLC寄存器地址未配置。"); + + await App.PlcService.WriteRegisterAsync(registerAddress, (ushort)Math.Clamp(value, 1, ushort.MaxValue)); + } + private static async Task WriteDissolution1IntervalAsync(double value) { ushort registerAddress = ResolveDissolution1IntervalRegister(); @@ -379,6 +405,16 @@ namespace TabletTester2025 return App.PlcConfig.Dissolution2Speed != 0 ? App.PlcConfig.Dissolution2Speed : (ushort)350; } + private static ushort ResolveDissolution1TimeRegister() + { + return App.PlcConfig.Dissolution1Time != 0 ? App.PlcConfig.Dissolution1Time : (ushort)430; + } + + private static ushort ResolveDissolution2TimeRegister() + { + return App.PlcConfig.Dissolution2Time != 0 ? App.PlcConfig.Dissolution2Time : (ushort)440; + } + private static ushort ResolveDissolution1IntervalRegister() { return App.PlcConfig.Dissolution1SampleInterval != 0 ? App.PlcConfig.Dissolution1SampleInterval : (ushort)432;