更新
This commit is contained in:
@@ -20,6 +20,7 @@ namespace TabletTester2025.ViewModels
|
||||
{
|
||||
public partial class StationViewModel : ObservableObject
|
||||
{
|
||||
private DispatcherTimer _hardnessGlobalTimer;
|
||||
private readonly IPlcService _plc;
|
||||
private readonly PlcConfiguration _plcConfig;
|
||||
private readonly DatabaseService _db;
|
||||
@@ -75,7 +76,8 @@ namespace TabletTester2025.ViewModels
|
||||
[ObservableProperty] private double _hardnessSudu = 300;// 硬度速度输入mm/min
|
||||
[ObservableProperty] private double _hardnessWeiyi = 100; // 硬度位移输入mm
|
||||
//[ObservableProperty] private double _hardnessPoSun = 400; // 硬度破损判定输入N
|
||||
//[ObservableProperty] private int _hardnessMaxN = 72; //最大力采集
|
||||
//[ObservableProperty] private double _hardnessMaxN = 72; //最大力采集
|
||||
[ObservableProperty] private double _hardnessShishilizhi = 0.0; //最大力采集
|
||||
|
||||
|
||||
|
||||
@@ -105,7 +107,8 @@ namespace TabletTester2025.ViewModels
|
||||
[ObservableProperty] private int _hardnessIntervalSec = 2;
|
||||
[ObservableProperty] private int _hardnessCurrentCount;
|
||||
[ObservableProperty] private double _hardnessMax;
|
||||
[ObservableProperty] private double _hardnessMin;
|
||||
|
||||
|
||||
|
||||
|
||||
[ObservableProperty] private bool _disintegrationPass; // 新增
|
||||
@@ -221,23 +224,16 @@ namespace TabletTester2025.ViewModels
|
||||
DissolutionPlotModel.Series.Add(_dissolution1Series);
|
||||
DissolutionPlotModel.Series.Add(_dissolution2Series);
|
||||
|
||||
// 硬度命令
|
||||
//HardnessUpCommand = new AsyncRelayCommand(async () =>
|
||||
//{
|
||||
|
||||
|
||||
// await _plc.WriteCoilAsync(0x20, true);
|
||||
// await Task.Delay(100);
|
||||
// await _plc.WriteCoilAsync(0x20, false);
|
||||
//});
|
||||
|
||||
HardnessDownCommand = new AsyncRelayCommand(async () =>
|
||||
HardnessDownCommand = new AsyncRelayCommand(async () =>
|
||||
{
|
||||
await _plc.WriteCoilAsync(0x21, true);
|
||||
await Task.Delay(100);
|
||||
await _plc.WriteCoilAsync(0x21, false);
|
||||
});
|
||||
|
||||
//复位
|
||||
//硬复位
|
||||
HardnessResetCommand = new AsyncRelayCommand(async () =>
|
||||
{
|
||||
// 1. 标准PLC按钮脉冲逻辑:置1 → 延时 → 置0(模拟按下再松开按钮)
|
||||
@@ -245,12 +241,8 @@ namespace TabletTester2025.ViewModels
|
||||
await Task.Delay(100); // 脉冲宽度,可根据PLC程序调整20~100ms
|
||||
await _plc.WriteCoilAsync(_plcConfig.HardnessStartReset, false);
|
||||
_hardnessResults.Clear();
|
||||
HardnessValue = 0;
|
||||
HardnessAvg = 0;
|
||||
HardnessRSD = 0;
|
||||
HardnessCurrentCount = 0;
|
||||
HardnessMax = 0;
|
||||
HardnessMin = 0;
|
||||
HardnessShishilizhi = 0;
|
||||
Phase = TestPhase.Idle;
|
||||
|
||||
});
|
||||
@@ -1101,11 +1093,10 @@ namespace TabletTester2025.ViewModels
|
||||
|
||||
private async Task RunHardnessAsync()
|
||||
{
|
||||
// 点击启动才执行一次
|
||||
if (Phase != TestPhase.Idle) return;
|
||||
CurrentTest = TestType.Hardness;
|
||||
Phase = TestPhase.Running;
|
||||
HardnessPass = false;
|
||||
_hardnessResults.Clear();
|
||||
|
||||
try
|
||||
{
|
||||
@@ -1118,44 +1109,17 @@ namespace TabletTester2025.ViewModels
|
||||
double currentWeiyi = HardnessWeiyi;
|
||||
|
||||
|
||||
// 如果你需要把这3个值发给PLC,就在这里发一次(测试开始用当前参数)
|
||||
// 写入PLC
|
||||
await _plc.WriteFloatAsync(_plcConfig.HardnessSudu, (float)currentSpeed);
|
||||
await _plc.WriteFloatAsync(_plcConfig.HardnessWeiyi, (float)currentWeiyi);
|
||||
|
||||
await _plc.WriteCoilAsync(_plcConfig.HardnessStartCoil, true);//启动
|
||||
|
||||
// 开始循环测试
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
await _plc.WriteCoilAsync(_plcConfig.HardnessStartCoil, true);
|
||||
|
||||
bool completed = false;
|
||||
while (!completed && Phase == TestPhase.Running)
|
||||
{
|
||||
await Task.Delay(200);
|
||||
completed = await _plc.ReadCoilAsync(_plcConfig.HardnessCompleteCoil);
|
||||
}
|
||||
|
||||
double val = await _plc.ReadFloatAsync(_plcConfig.HardnessPoSun);
|
||||
_hardnessResults.Add(val);
|
||||
//HardnessPoSun = val;
|
||||
|
||||
await Task.Delay(1000);
|
||||
}
|
||||
|
||||
// 计算结果
|
||||
HardnessAvg = _hardnessResults.Average();
|
||||
HardnessMax = _hardnessResults.Max();
|
||||
HardnessMin = _hardnessResults.Min();
|
||||
HardnessCurrentCount = count;
|
||||
HardnessRSD = (StandardDeviation(_hardnessResults) / HardnessAvg) * 100;
|
||||
HardnessPass = HardnessAvg >= min && HardnessAvg <= max;
|
||||
|
||||
Phase = TestPhase.Completed;
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await App.Current.Dispatcher.InvokeAsync(() => MessageBox.Show($"硬度测试出错:{ex.Message}"));
|
||||
Phase = TestPhase.Error;
|
||||
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -1544,8 +1508,7 @@ namespace TabletTester2025.ViewModels
|
||||
// 硬度
|
||||
HardnessAvg = HardnessAvg,
|
||||
HardnessRSD = HardnessRSD,
|
||||
HardnessMax = HardnessMax,
|
||||
HardnessMin = HardnessMin,
|
||||
|
||||
HardnessTestCount = HardnessTestCount,
|
||||
HardnessInternalMin = HardnessInternalMin,
|
||||
HardnessInternalMax = HardnessInternalMax,
|
||||
|
||||
Reference in New Issue
Block a user