更新
This commit is contained in:
@@ -24,6 +24,7 @@
|
|||||||
// 兼容旧代码:硬度完成线圈与溶出或硬度实时值寄存器地址
|
// 兼容旧代码:硬度完成线圈与溶出或硬度实时值寄存器地址
|
||||||
public ushort HardnessOver { get; set; }
|
public ushort HardnessOver { get; set; }
|
||||||
public ushort HardnessCompleteCoil { get; set; }
|
public ushort HardnessCompleteCoil { get; set; }
|
||||||
|
public ushort HardnessStartOver { get; set; }
|
||||||
public ushort HardnessPoSun { get; set; }
|
public ushort HardnessPoSun { get; set; }
|
||||||
public ushort HardnessPressure { get; set; }
|
public ushort HardnessPressure { get; set; }
|
||||||
// 脆碎度
|
// 脆碎度
|
||||||
|
|||||||
@@ -77,6 +77,8 @@ namespace TabletTester2025.ViewModels
|
|||||||
[ObservableProperty] private double _hardnessRSD;
|
[ObservableProperty] private double _hardnessRSD;
|
||||||
[ObservableProperty] private double _hardnessInternalMin = 40;
|
[ObservableProperty] private double _hardnessInternalMin = 40;
|
||||||
[ObservableProperty] private double _hardnessInternalMax = 60;
|
[ObservableProperty] private double _hardnessInternalMax = 60;
|
||||||
|
[ObservableProperty] private bool _isHardnessResetting;
|
||||||
|
public string HardnessResetButtonText => IsHardnessResetting ? "复位中" : "复位";
|
||||||
|
|
||||||
|
|
||||||
//硬度新增
|
//硬度新增
|
||||||
@@ -267,16 +269,7 @@ namespace TabletTester2025.ViewModels
|
|||||||
});
|
});
|
||||||
|
|
||||||
//硬复位
|
//硬复位
|
||||||
HardnessResetCommand = new AsyncRelayCommand(async () =>
|
HardnessResetCommand = new AsyncRelayCommand(ResetHardnessAsync, CanResetHardness);
|
||||||
{
|
|
||||||
// 1. 标准PLC按钮脉冲逻辑:置1 → 延时 → 置0(模拟按下再松开按钮)
|
|
||||||
await _plc.WriteCoilAsync(_plcConfig.HardnessStartReset, true);
|
|
||||||
await Task.Delay(100); // 脉冲宽度,可根据PLC程序调整20~100ms
|
|
||||||
await _plc.WriteCoilAsync(_plcConfig.HardnessStartReset, false);
|
|
||||||
_isHardnessRunning = false;
|
|
||||||
RefreshOverallPhase();
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
// 硬前进按钮命令
|
// 硬前进按钮命令
|
||||||
HardnessForward = new AsyncRelayCommand(async () =>
|
HardnessForward = new AsyncRelayCommand(async () =>
|
||||||
@@ -1725,6 +1718,63 @@ namespace TabletTester2025.ViewModels
|
|||||||
HardnessSudu = value;
|
HardnessSudu = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
partial void OnIsHardnessResettingChanged(bool value)
|
||||||
|
{
|
||||||
|
OnPropertyChanged(nameof(HardnessResetButtonText));
|
||||||
|
HardnessResetCommand?.NotifyCanExecuteChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool CanResetHardness()
|
||||||
|
{
|
||||||
|
return !IsHardnessResetting;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task ResetHardnessAsync()
|
||||||
|
{
|
||||||
|
if (IsHardnessResetting)
|
||||||
|
return;
|
||||||
|
|
||||||
|
IsHardnessResetting = true;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await PulseCoilAsync(_plcConfig.HardnessStartReset);
|
||||||
|
_isHardnessRunning = false;
|
||||||
|
RefreshOverallPhase();
|
||||||
|
await WaitForHardnessResetCompleteAsync(ResolveHardnessResetCompleteCoil());
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
await Application.Current.Dispatcher.InvokeAsync(() =>
|
||||||
|
MessageBox.Show($"硬度复位出错: {ex.Message}"));
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
IsHardnessResetting = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private ushort ResolveHardnessResetCompleteCoil()
|
||||||
|
{
|
||||||
|
return _plcConfig.HardnessStartOver;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task WaitForHardnessResetCompleteAsync(ushort completeCoil)
|
||||||
|
{
|
||||||
|
if (completeCoil == 0)
|
||||||
|
throw new InvalidOperationException("硬度复位完成线圈未配置");
|
||||||
|
|
||||||
|
DateTime deadline = DateTime.Now.AddSeconds(120);
|
||||||
|
while (DateTime.Now <= deadline)
|
||||||
|
{
|
||||||
|
if (await _plc.ReadCoilAsync(completeCoil))
|
||||||
|
return;
|
||||||
|
|
||||||
|
await Task.Delay(100);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new TimeoutException("等待硬度复位完成信号超时");
|
||||||
|
}
|
||||||
|
|
||||||
private async Task WaitForHardnessSampleCompleteAsync(ushort completeCoil)
|
private async Task WaitForHardnessSampleCompleteAsync(ushort completeCoil)
|
||||||
{
|
{
|
||||||
DateTime deadline = DateTime.Now.AddSeconds(120);
|
DateTime deadline = DateTime.Now.AddSeconds(120);
|
||||||
|
|||||||
@@ -469,7 +469,7 @@
|
|||||||
|
|
||||||
<Button Command="{Binding StartHardnessCommand}" Content="开始" Style="{StaticResource StartButton}"/>
|
<Button Command="{Binding StartHardnessCommand}" Content="开始" Style="{StaticResource StartButton}"/>
|
||||||
<Button Command="{Binding StopHardnessCommand}" Content="停止" Style="{StaticResource StopButton}"/>
|
<Button Command="{Binding StopHardnessCommand}" Content="停止" Style="{StaticResource StopButton}"/>
|
||||||
<Button Command="{Binding HardnessResetCommand}" Content="复位" Style="{StaticResource ResetButton}"/>
|
<Button Command="{Binding HardnessResetCommand}" Content="{Binding HardnessResetButtonText}" Style="{StaticResource ResetButton}"/>
|
||||||
<Button Command="{Binding ClearHardnessRecordsCommand}" Content="清空记录" Style="{StaticResource SecondaryButton}"/>
|
<Button Command="{Binding ClearHardnessRecordsCommand}" Content="清空记录" Style="{StaticResource SecondaryButton}"/>
|
||||||
</WrapPanel>
|
</WrapPanel>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|||||||
Reference in New Issue
Block a user